mongodb 數據庫備份mongodb
mongodump --host mongodb.example.net --port 27017數據庫
備份路徑選擇ide
mongodump --out /data/backup/.net
選擇要備份的數據庫和集合rest
mongodump --collection myCollection --db testci
建立非本地數據庫備份it
mongodump --host mongodb1.example.net --port 3017 --username user --password "pass" --out /opt/backup/mongodump-2013-10-24io
====================================================================================================================================================class
數據庫恢復test
mongorestore --port <port number> <path to the backup>
mongorestore dump-2013-10-25/
mongorestore --oplogReplay
mongorestore --host mongodb1.example.net --port 3017 --username user --password 'pass' /opt/backup/mongodump-2013-10-24
冷備份
service mongod stop
指定數據庫文件的位置
cd /backup
mongodump --dbpath /var/lib/mongo/
service mongod start
熱備份
# cd /backup
# mongodump --db mongodevdb --username mongodevdb --password YourSecretPwd
# ls -l dump/
drwxr-xr-x. 2 root root 4096 Sep 7 10:08 mongodevdb
Backup a specific Collection
# cd /backup
# mongodump --collection employee --db mongodevdb --username mongodevdb --password YourSecretPwd
# mongodump --collection employee --db mongodevdb --username mongodevdb --password YourSecretPwd --out /dbbackup
[local-host]# mongodump --host 192.168.1.2 --port 37017 --db mongodevdb --username mongodevdb --password YourSecretPwd
service mongod stop
cd /backup
mongorestore --dbpath /var/lib/mongo dump
cd /backup
mongorestore --dbpath /var/lib/mongo --db mongodevdb dump/mongodevdb
Drop the old Database before Restoring
# cd /backup
# mongorestore --dbpath /var/lib/mongo --db mongodevdb dump/mongodevdb
# mongorestore --dbpath /var/lib/mongo --db mongodevdb --drop dump/mongodevdb
mongorestore --host 192.168.1.2 --port 3017 --db mongodevdb --username mongodevdb --password YourSecretPwd --drop /backup/dump