Mongo: 概念、GUI客户端、备份和恢复

发布于 2020-07-05 18:05:25

GUI

16M 大小限制

Mongo data babckup and restore

mongodump, mongorestore

Dump and restore database test:

> mongodump -d test
2020-07-05T17:38:52.589+0800	writing test.hi to dump/test/hi.bson
2020-07-05T17:38:52.595+0800	done dumping test.hi (2 documents)

> tree dump
dump
└── test
    ├── hi.bson
    └── hi.metadata.json
> mongorestore  dump/
2020-07-05T17:41:08.621+0800	preparing collections to restore from
2020-07-05T17:41:08.627+0800	restoring to existing collection test.hi without dropping
2020-07-05T17:41:08.627+0800	reading metadata for test.hi from dump/test/hi.metadata.json
2020-07-05T17:41:08.628+0800	restoring test.hi from dump/test/hi.bson
2020-07-05T17:41:08.639+0800	continuing through error: E11000 duplicate key error collection: test.hi index: _id_ dup key: { : ObjectId('5f0197ec39fc5ab33fd67b38') }
2020-07-05T17:41:08.639+0800	continuing through error: E11000 duplicate key error collection: test.hi index: _id_ dup key: { : ObjectId('5f0197fdd5d229b1aa990191') }
2020-07-05T17:41:08.639+0800	no indexes to restore
2020-07-05T17:41:08.639+0800	finished restoring test.hi (0 documents, 2 failures)
2020-07-05T17:41:08.639+0800	0 document(s) restored successfully. 2 document(s) failed to restore.

> mongorestore --drop dump/
2020-07-05T17:41:54.236+0800	preparing collections to restore from
2020-07-05T17:41:54.262+0800	reading metadata for test.hi from dump/test/hi.metadata.json
2020-07-05T17:41:54.292+0800	restoring test.hi from dump/test/hi.bson
2020-07-05T17:41:54.296+0800	no indexes to restore
2020-07-05T17:41:54.296+0800	finished restoring test.hi (2 documents, 0 failures)
2020-07-05T17:41:54.296+0800	2 document(s) restored successfully. 0 document(s) failed to restore.

archive one db

> mongodump --archive=test.$(date '+%Y%m%d').archive --db=test
2020-07-05T17:53:30.880+0800	writing test.hi to archive 'test.20200705.archive'
2020-07-05T17:53:30.890+0800	done dumping test.hi (2 documents)

> ll test.20200705.archive
-rw-r--r--  1 garden  staff   2.7K Jul  5 17:53 test.20200705.archive

> mongorestore --drop --archive=test.20200705.archive
# or
> mongorestore --drop --archive < test.20200705.archive
2020-07-05T17:50:43.290+0800	preparing collections to restore from
2020-07-05T17:50:43.329+0800	reading metadata for test.20200705.archive from archive on stdin
2020-07-05T17:50:43.360+0800	restoring test.hi from archive on stdin
2020-07-05T17:50:43.367+0800	no indexes to restore
2020-07-05T17:50:43.367+0800	finished restoring test.20200705.archive (2 documents, 0 failures)
2020-07-05T17:50:43.367+0800	2 document(s) restored successfully. 0 document(s) failed to restore.

更改命名空间

mongorestore --archive="mongodump-test-db" --nsFrom='test.*' --nsTo='examples.*'
comments powered by Disqus