Mongorestore--gzip--archive失败,成功还原了0个文档.0个文档失败



经过数小时的互联网搜索(包括Stackoverflow(,来回查看MongoDB官方网站的文档。我仍然没有找到解决方案,为什么我的mongodump存档文件没有用以下命令恢复

mongorestore --gzip --drop --nsInclude="*" --archive=/./././code/backups/notura-db-1659281356578.gzip -v

我得到以下输出:

2022-07-31T23:55:19.574+0200    using write concern: &{majority false 0}
2022-07-31T23:55:19.606+0200    will listen for SIGTERM, SIGINT, and SIGKILL
2022-07-31T23:55:19.607+0200    connected to node type: standalone
2022-07-31T23:55:19.619+0200    archive format version "0.1"
2022-07-31T23:55:19.619+0200    archive server version "5.0.3"
2022-07-31T23:55:19.619+0200    archive tool version "100.5.1"
2022-07-31T23:55:19.620+0200    preparing collections to restore from
2022-07-31T23:55:19.632+0200    demux finishing (err:<nil>)
2022-07-31T23:55:19.632+0200    received  from namespaceChan
2022-07-31T23:55:19.632+0200    restoring up to 4 collections in parallel
2022-07-31T23:55:19.632+0200    building indexes up to 4 collections in parallel
2022-07-31T23:55:19.632+0200    0 document(s) restored successfully. 0 document(s) failed to restore.

我没有收到任何错误消息,我的数据库也没有更新。

我正在运行MongoDB 5.0.3 Community

非常感谢您的帮助!

Aron

找到了解决方案,你可以在这里看到我对此的讨论:

https://www.mongodb.com/community/forums/t/mongorestore-gzip-archive-failed-w-0-document-s-restored-successfully-0-document-s-failed/178114/5

了解数据库名称是否确实正确非常重要。如果您没有在MongoDB shell中指定任何(使用mongosh、mongod或mongo输入(-->使用您的数据库名称,通过show dbs(在mongodb shell中(,您将看到有哪些数据库。创建一个或使用标准的测试。

写入以下内容以转储数据库:mongodump --uri="mongodb://localhost:27017" --db="your-database-name" --gzip --archive=/code/backups/notura-db.gz

在备份文件夹中,将创建notura-db.gz文件。在使用更复杂的方法之前,您可以通过执行mongoexport/mongoimport来查看是否一切正常。

要恢复数据,请使用以下命令行命令:mongorestore --drop --gzip --nsInclude="*" --archive=/code/backups/notura-db.gz -v

干杯!

Aron

最新更新