Skip to content
logo
Percona Backup for MongoDB
Schedule backups
Initializing search
    percona/pbm-docs
    percona/pbm-docs
    • Home
      • How PBM works
      • Components
      • Supported MongoDB versions
      • Supported MongoDB deployments
      • Install
      • Set up and configure
      • Overview
      • Physical backups
      • Incremental physical backups
      • Logical backups
      • Selective backups
      • Point-in-Time Recovery
      • Start a backup
      • List backups
      • Restore a backup
      • View restore progress
      • Cancel a backup
      • Delete backups
      • View backup logs
      • Replay oplog from arbitrary start time
      • Architecture
      • Authentication
        • Overview
        • Remote backup configuration examples
      • Schedule backups
        • Schedule backups with Point-in-Time Recovery running
        • Backup storage cleanup
      • Configure PBM remotely
      • Upgrade PBM
      • Troubleshoot PBM
      • Automate access to S3 buckets for PBM
      • Remove PBM
    • FAQ
      • PBM commands
        • Configuration file
        • Remote backup storage options
        • Point-in-time recovery options
        • Backup options
        • Restore options
      • Glossary
      • Release notes index
      • Percona Backup for MongoDB 2.0.5 (2023-03-23)
      • Percona Backup for MongoDB 2.0.4 (2023-02-21)
      • Percona Backup for MongoDB 2.0.3 (2023-01-11)
      • Percona Backup for MongoDB 2.0.2 (2022-10-27)
      • Percona Backup for MongoDB 2.0.1 (2022-10-12)
      • Percona Backup for MongoDB 2.0.0 (2022-09-21)
      • Percona Backup for MongoDB 1.8.1 (2022-07-12)
      • Percona Backup for MongoDB 1.8.0 (2022-06-09)
      • Percona Backup for MongoDB 1.7.0 (2022-04-18)
      • Percona Backup for MongoDB 1.6.1 (2021-11-04)
      • Percona Backup for MongoDB 1.6.0 (2021-08-16)
      • Percona Backup for MongoDB 1.5.0 (2021-05-10)
      • Percona Backup for MongoDB 1.4.1 (2021-01-28)
      • Percona Backup for MongoDB 1.4.0 (2020-12-24)
      • Percona Backup for MongoDB 1.3.4 (2020-11-19)
      • Percona Backup for MongoDB 1.3.3 (2020-11-04)
      • Percona Backup for MongoDB 1.3.2 (2020-10-14)
      • Percona Backup for MongoDB 1.3.1 (2020-09-03)
      • Percona Backup for MongoDB 1.3.0 (2020-08-26)
      • Percona Backup for MongoDB 1.2.1 (2020-07-27)
      • Percona Backup for MongoDB 1.2.0 (2020-05-13)
      • Percona Backup for MongoDB 1.1.3 (2020-04-14)
      • Percona Backup for MongoDB 1.1.1 (2020-01-31)
      • Percona Backup for MongoDB 1.1.0 (2020-01-16)
      • Percona Backup for MongoDB 1.0.0 (2019-09-19)
      • Percona Backup for MongoDB 0.5.0 (2019-06-17)
    • Submitting bug reports or feature requests
    • Copyright and Licensing
    • Trademark policy

    • Schedule backups with Point-in-Time Recovery running
    • Backup storage cleanup

    Schedule backups¶

    We recommend using crond or similar services to schedule backup snapshots.

    Important

    Before configuring crond, make sure that you have installed and configured Percona Backup for MongoDB to make backups in your database. Start a backup manually to verify this:

    pbm backup
    

    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:

    1. Create an environment file. Let’s name it pbm-cron.

      vim /etc/default/pbm-cron
      
      vim /etc/sysconfig/pbm-cron
      
    2. Specify the environment variable in pbm-cron:

      export PBM_MONGODB_URI="mongodb://pbmuser:secretpwd@localhost:27018?/replSetName=xxxx"
      
    3. Grant access to the pbm-cron file for the user that will execute the cron task.

    4. Create a crontab file. Let’s name it pbm-backup.

      touch pbm-backup
      
    5. 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.

    6. Verify that backups are running in /var/log/cron or /var/log/syslog logs:

      grep CRON /var/log/syslog
      

    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
    • Configure crond to 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.

    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 crontab file:

    /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 date function.

    Contact Us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.


    Last update: March 23, 2023
    Created: March 23, 2023
    Percona LLC and/or its affiliates, © 2023
    Made with Material for MkDocs

    Cookie consent

    We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.