In Percona Backup for MongoDB version 1.4.1 and earlier, we recommend using
crond or similar services to schedule backup snapshots.
The recommended approach is to create a
crontab file in the
/etc/cron.d directory and specify the command in it. This simplifies server administration especially if multiple users have access to it.
pbm CLI requires a valid MongoDB URI connection string to authenticate in MongoDB. Instead of specifying the MongoDB URI connection string as a command line argument, which is a potential security risk, we recommend creating an environment file and specify the
export PBM_MONGODB_URI=$PBM_MONGODB_URI statement within.
As an example, let’s configure to run backup snapshots on 23:30 every Sunday. The steps are the following:
Create an environment file. Let’s name it
pbm-cron. The path for this file on Debian and Ubuntu is
/etc/default/pbm-cron. For Red Hat Enterprise Linux and CentOS, the path is
Specify the environment variable in
Grant access to the
pbm-cronfile for the user that will execute the
crontabfile. Let’s name it
Specify the command in the file:
30 23 * * sun <user-to-execute-cron-task> . /etc/default/pbm-cron; /usr/bin/pbm backup
Note the dot
.before the environment file. It sources (includes) the environment file for the rest of the shell commands.
Verify that backups are running in
$ grep CRON /var/log/syslog
Backup storage cleanup
Previous backups are not automatically removed from the backup storage. You need to remove the oldest ones periodically to limit the amount of space used in the backup storage.
We recommend using the pbm delete backup --older-than <timestamp> command. You can configure a
cron task to automate backup deletion by specifying the following command in the
/usr/bin/pbm delete-backup -f --older-than $(date -d '-1 month' +\%Y-\%m-\%d)
This command deletes backups that are older than 30 days. You can change the period by specifying a desired interval for the
Schedule backups with Point-in-Time Recovery running¶
It is convenient to automate making backups on a schedule using
crond if you enabled Point-in-Time Recovery.
You can configure Point-in-Time Recovery and
crond in any order. Note, however, that Point-in-Time Recovery will only start running after at least one full backup has been made.
Make a fresh backup manually. It will serve as the starting point for incremental backups
Enable point-in-time recovery
crondto run backup snapshots on a schedule
When it is time for another backup snapshot, Percona Backup for MongoDB automatically disables Point-in-Time Recovery and re-enables it once the backup is complete.