Skip to content

How Percona Backup for MongoDB works

Even in a highly-available architecture, such as with MongoDB replication, backups are still required even though losing one server is not fatal. Be it a complete or partial data disaster, you can use PBM (Percona Backup for MongoDB) to go back in time to the best available backup snapshot.

Percona Backup for MongoDB is a command line interface tool. It provides the set of commands to manage backup and restore operations in your database.

What backup to choose?

Usage example

Let’s have a look at how Percona Backup for MongoDB works.

With Percona Backup for MongoDB up and running in your environment, make a backup:

$ pbm backup --type=logical

To save all events that occurred to the data between backups, enable saving oplog slices:

$ pbm config --set pitr.enabled=true

Now, imagine that your web application’s update was released on February 7 at 03:00 UTC. By 15:23 UTC, someone realizes that this update has a bug that is wiping the historical data of any user who logged in. To remediate this negative impact on data, it’s time to roll back up to the time of the application’s update - up to February 7, 03:00 UTC.

$ pbm list
Sample output
Backup snapshots:
    2024-02-05T13:55:55Z [complete: 2024-02-05T13:56:15]
    2024-02-07T13:57:58Z [complete: 2024-02-07T13:58:17]
    2024-02-03T08:08:15Z [complete: 2024-02-03T08:08:35]
    2024-02-09T14:06:06Z [complete: 2024-02-09T14:06:26]
    2024-02-11T14:22:41Z [complete: 2024-02-11T14:23:01]

The output lists the valid time ranges for the restore. The desired time (February 7, 03:00 UTC) falls within the 2024-02-03T08:08:36Z-2024-02-09T12:20:23Z range, so let’s restore the database up to that time.

$ pbm restore --time 2024-02-07T02:59:59

To be on the safe side, it is a good practice to make a fresh backup after the restore is complete.

$ pbm backup

This backup refreshes the timeline and serves as the base for saving oplog slices. To re-enable this process, run:

$ pbm config --set pitr.enabled=true

Next steps

Ready to try it out?

Quickstart

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: December 18, 2024
Created: December 18, 2024