用不同的名称恢复mongodb数据库

jma*_*jma 3 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_name"
Run Code Online (Sandbox Code Playgroud)

但是生产中的 dbname 是 example_prod,而在登台服务器上,我想恢复到 example_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"
Run Code Online (Sandbox Code Playgroud)

唯一的区别是 --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
Run Code Online (Sandbox Code Playgroud)

我也试过使用--tsFrom=example_prod --tsTo=example_staging,不高兴。

关于正确方法的任何建议?

wil*_*lis 5

我也试过使用 --tsFrom=example_prod --tsTo=example_staging,没有乐趣。

我在 mongorestore 文档中没有看到 tsFrom 和 tsTo——你使用的是哪个版本?https://docs.mongodb.com/manual/reference/program/mongorestore/

看起来有nsFromnsTo选项需要命名空间,所以这样做--nsFrom='example_prod.*'并且--nsTo=example_staging.*应该工作。

从文档:

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