简体   繁体   English

为什么mongodump不备份索引?

[英]Why mongodump does not backup indexes?

While reading the mongodump documentation, I came across this information. 在阅读mongodump文档时,我发现了这些信息。 "mongodump only captures the documents in the database in its backup data and does not include index data. mongorestore or mongod must then rebuild the indexes after restoring data." “mongodump只在其备份数据中捕获数据库中的文档,并且不包括索引数据。然后mongorestore或mongod必须在恢复数据后重建索引。”

Considering that indexes are also critical piece of the database puzzle and they form required to be rebuilt, why doesn't mongodump have an option of taking the backups with indexes? 考虑到索引也是数据库难题的关键部分,并且它们需要重建,为什么mongodump没有选择使用索引进行备份?

I get that there are two advantages of not backing up indexes as a default option: 1. We save time which would otherwise be required for backup and restore of indexes. 我知道没有备份索引作为默认选项有两个好处:1。我们节省了备份和恢复索引所需的时间。 2. We save space required for storing the backups. 2.我们节省了存储备份所需的空间。

But why not have it as an option at all? 但为什么不把它作为一种选择呢?

mongodump creates a binary export of data from a MongoDB database (in BSON format). mongodump从MongoDB数据库(BSON格式)创建数据的二进制导出。 The index definitions are backed up in <dbname>.metadata.json files, so mongorestore can recreate the original data & indexes. 索引定义<dbname>.metadata.json文件中备份,因此mongorestore可以重新创建原始数据和索引。

There are two main reasons that the actual indexes cannot be backed up with mongodump : 使用mongodump无法备份实际索引有两个主要原因:

  • Indexes point to locations in the data files. 索引指向数据文件中的位置。 The data files do not exist if you are only exporting the documents in the data files (rather than taking a full file copy of the data files). 如果仅导出数据文件中的文档(而不是获取数据文件的完整文件副本),则数据文件不存在。

  • The format of indexes on disk is storage-engine specific, whereas mongodump is intended to be storage-engine independent. 磁盘上的索引格式是特定于存储引擎的,而mongodump旨在独立于存储引擎。

If you want a full backup of data & indexes, you need to backup by copying the underlying data files (typically by using filesystem or EBS snapshots). 如果要完整备份数据和索引,则需要通过复制基础数据文件进行备份 (通常使用文件系统或EBS快照)。 This is a more common option for larger deployments, as mongodump requires reading all data into the mongod process (which will evict some of your working set if your database is larger than memory). 对于大型部署来说,这是一个更常见的选项,因为mongodump需要将所有数据读入mongod进程(如果数据库大于内存,将会驱逐一些工作集)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM