Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb: how to do backup of mongodb [closed]

Tags:

mongodb

I think someone has already suggested:

1. stop the mongod
2. backup the data directory

Is it reliable, I mean, ensure 100% success to restore? And I can't find which directory stores the data... any command can help me to find it?

like image 755
Bin Chen Avatar asked Jan 10 '12 04:01

Bin Chen


2 Answers

If mongod process exits cleanly (that is, no crashes or kill -9 stuff), then it is safe to copy data files somewhere.

If your current installation breaks (for example, data corruption due to unclean shutdown), you can delete its files, copy that backup over and start mongod again.

Default data directory is /data/db, but it may be set to another value in your config file. For example, I set it to /var/lib/mongodb.

You can also use mongodump to do a backup from a live server (this may impact performance). Use mongorestore to restore backups made by mongodump.

like image 102
Sergio Tulentsev Avatar answered Oct 15 '22 05:10

Sergio Tulentsev


At IGN we do hot backups via mongodump running as an hourly cron job, and take filer snapshots (NetApp storage) on a half-hourly basis. If your system is not too write heavy and you can afford write blocks, try using fsync and lock to flush the writes to the disk and prevent further writes. This can be followed by mongodump and upon completion you can unlock the db. Please note that you've to be admin to do so.

db.runCommand({fsync:1,lock:1})
like image 41
lobster1234 Avatar answered Oct 15 '22 07:10

lobster1234