mongodb存档格式是什么?

时间:2019-06-09 05:22:02

标签: mongodb archive restore

我已经使用它们的存档选项备份了一些mongoDB,但是我不能简单地解压缩它们。当我执行一些步骤来解压缩数据时,看起来存档是整个数据库放在一个大文件中。 我想获取各个集合的文件。 有办法吗?

$ tar -xvf valk.archive
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
$ file valk.archive
valk.archive: gzip compressed data, original size 13953183
$ gunzip valk.archive
gunzip: valk.archive: unknown suffix -- ignored
$ unzip valk.archive
Archive:  valk.archive
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of valk.archive or
        valk.archive.zip, and cannot find valk.archive.ZIP, period.
$ mv valk.zip valk.gz
$ gunzip valk.gz
$ open .
$ tar -xvf valk
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
$ head valk
TemplateDatametadata�{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"valk.TemplateData"}],"uuid":"f52402b5aba24856b072d57cc3e46a72"}size-dbvalkcollectioMetricsmetadata�{"options":{"capped":true,"size":10485760,"max":1000000},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"valk.Metrics"},{"v":2,"key":{"openid":1},"name":"openid_1","ns":"valk.Metrics"}],"uuid":"43d92ff01815432c95dac5a2e05a64c0"}size�dbvalkcollection
AppConfigmetadata�{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"valk.AppConfig"}],"uuid":"df633b0a43184de38e8b8ea7489cda3e"}size�dbvalkcollecMinibotZonesmetadata�{"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"valk.MinibotZones"}],"uuid":"095bbac0d17640be9e27dffe681b7d83"}size�dbvalkcollection    ChatLogsmetadataQ{"options":{"capped":true,"size":104857600,"max":10000000},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_","ns":"valk.ChatLogs"},{"v":2,"key":{"openid":1,"createdAt":1},"name":"openid_1_createdAt_1","ns":"valk.ChatLogs"},{"v":2,"key":{"createdAt":1},"name":"createdAt_1","ns":"valk.ChatLogs"}],"uuid":"70586c82b3ae42cf8d9c47ad339ea55b"}size�dbvalkcollection

1 个答案:

答案 0 :(得分:2)

mongodump存档格式是一种特殊用途的格式;您需要将mongorestore --archive与其他合适的选项一起使用。

例如,您可以使用--nsInclude选项(mongorestore 3.4+)按名称空间选择性地还原多个集合。

有关MongoDB存档格式的更多信息(以及为何不适合使用tar的信息),请参见: Archiving and Compression in MongoDB Tools。要点是:

  

通用存档格式(例如tar)仅支持存档内的连续文件打包。将这些存档格式用于mongodump和mongorestore将导致性能下降到无法接受的程度,因为必须按顺序将所有集合中的数据写入和读取。为了支持这些工具的并发行为,我们开发了一种特殊目的的存档格式,该格式支持非连续文件写入。新的存档功能大大提高了备份和还原操作的效率。