Backup & Disaster Recovery
Backup & Disaster Recovery
Section titled “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.
Why Git-Based Backups?
Section titled “Why Git-Based Backups?”Traditional database backups capture a single point in time. MirthSync’s Git-based approach provides superior disaster recovery capabilities:
| Feature | Database Backup | MirthSync Git Backup |
|---|---|---|
| Point-in-time recovery | Single snapshot | Any commit in history |
| Change tracking | No history | Full audit trail |
| Selective restore | All or nothing | Individual channels |
| Offsite redundancy | Requires separate setup | Built-in with Git remotes |
| Team collaboration | Not designed for it | Branch and merge |
Backup Workflow Overview
Section titled “Backup Workflow Overview”Setting Up Automated Backups
Section titled “Setting Up Automated Backups”Cron-Based Automated Backup
Section titled “Cron-Based Automated Backup”Create a backup script that runs automatically:
#!/bin/bash
# ConfigurationBACKUP_DIR="/opt/mirthsync/mirth-backup"LOG_FILE="/var/log/mirthsync-backup.log"DATE=$(date '+%Y-%m-%d %H:%M:%S')
# Navigate to backup directorycd "$BACKUP_DIR" || exit 1
# Pull latest configurationecho "[$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 changesif git diff --quiet && git diff --cached --quiet; then echo "[$DATE] No changes detected" >> "$LOG_FILE" exit 0fi
# 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:
# Make executablechmod +x /opt/mirthsync/backup.sh
# Edit crontabcrontab -e
# Add hourly backup (adjust frequency as needed)0 * * * * /opt/mirthsync/backup.shTask Scheduler Automated Backup
Section titled “Task Scheduler Automated Backup”Create a PowerShell backup script:
# Configuration$BackupDir = "C:\MirthSync\mirth-backup"$MirthSyncDir = "C:\MirthSync\mirthsync-3.5.0\bin"$MirthUrl = "https://mirth-server:8443/api"$MirthUser = "admin"$LogFile = "C:\MirthSync\logs\backup.log"$Date = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
# Password should be set via environment variable: $env:MIRTHSYNC_PASSWORD
# Navigate to MirthSync directorySet-Location $MirthSyncDir
# Pull latest configurationAdd-Content $LogFile "[$Date] Starting backup...".\mirthsync.sh pull -s $MirthUrl -u $MirthUser -t $BackupDir 2>&1 | Add-Content $LogFile
# Check for changes using git status$status = git -C $BackupDir status --porcelainif (-not $status) { Add-Content $LogFile "[$Date] No changes detected" exit 0}
# Commit and push changes.\mirthsync.sh -t $BackupDir git add 2>&1 | Add-Content $LogFile.\mirthsync.sh -t $BackupDir --commit-message "Automated-backup-$Date" git commit 2>&1 | Add-Content $LogFile.\mirthsync.sh -t $BackupDir git push 2>&1 | Add-Content $LogFile
Add-Content $LogFile "[$Date] Backup completed successfully"Schedule with Task Scheduler:
- Open Task Scheduler
- Create Basic Task → Name: “MirthSync Backup”
- Trigger: Daily, repeat every 1 hour
- Action: Start a program
- Program:
powershell.exe - Arguments:
-ExecutionPolicy Bypass -File "C:\MirthSync\backup.ps1"
- Program:
Container-Based Backup
Section titled “Container-Based Backup”For Docker deployments, create a backup container:
version: '3.8'services: mirthsync-backup: image: eclipse-temurin:17-jdk-alpine volumes: - ./mirth-backup:/backup - ./mirthsync-3.5.0:/opt/mirthsync:ro - ./backup.sh:/backup.sh:ro environment: - MIRTH_URL=https://mirth-server:8443/api - MIRTH_USER=admin - MIRTHSYNC_PASSWORD=${MIRTH_PASSWORD} command: > sh -c "apk add --no-cache git bash && crond -f -d 8" restart: unless-stopped#!/bin/bashMIRTHSYNC="/opt/mirthsync/bin/mirthsync.sh"BACKUP_DIR="/backup"DATE=$(date +%Y-%m-%d_%H-%M-%S)
cd "$BACKUP_DIR"$MIRTHSYNC pull -s "$MIRTH_URL" -u "$MIRTH_USER" -t "$BACKUP_DIR"if ! git diff --quiet; then $MIRTHSYNC -t "$BACKUP_DIR" git add $MIRTHSYNC -t "$BACKUP_DIR" --commit-message "Automated-backup-$DATE" git commit $MIRTHSYNC -t "$BACKUP_DIR" git pushfiBackup Frequency Recommendations
Section titled “Backup Frequency Recommendations”Choose your backup frequency based on your change rate and recovery requirements:
| Environment | Recommended Frequency | Rationale |
|---|---|---|
| Development | Daily | Frequent changes, less critical |
| Staging/QA | Every 4 hours | Moderate changes, testing workflows |
| Production | Hourly | Critical systems, minimal data loss |
| High-volume | Every 15 minutes | Frequent changes, strict RTO/RPO |
Retention Policies
Section titled “Retention Policies”Git Tag-Based Retention
Section titled “Git Tag-Based Retention”Use Git tags to mark important backup milestones:
# Tag production releasesgit tag -a "prod-v2.1.0" -m "Production release 2.1.0"git push origin --tags
# Tag before major changesgit tag -a "pre-upgrade-$(date +%Y%m%d)" -m "Before Mirth Connect upgrade"git push origin --tagsBranch-Based Retention
Section titled “Branch-Based Retention”Maintain separate branches for different retention periods:
# Create monthly archive branchesgit checkout -b archive/2024-01 maingit push origin archive/2024-01
# Your main branch keeps daily commits# Archive branches preserve monthly snapshotsAdvanced: Automated Cleanup Scripts
Automated Cleanup
Section titled “Automated Cleanup”Remove old local branches while preserving remote history:
# List merged branches older than 30 daysgit 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'Prune Remote Tracking Branches
Section titled “Prune Remote Tracking Branches”# Remove stale remote tracking branchesgit remote prune origin
# Or automatically prune on fetchgit config --global fetch.prune trueArchive Old Commits
Section titled “Archive Old Commits”For long-running backup repositories, consider using git-archive to create snapshots:
# Create a ZIP archive of a specific taggit archive --format=zip --output=backup-2024-01.zip prod-v1.0.0
# Archive and compressgit archive prod-v1.0.0 | gzip > backup-2024-01.tar.gzDisaster Recovery Procedures
Section titled “Disaster Recovery Procedures”Complete Server Recovery
Section titled “Complete Server Recovery”If your Mirth Connect server is lost and you need to restore everything:
# 1. Clone your backup repositorygit clone https://github.com/your-org/mirth-backup.gitcd mirth-backup
# 2. Download and extract MirthSync (Java JAR, not npm)# See: https://github.com/SagaHealthcareIT/mirthsync/releaseswget https://github.com/SagaHealthcareIT/mirthsync/releases/download/v3.5.0/mirthsync-3.5.0.zipunzip mirthsync-3.5.0.zip
# 3. Set environment variables for new serverexport 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 differencesRestore only specific channels or components:
# 1. Clone and checkout the desired point in timegit clone https://github.com/your-org/mirth-backup.gitcd mirth-backupgit checkout <commit-hash> # or tag name
# 2. Push configurations to server./mirthsync-3.5.0/bin/mirthsync.sh push -s $MIRTH_URL -u $MIRTH_USERNAME -t . --deploy-all
# Note: To restore specific channels, copy only those channel# directories before pushing, or manually import via Admin ConsoleRestore to a specific point in history:
# 1. Find the commit you want to restoregit log --oneline --all | head -20
# 2. View what was different at that timegit show <commit-hash>
# 3. Checkout that specific pointgit checkout <commit-hash>
# 4. Push to server./mirthsync-3.5.0/bin/mirthsync.sh push -s $MIRTH_URL -u $MIRTH_USERNAME -t . --deploy-all
# 5. Return to current stategit checkout mainPartial Recovery Scenarios
Section titled “Partial Recovery Scenarios”Recover a Deleted Channel
Section titled “Recover a Deleted Channel”# Find when the channel was deletedgit log --all --full-history -- "Channels/My Channel/"
# Checkout the channel from before deletiongit 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 restorationgit add .git commit -m "Restored accidentally deleted channel"Recover from Bad Configuration Change
Section titled “Recover from Bad Configuration Change”# See recent changesgit log --oneline -10
# Identify the bad commitgit show <bad-commit>
# Revert that specific changegit revert <bad-commit>
# Push the reverted configuration./mirthsync-3.5.0/bin/mirthsync.sh push -s $MIRTH_URL -u $MIRTH_USERNAME -t . --deploy-allCompare Two Points in Time
Section titled “Compare Two Points in Time”# See what changed between two datesgit diff $(git rev-list -1 --before="2024-01-01" main) \ $(git rev-list -1 --before="2024-01-15" main)
# See changes to a specific channelgit log -p --follow -- "Channels/ADT Processor/"Multi-Site Backup Strategy
Section titled “Multi-Site Backup Strategy”For organizations with multiple Mirth Connect instances:
Branch-Per-Environment Setup
Section titled “Branch-Per-Environment Setup”# Production backupcd mirth-prod-backupgit 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 backupcd mirth-staging-backupgit 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 stagingMonitoring and Alerts
Section titled “Monitoring and Alerts”Backup Verification Script
Section titled “Backup Verification Script”Create a script to verify backup health:
#!/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 ageLAST_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 reachableif ! 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"fiIntegration with Monitoring Systems
Section titled “Integration with Monitoring Systems”For enterprise monitoring (Nagios, Zabbix, Prometheus):
#!/bin/bash# Nagios/monitoring plugin format
BACKUP_DIR="/opt/mirthsync/mirth-backup"WARNING_HOURS=2CRITICAL_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 2fi
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 2elif [ $AGE_HOURS -ge $WARNING_HOURS ]; then echo "WARNING - Last backup $AGE_HOURS hours ago" exit 1else echo "OK - Last backup $AGE_HOURS hours ago" exit 0fiSecurity Best Practices
Section titled “Security Best Practices”Secure Credential Storage
Section titled “Secure Credential Storage”Never store credentials in backup scripts. Use environment variables or credential managers:
# Set in your shell profile or systemd serviceexport MIRTH_URL="https://mirth-server:8443/api"export MIRTH_USER="backup-user"export MIRTH_PASS="<from-secret-manager>"# Retrieve credentials from Vaultexport MIRTHSYNC_PASSWORD=$(vault kv get -field=password secret/mirthsync)./mirthsync.sh pull -s $MIRTH_URL -u $MIRTH_USER -t .Access Control
Section titled “Access Control”Create a dedicated backup user in Mirth Connect with minimal permissions:
- Create a new user:
mirthsync-backup - Assign only “Read” permissions for channels and settings
- Do not grant “Deploy” or “Write” permissions
Testing Your Recovery Plan
Section titled “Testing Your Recovery Plan”Recovery Drill Checklist
Section titled “Recovery Drill Checklist”- Clone backup repository to a clean machine
- Verify MirthSync can connect to test server
- Perform full restoration
- Verify all channels are present and configured correctly
- Test message processing on restored channels
- Document time to recovery (TTR)
- Note any issues or improvements needed
Next Steps
Section titled “Next Steps”Now that you have a backup strategy in place:
- CI/CD Setup - Automate testing and deployment
- Multi-Environment Management - Manage dev, staging, and production
- Best Practices - Optimize your MirthSync workflow