Hello,
is possible to use mongodump and mongorestore by the .net driver ?
In the shell to backup a single database i can write : mongodump --db mydbname --out \folderA\folderB\
and then to restore i write : mongorestore --db mydbname --drop \folderA\folderB\mydbname
Works like a charme.
Can we do the same with the driver ?
Thanks a lot.
Hello guys, share my solution.
Hope this helps !
Mongodump and Mongorestore are applications, not MongoDB commands which is why i would have to run the executable on another thread for not freeze the UI if the operation fail.
Using Mongodump:
Task.Run(() =>
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
//Important is that the argument begins with /C otherwise it won't work.
startInfo.Arguments = @"/C mongodump --db shop --out \backup\mongo\";
process.StartInfo = startInfo;
process.Start();
while (!process.HasExited) ;
if (process.ExitCode == 0)
{
MessageBox.Show("Backup OK !");
}
else
{
MessageBox.Show($"Backup fail ! Exit code: {process.ExitCode}");
}
});