Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The examples given below make use of so called “ephemeral disk space”.

This means that disk space may become an issue if the database is very big and disk space is limited. The ephemeral disk space is located in /var/lib/kubelet and /var/lib/containers. If you have /var/lib placed on a separate disk, you con check the available space with the following command:

df -h /var/lib

Backup MongoDB

First, open a shell to your (primary) MongoDB node.

To backup the MongoDB instance, run mongodump with the following command-line options:

mongodump --oplog --gzip --archive=/tmp/mongobackup_$(date "+%Y.%m.%d_%H.%M.%S").gz

The --oplog option captures incoming write operations during the mongodump operation to ensure that the backups reflect a consistent data state.

After the backup has completed, there are several ways to retrieve the compressed file from the container. Here is an example for Kubernetes:

kubectl cp cdcm/cdcm-mongodb-0:/tmp/mongobackup_<date>.gz .

The <date> portion needs to be adapted to reflect the actual file.

Restore MongoDB

First, upload the backup to the target instance.

Make sure that you are using the correct context!

Once again, this example applies to Kubernetes:

kubectl cp <archive> cdcm-mongodb-0:/tmp/

To restore the MongoDB instance, run mongorestore with the following command-line options:

mongorestore --gzip --archive=<path-to-archive>

If you used the --oplog option with mongodump, you need to run mongorestore with the --oplogReplay option:

mongorestore --gzip --oplogReplay --archive=<path-to-archive>

Please find the complete documentation at https://www.mongodb.com/docs/manual/tutorial/backup-and-restore-tools/

  • No labels