mongodb  数据库备份


mongodump --host mongodb.example.net --port 27017


备份路径选择

mongodump --out /data/backup/


选择要备份的数据库和集合

mongodump --collection myCollection --db test


创建非本地数据库备份


mongodump --host mongodb1.example.net --port 3017 --username user --password "pass" --out /opt/backup/mongodump-2013-10-24


====================================================================================================================================================



数据库恢复


mongorestore --port



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