Mongodb: how to backup mongodb

I think someone already suggested:

1. stop the mongod 2. backup the data directory 

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

+6
source share
2 answers

If the mongod process crashes (that is, without crashing or kill -9 ), then data files can be copied somewhere.

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

The default data directory is /data/db , but a different value may be set in your configuration file. For example, I installed it in /var/lib/mongodb .

You can also use mongodump to back up from a live server (this may affect performance). Use mongorestore to restore backups made with mongodump .

+6
source

At IGN, we make hot backups through mongodump , working as an hourly cron job, and get snapshots of files (NetApp storage) for half an hour. If your system is not too heavy, and you can afford to write blocks, try using fsync and lock to clear the disk writes and prevent further recording. This can be followed by mongodump , and upon completion you can unlock db. Please note that you must be an administrator for this.

 db.runCommand({fsync:1,lock:1}) 
+5
source

Source: https://habr.com/ru/post/905583/


All Articles