【问题标题】:MongoDB DigitalOcean using mongodump and mongorestoreMongoDB DigitalOcean 使用 mongodump 和 mongorestore
【发布时间】:2018-05-30 15:46:33
【问题描述】:
我正在尝试将 mongo 数据库迁移到 DigitalOcean 服务器上。我已将文件转储到本地系统(mac)上。另外,我尝试使用 SCP 文件传输(错误)并尝试使用 mongorestore。如果有人有一个很好的例子来说明如何做到这一点,将不胜感激。
【问题讨论】:
标签:
linux
mongodb
scp
mongorestore
【解决方案1】:
使用 Digital Ocean mongorestore,您必须使用 --uri 标志来设置连接字符串。您还需要在连接字符串中指定 CA 证书文件的路径。例如。
mongorestore --uri="mongodb+srv://**username**:**host**/admin?authSource=admin&replicaSet=db-mongodb-fra1-xxxxxx&tls=true&tlsCAFile=**c:\ca-certificate.crt**" --archive=mobivote.gz --gzip
只需使用密码从 DO 数据库面板(连接字符串)复制 uri。下载 CA 证书并在连接字符串的 CAFile 中指定路径。
如果您的备份是存档,请使用 --archive 指定文件并使用 --gzip 指定压缩。
【解决方案2】:
mongodump
mongodump --host <HOST_DETAILS> --username <USERNAME> --password <PASSWORD> --authenticationDatabase admin --db <DATABASE>
可以在mongodump中使用--gzip来启用压缩
mongorestore
mongorestore --host <HOST_DETAILS> --username <USERNAME> --password <PASSWORD> --db <database> --authenticationDatabase admin --dir <PATH>
在mongorestore 中包含--gzip 以从压缩转储中恢复