mongdb迁移数据到另一个服务器的库

一 通过执行mongodb bin 目录 下的mongodump来备份数据库名为storager 的数据

./mongodump --db testdb -u bbs -p bbs--collection fs.files --out  /home/service/bak

./mongodump --db testdb -u bbs -p bbs--collection fs.chunks --out /home/service/bak

下面是导出的详细过程:

linux:/home/service/mongodb/bin # ./mongodump --db testdb  -u bbs -p bbs --collection fs.files --out  /home/service/bak
2018-03-19T20:17:10.998+0800 writing testdb.fs.files to 
2018-03-19T20:17:11.000+0800 done dumping testdb.fs.files (299 documents)
linux:/home/service/mongodb/bin # ./mongodump --db testdb -u bbs -p bbs --collection fs.chunks --out /home/service/bak
2018-03-19T20:17:26.990+0800 writing testdb.fs.chunks to 
2018-03-19T20:17:29.971+0800 [#######################.]  testdb.fs.chunks  9085/9478  (95.9%)
2018-03-19T20:17:30.085+0800 [########################]  testdb.fs.chunks  9478/9478  (100.0%)
2018-03-19T20:17:30.085+0800 done dumping testdb.fs.chunks (9478 documents)


二 通过执行mongodb bin 目录 下的mongorestore 来导入名为storager 的数据库
./mongorestore --db testdb -u bbs -p bbs --collection fs.files  /home/storager/fs.files.bson

./mongorestore --db testdb -u bbs -p bbs --collection fs.chunks /home/storager/fs.chunks.bson

下面是导入的详细过程:

linux:/home/mongodb/mongodb # cd bin
linux:/home/mongodb/mongodb/bin # ./mongorestore --db testdb -u bbs -p bbs --collection fs.files  /home/testdb/fs.files.bson
2018-03-20T05:40:21.019+0800 checking for collection data in /home/testdb/fs.files.bson
2018-03-20T05:40:21.019+0800 reading metadata for testdb.fs.files from /home/testdb/fs.files.metadata.json
2018-03-20T05:40:21.035+0800 restoring testdb.fs.files from /home/testdb/fs.files.bson
2018-03-20T05:40:21.097+0800 restoring indexes for collection testdb.fs.files from metadata
2018-03-20T05:40:21.113+0800 finished restoring testdb.fs.files (299 documents)
2018-03-20T05:40:21.113+0800 done
linux:/home/mongodb/mongodb/bin # ./mongorestore --db testdb -u bbs -p bbs --collection fs.chunks /home/testdb/fs.chunks.bson
2018-03-20T05:40:40.401+0800 checking for collection data in /home/testdb/fs.chunks.bson
2018-03-20T05:40:40.401+0800 reading metadata for testdb.fs.chunks from /home/testdb/fs.chunks.metadata.json
2018-03-20T05:40:40.418+0800 restoring testdb.fs.chunks from /home/testdb/fs.chunks.bson
2018-03-20T05:40:43.388+0800 [###.....................]  testdb.fs.chunks  322MB/2.26GB  (13.9%)
2018-03-20T05:40:46.388+0800 [###.....................]  testdb.fs.chunks  366MB/2.26GB  (15.8%)
2018-03-20T05:40:49.388+0800 [####....................]  testdb.fs.chunks  475MB/2.26GB  (20.5%)
2018-03-20T05:40:52.388+0800 [######..................]  testdb.fs.chunks  638MB/2.26GB  (27.5%)
2018-03-20T05:40:55.388+0800 [#######.................]  testdb.fs.chunks  764MB/2.26GB  (33.0%)
2018-03-20T05:40:58.388+0800 [########................]  testdb.fs.chunks  829MB/2.26GB  (35.8%)
2018-03-20T05:41:01.388+0800 [##########..............]  testdb.fs.chunks  996MB/2.26GB  (43.0%)
2018-03-20T05:41:04.388+0800 [###########.............]  testdb.fs.chunks  1.12GB/2.26GB  (49.4%)
2018-03-20T05:41:07.388+0800 [############............]  testdb.fs.chunks  1.18GB/2.26GB  (52.3%)
2018-03-20T05:41:10.388+0800 [#############...........]  testdb.fs.chunks  1.24GB/2.26GB  (55.0%)
2018-03-20T05:41:13.388+0800 [###############.........]  testdb.fs.chunks  1.42GB/2.26GB  (62.7%)
2018-03-20T05:41:16.388+0800 [################........]  testdb.fs.chunks  1.56GB/2.26GB  (69.0%)
2018-03-20T05:41:19.388+0800 [#################.......]  testdb.fs.chunks  1.68GB/2.26GB  (74.2%)
2018-03-20T05:41:22.388+0800 [##################......]  testdb.fs.chunks  1.76GB/2.26GB  (77.6%)
2018-03-20T05:41:25.388+0800 [##################......]  testdb.fs.chunks  1.77GB/2.26GB  (78.1%)
2018-03-20T05:41:28.388+0800 [##################......]  testdb.fs.chunks  1.77GB/2.26GB  (78.4%)
2018-03-20T05:41:31.388+0800 [##################......]  testdb.fs.chunks  1.78GB/2.26GB  (78.4%)
2018-03-20T05:41:34.388+0800 [###################.....]  testdb.fs.chunks  1.83GB/2.26GB  (81.1%)
2018-03-20T05:41:37.388+0800 [###################.....]  testdb.fs.chunks  1.84GB/2.26GB  (81.3%)
2018-03-20T05:41:40.388+0800 [###################.....]  testdb.fs.chunks  1.88GB/2.26GB  (82.9%)
2018-03-20T05:41:43.388+0800 [#####################...]  testdb.fs.chunks  2.04GB/2.26GB  (90.1%)
2018-03-20T05:41:46.388+0800 [######################..]  testdb.fs.chunks  2.13GB/2.26GB  (94.0%)
2018-03-20T05:41:49.388+0800 [#######################.]  testdb.fs.chunks  2.26GB/2.26GB  (99.8%)
2018-03-20T05:41:49.587+0800 [########################]  testdb.fs.chunks  2.26GB/2.26GB  (100.0%)
2018-03-20T05:41:49.587+0800 restoring indexes for collection testdb.fs.chunks from metadata
2018-03-20T05:41:51.094+0800 finished restoring testdb.fs.chunks (9478 documents)
2018-03-20T05:41:51.094+0800 done

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值