Connected On-Prem Backup and Restore Strategy

Updated 3 months ago by Michael Cretzman

This topic covers backup strategies for the Harness On-Prem MongoDB database.

In this topic:

Harness Backup Strategy Overview

Harness On-Prem database backups are extremely important to protect MongoDB Production Database data and prevent data loss. 

MongoDB provides several ways to back up databases:

Apart from the above methods, there are some third-party tools available in the market.

Harness recommends that you schedule both of the following backup methods to protect production systems from data loss:

  • Full Backup Method: Daily full backups using mongodump and crontab (in non-peak hours).
  • Incremental Backup Method: Incremental backups multiple times a day, such as every 30min or 1hr. The backup method depends on the software you have available. For example, file system snapshots, storage replication, or rsync synchronization.
Please test backup commands before using them in Production.

Full Backup Method

Harness recommends you perform full backups daily, using mongodump and crontab (in non-peak hours).

Backup Docker MongoDB with Mongodump and Mongorestore

The mongodump tool provides a very simple method for backing up Docker MongoDB databases in binary format (BSON). Mongodump can run from the base host as well as the Docker container. This backup can be placed on any storage attached to the base host.

Mongodump has other features such as collection-level backup (include or exclude) and consistent backup with the oplog parameter (full backup).

Mongorestore uses backed up BSON files to restore your database.

Backup Process on Docker

To take a full backup of a MongoDB replica set (consistent backup including changes during backup), run the following command on any on node: 

docker exec -it  mongoContainer mongodump --host=rs0/xxxxxx:7144,xxxxxx:7144,192.1xxxx:7144 -u=<admin user> -p=<admin password> --authenticationDatabase=admin  --oplog --out /data/db/backup

To connect to the replica set using the --host parameter, use the string format:hostname1:7144, hostname2:7144, hostname3:7144.

Please don’t keep backup files on the same host. Always keep backup files in a different location.

Restore Process

In the event of a MongoDB replica set loss, you can restore the entire replica set by contacting the Harness Support team. 

The Harness Support team will do the following:

  1. Harness Support brings up the MongoDB containers (Connected On-Prem).
  2. Harness Support uses your backup to restore your database.         

Incremental Backup Method

Harness recommends incremental backups multiple times a day, such as every 30min or 1hr.

Backup With OS Utilities and File System Snapshot

This method copies all of the MongoDB data files using OS-level utilities. Copying multiple files is not atomic, and requires that you stop all writes before copying the files.

Backup Process

  1. Use the secondary node to take the backup, and place the replica set in lock mode:
docker exec -it mongoContainer /usr/bin/mongo --host=rs0/xxxxxxx:27017  -u <admin user> -p <admin password> --authenticationDatabase admin --eval "db.fsyncLock()"
  1. Copy the MongoDB data file to the backup location using cp, rsync, or snapshot. For example:
cp -p -r <datafile location>  <backup location>/
File system snapshot / Storage Replication / rsync
  1. Unlock the replica set after the copy is complete: 
docker exec -it mongoContainer /usr/bin/mongo --host=rs0/xxxxxxx:27017  -u <admin user> -p <admin password> --authenticationDatabase admin --eval "db.fsyncUnlock()"

Restore Process

To restore the entire replica set, the following steps are performed:

  • Harness Support brings up the MongoDB containers (Connected On-Prem).
  • You copy all of the backup files to /data/db/ (on all 3 replicas).
  • Harness Support uses the backup to restore the database.


How did we do?