How to use C# to backup and restore the Mongodb database? For now there is only an server to save the mongodb data, and I want to make an backup in case of the server is destroyed so that I can restore it.
Dose anybody know how to do that using C#?
From the mongolab website (http://docs.mongolab.com/backups/) a useful/simple example:
To backup use mongodump:
% mongodump -h ds012345.mongolab.com:56789 -d dbname -u dbuser -p dbpassword -o dumpdir
To restore use mongorestore:
% mongorestore -h ds023456.mongolab.com:45678 -d dbname -u dbuser -p dbpassword dumpdir/*
If you just want automated backups, there is an easier way than resorting to a full-fledged programming language:
http://docs.mongodb.org/manual/tutorial/backup-databases-with-filesystem-snapshots/
As shown in the link, the below command would suffice. You may put it in a statup-script/daemon to execute it at regular frequencies:
Backup:
lvcreate --size 100M --snapshot --name mdb-snap01 /dev/vg0/mongodb
Restore:
lvcreate --size 1G --name mdb-new vg0
gzip -d -c mdb-snap01.gz | dd of=/dev/vg0/mdb-new
mount /dev/vg0/mdb-new /srv/mongodb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With