MongoDB backup
MongoDB Backup
https://docs.mongodb.com/manual/core/backups/
https://docs.mongodb.com/manual/tutorial/backup-and-restore-tools/
mongodump and mongorestore —Standard utilities for backing up and restoring a database. mongodump saves the database’s data in its native BSON format and thus is best used for backups only; this tool has the advantage of being usable for hot backups, which can easily be restored with mongorestore.
mongoexport and mongoimport —Export and import JSON, CSV, and TSV[7] data; this is useful if you need your data in widely supported formats. mongoimport can also be good for initial imports of large data sets, although before importing, it’s often desirable to adjust the data model to take best advantage of MongoDB. In such cases, it’s easier to import the data through one of the drivers using a custom script.
Options
Filesystem Snapshots
Making a copy of MongoDB’s underlying data files, volume snapshot
CP or Rsync
如果snapshot不支持,可以通过cp 和 rsync 来备份数据文件
mongodump
mongodump
reads data from a MongoDB database and creates high fidelity BSON files which the mongorestore
tool can use to populate a MongoDB database.
针对dump 期间的数据变动,可以通过--oplog 来build a point-in-time snapshot of a database within a replica set, 对应的 mongorestore --oplogReplay
eg
mongodump --out=/data/backup/ --collection=myCollection --db=test |