Skip to content
Contact Us

Backup & Disaster Recovery

Learn how to implement a robust backup strategy for your Mirth Connect or Open Integration Engine configurations. This guide covers automated backup scripts, retention policies, and step-by-step disaster recovery procedures.

Traditional database backups capture a single point in time. MirthSync’s Git-based approach provides superior disaster recovery capabilities:

FeatureDatabase BackupMirthSync Git Backup
Point-in-time recoverySingle snapshotAny commit in history
Change trackingNo historyFull audit trail
Selective restoreAll or nothingIndividual channels
Offsite redundancyRequires separate setupBuilt-in with Git remotes
Team collaborationNot designed for itBranch and merge
Backup flow from Mirth database to Git remote and cloud

Create a backup script that runs automatically:

/opt/mirthsync/backup.sh
#!/bin/bash
# Configuration
BACKUP_DIR="/opt/mirthsync/mirth-backup"
LOG_FILE="/var/log/mirthsync-backup.log"
DATE=$(date '+%Y-%m-%d %H:%M:%S')
# Navigate to backup directory
cd "$BACKUP_DIR" || exit 1
# Pull latest configuration
echo "[$DATE] Starting backup..." >> "$LOG_FILE"
./mirthsync.sh pull -s "$MIRTH_URL" -u "$MIRTH_USER" -t "$BACKUP_DIR" >> "$LOG_FILE" 2>&1
# Check if there are changes
if git diff --quiet && git diff --cached --quiet; then
echo "[$DATE] No changes detected" >> "$LOG_FILE"
exit 0
fi
# Commit and push changes
./mirthsync.sh -t "$BACKUP_DIR" git add >> "$LOG_FILE" 2>&1
./mirthsync.sh -t "$BACKUP_DIR" --commit-message "Automated backup $DATE" git commit >> "$LOG_FILE" 2>&1
./mirthsync.sh -t "$BACKUP_DIR" git push >> "$LOG_FILE" 2>&1
echo "[$DATE] Backup completed successfully" >> "$LOG_FILE"

Make the script executable and schedule it:

Terminal window
# Make executable
chmod +x /opt/mirthsync/backup.sh
# Edit crontab
crontab -e
# Add hourly backup (adjust frequency as needed)
0 * * * * /opt/mirthsync/backup.sh

Choose your backup frequency based on your change rate and recovery requirements:

EnvironmentRecommended FrequencyRationale
DevelopmentDailyFrequent changes, less critical
Staging/QAEvery 4 hoursModerate changes, testing workflows
ProductionHourlyCritical systems, minimal data loss
High-volumeEvery 15 minutesFrequent changes, strict RTO/RPO

Use Git tags to mark important backup milestones:

Terminal window
# Tag production releases
git tag -a "prod-v2.1.0" -m "Production release 2.1.0"
git push origin --tags
# Tag before major changes
git tag -a "pre-upgrade-$(date +%Y%m%d)" -m "Before Mirth Connect upgrade"
git push origin --tags

Maintain separate branches for different retention periods:

Terminal window
# Create monthly archive branches
git checkout -b archive/2024-01 main
git push origin archive/2024-01
# Your main branch keeps daily commits
# Archive branches preserve monthly snapshots
Advanced: Automated Cleanup Scripts

Remove old local branches while preserving remote history:

Terminal window
# List merged branches older than 30 days
git branch --merged | grep -v main | xargs -I {} sh -c \
'if [ $(git log -1 --format=%ct {}) -lt $(date -d "30 days ago" +%s) ]; then echo {}; fi'
Terminal window
# Remove stale remote tracking branches
git remote prune origin
# Or automatically prune on fetch
git config --global fetch.prune true

For long-running backup repositories, consider using git-archive to create snapshots:

Terminal window
# Create a ZIP archive of a specific tag
git archive --format=zip --output=backup-2024-01.zip prod-v1.0.0
# Archive and compress
git archive prod-v1.0.0 | gzip > backup-2024-01.tar.gz

If your Mirth Connect server is lost and you need to restore everything:

