1, see the test database data
2, back up the current database
[root@ops-site mongodb_backup]# mongodump -h 10.3.152.78 -u test2 -p abc123 -d test -o .
2019-07-16T23:09:17.902+0800 writing test.runoob to test/runoob.bson
2019-07-16T23:09:17.912+0800 writing test.system.indexes to test/system.indexes.bson
2019-07-16T23:09:17.917+0800 writing test.runoob metadata to test/runoob.metadata.json
2019-07-16T23:09:17.918+0800 done dumping test.runoob (1 document)
3, delete the test database
4, restore the database
[root@ops-site ~]# mongorestore -h 10.3.152.78 -u test2 -p "abc123" -d test /app/backup/mongodb_backup/test/
2019-07-16T23:16:09.928+0800 building a list of collections to restore from /app/backup/mongodb_backup/test/ dir
2019-07-16T23:16:09.938+0800 reading metadata file from /app/backup/mongodb_backup/test/runoob.metadata.json
2019-07-16T23:16:09.938+0800 restoring test.runoob from file /app/backup/mongodb_backup/test/runoob.bson
2019-07-16T23:16:11.055+0800 restoring indexes for collection test.runoob from metadata
2019-07-16T23:16:11.056+0800 finished restoring test.runoob (1 document)
2019-07-16T23:16:11.056+0800 done
Note:
mongorestore: Restore command
-h: the need to restore the host
-u: Restore the user database, the database must have the test read and write permissions for the job
-p: user's password
-d: you need to restore the database
/ app / backup / mongodb_backup / test / : the path backup location