Single Instance Backup#
This section provides a comprehensive guide for single instance backup for Docker Compose MSR installation.
Prerequisites#
Stop Write Operations (Optional but Recommended)
Before backing up, set Harbor/MSR 4 to read-only mode to prevent data inconsistencies.
Enable Read-Only Mode in Harbor:
- Log in as an administrator.
- Go to Administration → Configuration.
- Under System Settings, enable Repository Read-Only mode.
- Click Save.
Backup Components#
A complete backup includes:
- Registry Storage (Images and Artifacts)
- Harbor Databases (PostgreSQL and Redis)
- Configuration Files
Backup Registry Storage (Default: /data)#
If using filesystem storage, copy the image storage directory:
tar -czvf harbor-registry-backup.tar.gz /data
If using an S3-compatible backend, ensure retention policies exist on the object storage.
Backup Databases (PostgreSQL and Redis)#
MSR 4 uses PostgreSQL and Redis. Backup them separately.
Backup PostgreSQL:
docker exec -t harbor-db pg_dumpall -U harbor > harbor-db-backup.sql
Backup Redis (if needed - used for caching/session storage):
docker exec -t harbor-redis redis-cli save
cp /var/lib/redis/dump.rdb harbor-redis-backup.rdb
Backup Configuration Files
Back up the configuration and TLS certs from the install
directory (typically /etc/harbor/):
tar -czvf harbor-config-backup.tar.gz /etc/harbor/
Restore Process#
If disaster recovery is needed, follow these steps:
-
Stop Running Containers:
docker compose down -
Restore Registry Storage:
tar -xzvf harbor-registry-backup.tar.gz -C / -
Restore PostgreSQL Database:
cat harbor-db-backup.sql | docker exec -i harbor-db psql -U postgres -d registryUse
-d registryto restore into the correct database. -
Restore Redis (if needed):
cp harbor-redis-backup.rdb /var/lib/redis/dump.rdb -
Restore Configuration Files:
tar -xzvf harbor-config-backup.tar.gz -C / -
Restart Harbor:
docker compose up -d -
Automate and Schedule Backups
For regular automated backups, use cron jobs.
-
Edit the crontab
crontab -e -
Add a scheduled task to run nightly at 2 AM:
0 2 * * * /bin/bash -c "tar -czvf /backup/harbor-registry-$(date +\%F).tar.gz /data && docker exec -t harbor-db pg_dumpall -U harbor > /backup/harbor-db-$(date +\%F).sql"
How Long Will This Take?#
| Component | Estimated Time |
|---|---|
Configuration Files (/etc/harbor/) |
<1 minute |
| PostgreSQL DB Backup | 1-5 minutes (depends on size) |
| Redis Backup | <1 minute |
Registry Storage (/data/) |
Varies (Minutes to Hours for TBs) |