mongo备份索引,为什么mongodump不备份索引?

While reading the mongodump documentation, I came across this information.

"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."

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?

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.

2. We save space required for storing the backups.

But why not have it as an option at all?

解决方案

mongodump creates a binary export of data from a MongoDB database (in BSON format). The index definitions are backed up in .metadata.json files, so mongorestore can recreate the original data & indexes.

There are two main reasons that the actual indexes cannot be backed up with 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.

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). 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).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值