如何使用 mongorestore 命令从备份中恢复特定数据库

pan*_*ary 70 mongodb

我使用 mongodump 命令创建了所有数据库的备份。现在我想使用 mongorestore 命令恢复特定的数据库。

这怎么可能,我使用这个命令:--db 选项然后 mongodb 不恢复特定的数据库。

Ste*_*nie 103

要恢复单个数据库,您需要在mongorestore命令行中提供转储目录的路径。

例如:

# Backup the training database
mongodump --db training

# Restore the training database to a new database called training2
mongorestore --db training2 dump/training
Run Code Online (Sandbox Code Playgroud)

--db对选项mongodump指定源数据库转储。

--db对选项mongorestore指定目标数据库恢复到。


小智 20

使用以下命令恢复 mongo db:

mongorestore -d dbname dbpath
Run Code Online (Sandbox Code Playgroud)


dou*_*ack 11

$ mongorestore --drop -d <database-name> <dir-of-backup-files>
Run Code Online (Sandbox Code Playgroud)
  • --drop 如果要替换现有数据库,则必须删除
  • -d <database-name> 要创建/替换的数据库的名称
  • <dir-of-backup-files> 出于某种原因,即使它是当前目录,这也是必要的

在此处输入图片说明

参考:https : //coderwall.com/p/3hx06a/restore-a-mongodb-database-mongorestore