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?
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
.
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})
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