Mongodb-备份(mongodump)与恢复(mongorestore)

[root@localhost ~]# docker exec -it mytest /bin/bash

[root@1c178edd6a92 /]# cd /home/Java/mongodb

[root@1c178edd6a92 mongodb]# bin/mongo –port 17016

> use cloudcc

switched to db cloudcc

> db.test.insert({“username”:”hacker”, “age”:26})

WriteResult({ “nInserted” : 1 })

> exit

bye

[root@1c178edd6a92 mongodb]# clear

[root@1c178edd6a92 mongodb]# bin/mongodump -h 172.17.0.5:17016 -d cloudcc -o /home/Java

2017-07-19T09:32:06.571+0000    writing cloudcc.test to

2017-07-19T09:32:06.573+0000    done dumping cloudcc.test (1 document)

[root@1c178edd6a92 mongodb]# ls /home/Java/

cloudcc  mongodb  mongodb-linux-x86_64-rhel70-3.4.5.tgz

[root@1c178edd6a92 mongodb]# ls /home/Java/cloudcc/

test.bson  test.metadata.json

[root@1c178edd6a92 mongodb]#

[root@1c178edd6a92 mongodb]# bin/mongo –port 17016

> use cloudcc

switched to db cloudcc

> db.dropDatabase()

{ “dropped” : “cloudcc”, “ok” : 1 }

> exit

bye

[root@1c178edd6a92 mongodb]# bin/mongorestore -h 172.17.0.5:17016 -d cloudcc /home/Java/cloudcc/

    原文作者:黑客不黑撒
    原文地址: https://www.jianshu.com/p/d3619f4377d3
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