恢复具有不同名称的mongodb数据库

恢复具有不同名称的mongodb数据库,mongodb,mongorestore,Mongodb,Mongorestore,我一直在定期(每24小时)备份我的mongodb实例。这非常有效,我可以在我的暂存服务器上毫无问题地恢复它们: time mongorestore --ssl --gzip --authenticationDatabase=admin \ --host=fra-mongo-staging-1.example.com --port=27017 \ --username=restore --password=secret --archive="$snapshot_na

我一直在定期(每24小时)备份我的mongodb实例。这非常有效,我可以在我的暂存服务器上毫无问题地恢复它们:

time mongorestore  --ssl --gzip --authenticationDatabase=admin \
    --host=fra-mongo-staging-1.example.com --port=27017        \
    --username=restore --password=secret --archive="$snapshot_name"
但是生产环境中的dbname是example\u prod,而在staging服务器上,我希望恢复到example\u staging。所以我输入这个:

time mongorestore  --ssl --gzip --db "$dbname" --authenticationDatabase=admin \
    --host=fra-mongo-staging-1.example.com --port=27017                       \
    --username=restore --password=secret --archive="$snapshot_name"
唯一的区别是--db“$dbname”(其中$dbname是example_staging)。这不起作用:我看到了关于准备的台词,然后它说“完成”,但什么都没有恢复

2019-02-07T11:16:36.743+0000    the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2019-02-07T11:16:36.772+0000    archive prelude example_prod.surveys
2019-02-07T11:16:36.773+0000    archive prelude example_prod.settings
2019-02-07T11:16:36.773+0000    archive prelude example_prod.spines
2019-02-07T11:16:36.773+0000    archive prelude example_prod.reduced_authors
2019-02-07T11:16:36.773+0000    archive prelude example_prod.delayed_backend_mongoid_jobs
2019-02-07T11:16:36.773+0000    archive prelude example_prod.email_events
2019-02-07T11:16:36.773+0000    archive prelude example_prod.authors
2019-02-07T11:16:36.774+0000    archive prelude example_prod.crowberry
2019-02-07T11:16:36.774+0000    archive prelude example_prod.bitly
2019-02-07T11:16:36.774+0000    archive prelude example_prod.mytestcollection
2019-02-07T11:16:36.774+0000    archive prelude example_prod.reviews
2019-02-07T11:16:36.774+0000    archive prelude example_prod.books
2019-02-07T11:16:36.774+0000    archive prelude example_prod.candy_events
2019-02-07T11:16:36.774+0000    archive prelude example_prod.features
2019-02-07T11:16:36.774+0000    archive prelude example_prod.elderberry
2019-02-07T11:16:36.776+0000    preparing collections to restore from
2019-02-07T11:17:02.403+0000    done
我还尝试过使用
--tsFrom=example\u prod--tsTo=example\u staging
,没有乐趣

对正确的方法有什么建议吗

我还尝试使用--tsFrom=example\u prod--tsTo=example\u staging,no joy

我在mongorestore文档中没有看到tsFrom&tsTo,您使用的是哪个版本

似乎有
nsFrom
nsTo
选项采用了名称空间,因此执行
--nsFrom='example\u prod.*.'
--nsTo=example\u staging.*
应该可以工作

从文档中:

对于简单的替换,请使用星号(*)作为通配符。用反斜杠转义所有文字星号和反斜杠。替换与匹配项线性对应:--nsFrom中的每个星号必须与--nsTo中的一个星号对应,并且--nsFrom中的第一个星号与nsTo中的第一个星号匹配


另一种方法是转储数据库,重命名文件夹并使用新名称导入

例如


如果没有--nsinlude.

可能这会对我使用3.6.5版有所帮助。那么你应该使用
nsFrom
nsTo
而不是
tsFrom
tsTo
——是的,我缺少的是s/ts/ns/和“*”。谢谢
mongodump --out=tempBackup
mv tempBackup/oldDbName tempBackup/newDbName
mongorestore --nsInclude= newDbName tempBackup