在Ubuntu系統上,MongoDB的數據恢復可以通過使用mongorestore
命令來實現。以下是數據恢復的基本步驟和命令示例:
停止MongoDB服務: 在開始恢復數據之前,請確保MongoDB服務已經停止,以防止數據被覆蓋。
sudo systemctl stop mongod
執行mongorestore命令:
使用mongorestore
命令將備份數據恢復到MongoDB中?;菊Z法如下:
mongorestore --host hostname:port --db database_name /path/to/backup
其中,hostname
和port
是MongoDB服務器的地址和端口,database_name
是要恢復的數據庫名稱,/path/to/backup
是備份數據的路徑。
恢復特定集合: 如果只想恢復特定的集合,可以使用以下命令:
mongorestore --host hostname:port --db database_name /path/to/backup/collection_name.bson
其中,collection_name.bson
是備份的集合文件。
使用–drop選項:
注意,使用--drop
選項會在恢復數據前刪除目標數據庫中的現有數據。請謹慎使用此選項。
重新啟動MongoDB服務: 恢復數據完成后,重新啟動MongoDB服務:
sudo systemctl start mongod
通過以上步驟,您可以在Ubuntu系統上使用mongorestore
工具恢復MongoDB數據庫的數據。請根據您的實際情況調整命令中的參數。