Introduction
At first, I try to use mlab built-in backup system. However, it’s not include in its free 500mb program. As a result, I wrote a C# program to back up by myself.
Use cmd to backup mlab
If you have a mlab account, you can find this in the first page after you login. The way to backup the whole database to your local client is to use code under export Database:
mongodump -h ds155841.mlab.com:55841 -d <databaseName> -u <user> -p <password> -o <output directory>
Once tou succeed, you will get:
And you can go to the dircetory you define as output directory. And foreach collection, you will get two output dump file “collectionName.bson” and “collectionName.metadata.json”
Use C# to manipulate cmd
First, Open a console project.
Second, input codes below in the Main thread
Third, set build type to be “release”, then build the program.
Fourth, check the directory of your console project, and find “\bin\Release\YourProjName.exe”. Once you execute this exeutable file, you will start the same process with using cmd to dump. In this way, you have successfully manipulated cmd by C#.
Use Windows10 task schedulor to execute this program autometically
this you can directly refer to this video