Percona released Percona Backup MongoDB version 1.3.1 and it brings a feature that was hugely expected by the community. It’s the ability to perform consistent incremental backups. This allows us to perform Point in Time Recovery (PITR).
Let’s see how to run a full backup with incremental backup in details.
First, it is necessary to have the PBM agent installed on the host where the mongoD
process is running. You can install using YUM or APT.
To install using YUM:
1 |
bash> sudo yum upgrade percona-backup-mongodb |
Next, you need to start the pbm-agent
in the server where mongoD
process is running. You can use systemctl
or nohup
. For, example, using systemctl
:
1 |
bash> systemctl start pbm-agent |
In, this example, I’m going to start manually and in the foreground just for illustrative purposes:
1 2 3 4 5 6 7 8 9 10 |
bash> pbm-agent --mongodb-uri "mongodb://user:password@localhost:37017/" 2020/09/05 18:48:01 pbm-agent Version: 1.3.1 Platform: linux/amd64 GitCommit: b5f389676c6d3f11a027ee4aa782c6d4514bd854 GitBranch: release-1.3.1 BuildTime: 2020-09-02_00:55_UTC GoVersion: go1.14.2 2020/09/05 18:48:01 starting pitr routine 2020/09/05 18:48:01 listening for the commands 2020/09/05 18:48:01 node: replset/localhost:37017 |
Now, we need to install pbm
on another host. The pbm
is the utility that will execute the backups. Percona backup for MongoDB allows to stream to AWS S3 or to the filesystem. In this case, I’m going to use the filesystem and enable PITR
feature. I’m going to create a config.yaml
file with the settings:
1 2 3 4 5 6 |
pitr: enabled: true storage: type: filesystem filesystem: path: /home/vinicius.grippa/data/backup |
Once we did it, I’m going to set the initial configuration on pbm
:
1 2 3 4 5 6 7 8 9 10 |
bash> export PBM_MONGODB_URI="mongodb://user:password@10.10.0.1:37017/" bash> pbm config --file=config.yaml [Config set] ------ pitr: enabled: true storage: type: filesystem filesystem: path: /home/vinicius.grippa/data/backup |
If we look at the pbm-agent output:
1 2 3 4 |
2020/09/05 19:12:41 Got command resyncBcpList [{resyncBcpList { } { } { 0} 1599347561}] 2020/09/05 23:12:41 [INFO] resyncBcpList: started 2020/09/05 23:12:41 [INFO] resyncBcpList: succeed 2020/09/05 23:13:49 [ERROR] pitr: defining starting point for the backup: no backup found, a new backup is required to start PITR |
The last error message is expected because we do not have a full backup at this point. But now everything is ready. So let’s start a backup:
1 |
bash> pbm backup |
And that’s it. Let’s check our backup:
1 2 3 4 5 |
bash> pbm list Backup snapshots: 2020-09-05T23:26:12Z PITR <on>: 2020-09-05T23:27:01 - 2020-09-05T23:38:29 |
And it is done! If we check our directory we will see the files:
1 2 3 4 5 6 7 8 9 10 11 |
bash> ls -larth backup/ total 44K drwxr-xr-x. 4 vinicius.grippa percona 4.0K Sep 5 19:13 .. -rw-rw-r--. 1 vinicius.grippa percona 5.9K Sep 5 19:27 2020-09-05T23:26:12Z_replset.dump.s2 -rw-rw-r--. 1 vinicius.grippa percona 818 Sep 5 19:27 2020-09-05T23:26:12Z_replset.oplog.s2 -rw-rw-r--. 1 vinicius.grippa percona 1.4K Sep 5 19:27 2020-09-05T23:26:12Z.pbm.json drwxr-xr-x. 3 vinicius.grippa percona 4.0K Sep 5 19:27 pbmPitr -rw-rw-r--. 1 vinicius.grippa percona 6.1K Sep 5 19:50 2020-09-05T23:49:24Z_replset.dump.s2 -rw-rw-r--. 1 vinicius.grippa percona 816 Sep 5 19:50 2020-09-05T23:49:24Z_replset.oplog.s2 -rw-rw-r--. 1 vinicius.grippa percona 1.4K Sep 5 19:50 2020-09-05T23:49:24Z.pbm.json drwxr-xr-x. 3 vinicius.grippa percona 4.0K Sep 5 19:50 . |
And the PITR directory:
1 2 3 4 5 6 7 |
bash> ls -larth replset/20200905/ total 28K drwxr-xr-x. 3 vinicius.grippa percona 4.0K Sep 5 19:27 .. -rw-rw-r--. 1 vinicius.grippa percona 7.4K Sep 5 19:38 20200905232701-3.20200905233829-1.oplog.snappy -rw-rw-r--. 1 vinicius.grippa percona 6.3K Sep 5 19:48 20200905233829-1.20200905234829-1.oplog.snappy drwxr-xr-x. 2 vinicius.grippa percona 4.0K Sep 5 19:50 . -rw-rw-r--. 1 vinicius.grippa percona 2.8K Sep 5 19:50 20200905234829-1.20200905235013-1.oplog.snappy |
As we can see, it is very easy to run backups with PITR. And it is a tool completely open source. The only similar option is available on Atlas (paid cloud form MongoDB) which is not open source.
See you next!