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

Restoring mongodb database with different name

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

time mongorestore  --ssl --gzip --authenticationDatabase=admin \
    --host=fra-mongo-staging-1.example.com --port=27017        \
    --username=restore --password=secret --archive="$snapshot_name"

但是生产中的数据库名称是 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"

唯一的区别是 --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_prod --tsTo=example_staging,不开心。

关于正确的方法有什么建议吗?

I've also tried using --tsFrom=example_prod --tsTo=example_staging, no joy.

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

看起来有 nsFromnsTo 选项采用命名空间,因此 --nsFrom='example_prod.*'--nsTo='example_staging.*' 应该可行。

来自文档:

For simple replacements, use asterisks (*) as wild cards. Escape all literal asterisks and backslashes with a backslash. Replacements correspond linearly to matches: each asterisk in --nsFrom must correspond to an asterisk in --nsTo, and the first asterisk in --nsFrom matches the first asterisk in nsTo.

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

EG,

mongodump --out=tempBackup
mv tempBackup/oldDbName tempBackup/newDbName
mongorestore --nsInclude= newDbName tempBackup

没有 --nsInlnclude 我没试过。