Terminal window
# 1. Clone your backup repository
git clone https://github.com/your-org/mirth-backup.git
cd mirth-backup
# 2. Download and extract MirthSync (Java JAR, not npm)
# See: https://github.com/SagaHealthcareIT/mirthsync/releases
wget https://github.com/SagaHealthcareIT/mirthsync/releases/download/v3.5.0/mirthsync-3.5.0.zip
unzip mirthsync-3.5.0.zip
# 3. Set environment variables for new server
export MIRTH_URL="https://new-server:8443/api"
export MIRTH_USERNAME="admin"
export MIRTHSYNC_PASSWORD="your-password"
# 4. Push all configurations to new server
./mirthsync-3.5.0/bin/mirthsync.sh push -s $MIRTH_URL -u $MIRTH_USERNAME -t . --deploy-all
# 5. Verify deployment
./mirthsync-3.5.0/bin/mirthsync.sh pull -s $MIRTH_URL -u $MIRTH_USERNAME -t .
git diff # Should show no differences
Terminal window
# Find when the channel was deleted
git log --all --full-history -- "Channels/My Channel/"
# Checkout the channel from before deletion
git checkout <commit-before-deletion> -- "Channels/My Channel/"
# Push to server (will restore the channel)
./mirthsync-3.5.0/bin/mirthsync.sh push -s $MIRTH_URL -u $MIRTH_USERNAME -t . --deploy-all
# Commit the restoration
git add .
git commit -m "Restored accidentally deleted channel"
Terminal window
# See recent changes
git log --oneline -10
# Identify the bad commit
git show <bad-commit>
# Revert that specific change
git revert <bad-commit>
# Push the reverted configuration
./mirthsync-3.5.0/bin/mirthsync.sh push -s $MIRTH_URL -u $MIRTH_USERNAME -t . --deploy-all
Terminal window
# See what changed between two dates
git diff $(git rev-list -1 --before="2024-01-01" main) \
$(git rev-list -1 --before="2024-01-15" main)
# See changes to a specific channel
git log -p --follow -- "Channels/ADT Processor/"

For organizations with multiple Mirth Connect instances:

Multi-site backup with per-environment Git branches
Terminal window
# Production backup
cd mirth-prod-backup
git checkout -b prod
./mirthsync.sh pull -s $PROD_MIRTH_URL -u $PROD_MIRTH_USERNAME -t .
git add . && git commit -m "Initial prod backup"
git push origin prod
# Staging backup
cd mirth-staging-backup
git checkout -b staging
./mirthsync.sh pull -s $STAGING_MIRTH_URL -u $STAGING_MIRTH_USERNAME -t .
git add . && git commit -m "Initial staging backup"
git push origin staging

Create a script to verify backup health:

verify-backup.sh
#!/bin/bash
BACKUP_DIR="/opt/mirthsync/mirth-backup"
ALERT_EMAIL="admin@example.com"
MAX_AGE_HOURS=2
cd "$BACKUP_DIR" || exit 1
# Check last commit age
LAST_COMMIT=$(git log -1 --format=%ct)
NOW=$(date +%s)
AGE_HOURS=$(( (NOW - LAST_COMMIT) / 3600 ))
if [ $AGE_HOURS -gt $MAX_AGE_HOURS ]; then
echo "WARNING: Last backup is $AGE_HOURS hours old" | \
mail -s "MirthSync Backup Alert" "$ALERT_EMAIL"
fi
# Verify remote is reachable
if ! git ls-remote --exit-code origin > /dev/null 2>&1; then
echo "ERROR: Cannot reach remote repository" | \
mail -s "MirthSync Backup Alert - Remote Unreachable" "$ALERT_EMAIL"
fi

For enterprise monitoring (Nagios, Zabbix, Prometheus):

check_mirthsync_backup.sh
#!/bin/bash
# Nagios/monitoring plugin format
BACKUP_DIR="/opt/mirthsync/mirth-backup"
WARNING_HOURS=2
CRITICAL_HOURS=4
cd "$BACKUP_DIR" || { echo "CRITICAL - Backup directory not found"; exit 2; }
LAST_COMMIT=$(git log -1 --format=%ct 2>/dev/null)
if [ -z "$LAST_COMMIT" ]; then
echo "CRITICAL - No commits found"
exit 2
fi
NOW=$(date +%s)
AGE_HOURS=$(( (NOW - LAST_COMMIT) / 3600 ))
if [ $AGE_HOURS -ge $CRITICAL_HOURS ]; then
echo "CRITICAL - Last backup $AGE_HOURS hours ago"
exit 2
elif [ $AGE_HOURS -ge $WARNING_HOURS ]; then
echo "WARNING - Last backup $AGE_HOURS hours ago"
exit 1
else
echo "OK - Last backup $AGE_HOURS hours ago"
exit 0
fi

Never store credentials in backup scripts. Use environment variables or credential managers:

Terminal window
# Set in your shell profile or systemd service
export MIRTH_URL="https://mirth-server:8443/api"
export MIRTH_USER="backup-user"
export MIRTH_PASS="<from-secret-manager>"

Create a dedicated backup user in Mirth Connect with minimal permissions:

  1. Create a new user: mirthsync-backup
  2. Assign only “Read” permissions for channels and settings
  3. Do not grant “Deploy” or “Write” permissions
  1. Clone backup repository to a clean machine
  2. Verify MirthSync can connect to test server
  3. Perform full restoration
  4. Verify all channels are present and configured correctly
  5. Test message processing on restored channels
  6. Document time to recovery (TTR)
  7. Note any issues or improvements needed

Now that you have a backup strategy in place: