Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to backup and restore the Mongodb database

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#?

like image 855
marx Avatar asked Apr 02 '13 03:04

marx


2 Answers

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/*
like image 124
AmpT Avatar answered Nov 10 '22 07:11

AmpT


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
like image 39
Prahlad Yeri Avatar answered Nov 10 '22 08:11

Prahlad Yeri