Percona Backup for MongoDB (PBM) supports snapshot-based physical backups. This is made possible by the backup cursor functionality present in Percona Server for MongoDB. 

The flow of snapshot-based physical backup consists of these stages:

  • Preparing the database – done by PBM
  • Taking the snapshots – done by the user/client app
  • Completing the backup – done by PBM

A more detailed description of what happens on each step can be found in the PBM documentation.

Let’s see a practical example of performing an actual backup. For this demo, I have created a 2-shard MongoDB cluster (each shard consisting of a 3-node replica set) deployed on Google Cloud Platform instances. Each instance has an extra persistent disk attached to it for the MongoDB data. PBM agent is installed on each instance as per the documentation.

Manual example

First, we start an external backup. This can be done from any host running the PBM client.

As we can see, PBM selects one node of each shard and one config server to be backed up.

At this point, we need to create snapshots of the hosts listed above. We could use the Google Cloud web console or run gcloud commands, as below.

Let’s list the attached disks of the first instance:

Once we know the attached disks, we can snapshot them. For example:

After repeating the above commands for all the instances listed, we need to complete the backup:

Finally, let’s check the backup status:

Automating the process

Now, the manual approach is ok but let’s see how we can automate the above.

Creating a service account

I haven’t mentioned authentication yet. We are going to use a service account with the required permissions to take snapshots. Another possibility could be using an IAM user with an associated HMAC key pair. Here are the steps to create the service account:

1.  Set your project ID

2. Create the service account

3. Assign Compute Admin and Compute Storage Admin roles

4. Generate and download the service account key file

The service account file should look like this:

With the service account ready, we can now start working on our automation.

Sample script

To automate the process, we loop through the list of hosts selected by PBM, get all the attached volumes, and create snapshots of them with descriptive names.

The following script requires gcloud CLI to be installed. Keep in mind this is just a proof of concept, so don’t use it for production environments, as there is only basic error checking. 

Looking ahead

Percona Backup for MongoDB provides the interface for making snapshot-based physical backups and restores. Database owners benefit from faster and more cost-efficient backups while ensuring that their data remains consistent.

This is the first stage of snapshot-based backups, and automated snapshot-based backups are planned for the future. If you have any suggestions for feature requests or bug reports, make sure to let us know by creating a ticket in our public issue tracker. Pull requests are also more than welcome!

Continue on to part two of this series.


MongoDB Performance Tuning is a collection of insights, strategies, and best practices from Percona’s MongoDB experts. Use it to diagnose — and correct — the issues that may be affecting your database’s performance.

 

Download MongoDB Performance Tuning today!

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments