简体   繁体   English

mongodump oplog,备份单个数据库

[英]mongodump oplog, backup a single database

I want to create an incremental backup strategy from a single database using oplog 我想使用oplog从单个数据库创建增量备份策略

since the --oplog option from mongodump creates a dump of full version, I wonder if there is any way to: 由于mongodump的--oplog选项创建了完整版本的转储,所以我想知道是否有任何方法可以:

  1. make a dump from a single database using the oplog option from "x" seconds ago? 使用 “ x”秒前的oplog选项单个数据库 进行转储?
  2. make a dump from a single collection using the oplog option from "x" seconds ago? 使用 “ x”秒前的oplog选项单个集合 进行转储?

since the --oplog version from mongodump creates a dump of full version 因为mongodump的--oplog版本会创建完整版本的转储

Actually, mongodump --oplog creates a partial dump of the oplog that only contains operations from the duration of the mongodump operation. 其实, mongodump --oplog创建的部分转储oplog只包含从持续时间操作mongodump操作。 The purpose of this option is to capture an effective point-in-time state of the database, as otherwise write operations during the mongodump procedure can affect the output of the backup. 此选项的目的是捕获数据库的有效时间点状态,否则,在mongodump过程中进行的写操作可能会影响备份的输出。

make a dump from a single database using the oplog option from "x" seconds ago? 使用“ x”秒前的oplog选项从单个数据库进行转储?

make a dump from a single collection using the oplog option from "x" seconds ago? 使用“ x”秒前的oplog选项从单个集合进行转储?

You can't use the oplog to dump a database or collection snapshot from X seconds ago: 您无法使用oplog转储X秒前的数据库或集合快照:

  • In order for the oplog to be usefully applied in a restore procedure, the oplog has to have an entry in common with your last full backup. 为了在还原过程中有用地应用操作日志,操作日志必须具有与上次完整备份相同的条目。

  • You can't efficiently dump a subset of the oplog as there are no indexes (and the oplog is a special-use capped collection that does not support adding indexes). 您无法有效地转储oplog的子集,因为没有索引(并且oplog是一个特殊用途的带帽集合,不支持添加索引)。

Backup Strategy 备份策略

Your backup strategy using the oplog would be: 使用oplog的备份策略为:

  • create periodic full backup of your database 创建数据库的定期完整备份
  • periodically backup the full oplog 定期备份完整的操作日志

You can use the oplog to do a point-in-time restore, but it's not very effective as an incremental backup strategy since you have to backup the full oplog. 您可以使用oplog进行时间点还原,但是由于必须备份完整的oplog,它作为增量备份策略并不是很有效。

If you want to incrementally backup a single collection, you could potentially do so using mongodump and a "last updated field" (or for an insert-only collection, a "created" timestamp). 如果要增量备份单个集合,则可以使用mongodump和“最后更新的字段”(或对于仅插入集合,使用“创建的”时间戳)进行备份。

A more common way to achieve a quick point in time backup for a replica set is using a filesystem snapshot . 为副本集实现快速时间点备份的一种更常见的方法是使用文件系统快照 Depending on your underlying storage layer, filesystem snapshots can generally be completed quickly with efficient storage of changes between successive snapshots. 根据底层存储层的不同,通常可以通过有效存储连续快照之间的更改来快速完成文件系统快照。 Snapshots are local, so you still have to consider how you will export backups offsite as part of your overall strategy. 快照是本地快照,因此,作为整体策略的一部分,您仍然必须考虑如何将备份导出到异地。

Caveats of mongodump for backup mongodump备份注意事项

When you use mongodump to backup you should also be aware that this: 使用mongodump备份时 ,还应该注意以下mongodump

  • Requires reading all data, so may swap useful data out of memory if your data set is much larger than memory. 需要读取所有数据,因此如果您的数据集远大于内存,则可能会将有用的数据交换出内存。
  • Exports the full data (except the local database, which includes the oplog), but only the definitions for indexes. 导出完整数据( local数据库除外,该数据库包括操作日志),但仅导出索引的定义。
  • The mongodump backup will use the least space (since you don't have preallocated storage or indexes) but will also have the longest time to restore (since mongorestore will have to rebuild all the data files and indexes). mongodump备份将使用最少的空间(因为您没有预分配的存储或索引),但还原时间也最长(因为mongorestore必须重建所有数据文件和索引)。

Related questions: 相关问题:

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

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