Skip to content

Point-in-Time Recovery oplog replay

Starting with version 1.7.0, you can replay the oplog for a specific period on top of any backup: logical, physical, storage level snapshot (like EBS-snapshot). Starting with version 1.8.0, you can save oplog slices without the mandatory base backup snapshot. This behavior is controlled by the pitr.oplogOnly configuration parameter

pitr:
   oplogOnly: true

By replaying these oplog slices on top of the backup snapshot with the oplog replay command, you can manually restore sharded clusters and non sharded replica sets to a specific point in time from a backup made by any tool and not only by Percona Backup for MongoDB. Plus, you reduce time, storage space and administration efforts on making the redundant base backup snapshot.

Warning

Use the oplog replay functionality with caution, only when you are sure about the starting time to replay oplog from. The oplog replay does not guarantee data consistency when restoring from any backup, however, it is less error-prone for backups made with Percona Backup for MongoDB.

Oplog replay for physical backups

To replay the oplog on top of physical backups made with Percona Backup for MongoDB, do the following:

  1. Stop Point-in-Time Recovery, if enabled, to release the lock.

  2. Run pbm status or pbm list commands to find oplog chunks available for replay.

  3. Run the pbm oplog-replay command and specify the --start and --end flags with the timestamps.

$ pbm oplog-replay --start="2022-01-02T15:00:00" --end="2022-01-03T15:00:00"
  1. After the oplog replay, make a fresh backup and enable the Point-in-Time Recovery oplog slicing.

Oplog replay for storage level snapshots

When making a backup, Percona Backup for MongoDB stops the Point-in-Time Recovery. This is done to maintain data consistency after the restore.

Storage-level snapshots are saved with Point-in-Time Recovery enabled. Thus, after the database restore from such a backup, Point-in-Time Recovery is automatically enabled and starts oplog slicing. These new oplog slices might conflict with the existing oplogs saved during the backup. To replay the oplog in such a case, do the following after the restore:

  1. Disable Point-in-Time Recovery

  2. Delete the oplog slices that might have been created

  3. Resync the data from the storage

  4. Run the pbm oplog-replay command and specify the --start and --end flags with the timestamps.

    $ pbm oplog-replay --start="2022-01-02T15:00:00" --end="2022-01-03T15:00:00"
    
  5. After the oplog replay, make a fresh backup and enable the Point-in-Time Recovery oplog slicing.

Known limitations

The oplog replay fails if you rename the entire database or a collection.