问题描述
在MongoDB中,是否可以转储数据库并将内容还原到其他数据库?例如这样的
In MongoDB, is it possible to dump a database and restore the content to a different database? For example like this:
mongodump --db db1 --out dumpdir
mongorestore --db db2 --dir dumpdir
但是它不起作用.这是错误消息:
But it doesn't work. Here's the error message:
不知道如何处理子目录"dumpdir/db1",正在跳过...
don't know what to do with subdirectory "dumpdir/db1", skipping...
完成
推荐答案
您实际上需要指向"数据库名称容器目录位于"上一个转储的输出目录内:
You need to actually point at the "database name" container directory "within" the output directory from the previous dump:
mongorestore -d db2 dumpdir/db1
通常< path>可以用作位置参数,而不是使用-dir
,只有在位置不正确"(即在参数列表的中间")时才需要使用-dir
.
And usually just <path> is fine as a positional argument rather than with -dir
which would only be needed when "out of position" i.e "in the middle of the arguments list".
p.s.对于存档备份文件(使用mongorestore v3进行已测试 .4.10)
p.s. For archive backup file (tested with mongorestore v3.4.10)
mongorestore --gzip --archive=${BACKUP_FILE_GZ} --nsFrom "${DB_NAME}.*" --nsTo "${DB_NAME_RESTORE}.*"
这篇关于Mongorestore到另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!