# Backing Up an Instance

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:

```bash
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.16/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:

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

***

#### Backup location

Backups are stored in `$MONGO_BACKUP_ROOT/<instance_name>/backup_<instance_name>_YYYYMMDD_hhmmss/`. Backup logs are sent to `$DMK_HOME/log/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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dbi-services.gitbook.io/dmk-mongodb/managing-databases/backing_up_database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
