Mongodb 之 數據庫備份恢復步驟

1、查看test數據庫數據

Mongodb  之  數據庫備份恢復步驟

2、備份當前數據庫

[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)

Mongodb  之  數據庫備份恢復步驟

3、刪除test數據庫

Mongodb  之  數據庫備份恢復步驟

4、恢復數據庫

[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

備註:

mongorestore: 還原的命令
-h: 需還原的主機
-u:還原該數據庫的用戶,必須要對該test數據庫有讀寫的權限才行
-p:用戶的密碼
-d:需要還原的數據庫
/app/backup/mongodb_backup/test/:備份位置所在路徑

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章