温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mongodb 数据库备份操作

发布时间:2020-05-24 02:34:13 来源:网络 阅读:1797 作者:zbill 栏目:MongoDB数据库


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 <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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI