【问题标题】:Restoring mongodb database with different name使用不同的名称恢复 mongodb 数据库
【发布时间】:2019-02-11 12:20:37
【问题描述】:

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

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

但生产中的 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"

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

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

【问题讨论】:

标签: mongodb mongorestore


【解决方案1】:

我也尝试过使用--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 中的第一个星号匹配。

【讨论】:

【解决方案2】:

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

EG,

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

如果没有 --nsInlnclude,我没有尝试过。

【讨论】:

    猜你喜欢
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 1970-01-01
    • 1970-01-01
    • 2021-01-14
    相关资源
    最近更新 更多