Skip to content

Make a point-in-time restore

Preconditions

Run pbm status or pbm list commands to check that the full backup snapshot exists and there are oplog slices.

Before you start

  1. Disable point-in-time recovery. A restore and point-in-time recovery oplog slicing are incompatible operations and cannot be run simultaneously.

    $ pbm config --set pitr.enabled=false
    
  2. Stop the balancer and mongos nodes.

  3. Make sure no writes are made to the database during restore.

Procedure

Run pbm restore and specify the timestamp from the valid range:

$ pbm restore --time="2022-12-14T14:27:04"

The timestamp you specify for the restore must be within the time ranges in the PITR section of pbm list output. Percona Backup for MongoDB automatically selects the most recent backup among logical, physical and incremental in relation to the specified timestamp and uses that as the base for the restore.

To illustrate this behavior, let’s use the following pbm list output as the example.

$ pbm list    

  2021-08-04T13:00:58Z [restore_to_time: 2021-08-04T13:01:23Z]
  2021-08-05T13:00:47Z [restore_to_time: 2021-08-05T13:01:11Z]
  2021-08-06T08:02:44Z [restore_to_time: 2021-08-06T08:03:09Z]
  2021-08-06T08:03:43Z [restore_to_time: 2021-08-06T08:04:08Z]
  2021-08-06T08:18:17Z [restore_to_time: 2021-08-06T08:18:41Z] 

PITR <off>:
  2021-08-04T13:01:24 - 2021-08-05T13:00:11
  2021-08-06T08:03:10 - 2021-08-06T08:18:29
  2021-08-06T08:18:42 - 2021-08-06T08:33:09

For timestamp 2021-08-06T08:10:10, the backup snapshot 2021-08-06T08:02:44Z [restore_to_time: 2021-08-06T08:03:09] is used as the base for the restore as it is the most recent one.

If you select a backup snapshot for the restore with the –-base-snapshot option, the timestamp for the restore must also be later than the selected backup.

See also

Restore a backup

Post-restore steps

A restore operation changes the time line of oplog events. Therefore, all oplog slices made after the restore time stamp and before the last backup become invalid. After the restore is complete, do the following:

  1. Make a new backup to serve as the starting point for oplog updates:

    $ pbm backup
    
  2. Re-enable point-in-time recovery to resume saving oplog slices:

    $ pbm config --set pitr.enabled=true
    

Select a backup snapshot for the restore

Version added: 1.6.0

You can recover your database to the specific point in time using any backup snapshot, and not only the most recent one. Run the pbm restore command with the --base-snapshot=<backup_name> flag where you specify the desired backup snapshot.

To restore from any backup snapshot, Percona Backup for MongoDB requires continuous oplog. After the backup snapshot is made and point-in-time recovery is re-enabled, it copies the oplog saved with the backup snapshot and creates oplog slices from the end time of the latest slice to the new starting point thus making the oplog continuous.

Get expert help

If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services.


Last update: November 1, 2024
Created: November 1, 2024