Backing Up an Instance

Instructions for backing up MongoDB instances using DMK utilities.

This page explains how to back up a MongoDB instance using DMK utilities.


Backup overview

DMK performs backups using the dmk_dbbackup.py script, which supports multiple modes, including full backups and dumps, with or without compression. Backups are stored in a designated backup directory, typically defined by the MONGO_BACKUP_ROOT environment variable.


Performing a backup

To perform a backup of a MongoDB instance, run the following:

mongodb@vm00:/home/mongodb/ [mdb01] dmk_dbbackup.py -i mdb01
2025-06-30 04:18:41 | INFO     | Backup MongoDB instance mdb01 with options: 'None'.
2025-06-30 04:18:41 | INFO     | Backup command: /u01/app/mongodb/product/8.0.11/bin/mongodump --uri="mongodb://<username>:<password>@127.0.0.1:27017/?tls=true&tlsCertificateKeyFile=/u01/app/mongodb/admin/mdb01/secret/mongo-x509/clients/clientUser.pem&tlsCAFile=/u01/app/mongodb/admin/mdb01/secret/mongo-x509/ca/ca.pem" --out /u90/mongodb/backup/mdb01/backup_mdb01_20250630_041841
2025-06-30 04:18:41 | INFO     | Backup directory: '/u90/mongodb/backup/mdb01/backup_mdb01_20250630_041841'
2025-06-30 04:18:41 | INFO     | Backup MongoDB instance mdb01 in progress...
2025-06-30 04:18:41 | INFO     | Backup completed successfully.

By default, the script performs a full, uncompressed mongodump of the MongoDB instance.


Common options

  • -d, --instance_name <name>: (Required) Name of the MongoDB instance. It must match the value of the MONGO_INSTANCE environment variable.

  • -a, --archive: If present, generates the dump with the mongodump --archive option instead of mongodump --out. A single archive file will be generated instead of multiple BSON files.

  • -o, --mongodump_options "<options>": Extra options to pass to the mongodump command (e.g. --gzip, --archive, etc.).

Example:

$DMK_HOME/bin/dmk_dbbackup.py -i mdb01 -o="--gzip" -v

Backup location

Backups are stored in $MONGO_BACKUP_ROOT/<instance_name>/backup_<instance_name>_YYYYMMDD_hhmmss/. Backup logs are sent to $DMK_HOME/logs/backup/backup_<instance_name>_YYYYMMDD_hhmmss.log.


Notes

  • Ensure the MongoDB instance is reachable and running before performing a backup.

  • For replica sets, it is generally recommended to perform backups from a secondary node to avoid impacting the primary.

Last updated