mongodb备份和恢复

--------------------------备份--------------------------------------

1.备份语句
/usr/local/services/mongodb/bin/mongodump -h 172.17.70.190:28001 -u root -p 123456 --authenticationDatabase mgdb_livex --db=mgdb_livex -c ${table_name} -o /home/hxl/mongo_exportdata/${table_name}_${dump_date}

 

--------------------------恢复--------------------------------------

1.备份文件上传到服务器/tmp目录,然后进行解压
[root@localhost tmp]# tar -xvf test1.tar.gz
[root@localhost tmp]# tar -xvf test2.tar.gz

解压后会生成目录
[root@localhost tmp]# ls -1
test1
test2

目录下是库名目录,库名下面是具体的数据文件
[root@localhost mgdb_livex]# pwd
/tmp/test1/mgdb_livex
[root@localhost mgdb_livex]# ls -l
total 17360
-rw-r--r-- 1 test test 17768550 Sep 7 02:10 test1.bson
-rw-r--r-- 1 test test 536 Sep 7 02:10 test1.metadata.json

将数据恢复到另外的库:dbtest
/usr/local/services/mongodb/bin/mongorestore --host 127.0.0.1 --port 28001 -u root -p 123456 --authenticationDatabase admin -d dbtest /tmp/t_chartroom_msg_20210907/mgdb_livex
/usr/local/services/mongodb/bin/mongorestore --host 127.0.0.1 --port 28001 -u root -p 123456 --authenticationDatabase admin -d dbtest /tmp/t_chartroom_msg_client_20210907/mgdb_livex

原文地址:https://www.cnblogs.com/hxlasky/p/15238176.html