A Docker container for automated backups with rclone synchronization.
$WAKEUPTIME)/config/bns/backup_vols.txt (one per line)MAXBKP) is applied directly on the rclone target, not locallyImportant change from v1.x: This version uses a copy-based architecture instead of sync-based:
/backups (temporary)rclone copyMAXBKPBenefits: Local storage only needs space for one backup at a time, while the rclone target stores all retained backups.
After each backup, the following integrity checks are performed:
rclone lsl. This works with all cloud storage providers and avoids the read-only filesystem issues that rclone check can have.tar -tzf to verify it can be read and decompressed without actually extracting data (lightweight, fast, minimal storage overhead).If any verification step fails, it is logged as an error, but the backup cycle continues for other volumes.
Configure rclone outside of this container and mount its configuration file.
| Variable | Required | Default | Description |
|---|---|---|---|
HOSTID | Optional | hostname | Identifier for this host (used in backup paths) |
WAKEUPTIME | Optional | - | Daily backup time in HH:MM format (e.g., "09:20"). If not set, runs once and exits |
SKIPFIRSTRUN | Optional | false | Skip first run if current time is past WAKEUPTIME |
SRC_VOL_BASE | Optional | /data | Base directory containing volumes to backup |
BKP_BASE_DIR | Optional | /backups | Temporary local directory for backups (only used during upload) |
MAXBKP | Optional | 7 | Maximum number of backups to retain on rclone target |
PRESCRIPT | Optional | /config/bns/backup_pre_script.sh | Path to global pre-backup script |
POSTSCRIPT | Optional | /config/bns/backup_post_script.sh | Path to global post-backup script |
RCL_TARGET | Required | - | Rclone remote name |
RCL_PREFIX | Required | - | Prefix path on rclone target |
RCL_SUFFIX | Optional | dockervolumes | Suffix path on rclone target |
LOG_LEVEL | Optional | INFO | Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
ENABLE_HEALTH_SERVER | Optional | true | Enable health check HTTP server |
HEALTH_PORT | Optional | 8080 | Port for health check server |
Final backup path: $RCL_TARGET:$RCL_PREFIX/$HOSTID/$RCL_SUFFIX/{volume_name}/
The container exposes HTTP endpoints for health monitoring and metrics collection:
/health - Basic health check (returns 200 if healthy, 503 if unhealthy)/ready - Readiness check for Kubernetes/orchestration (returns 200 when ready)/metrics - Prometheus-compatible metrics endpointbackup_total_count - Total number of backup cycles completedbackup_failure_count - Total number of backup failuresbackup_volumes_success - Number of volumes successfully backed up in last cyclebackup_volumes_failed - Number of volumes that failed in last cyclebackup_last_duration_seconds - Duration of last backup cycle in secondsbackup_last_success_timestamp - Unix timestamp of last successful backupbackup_uptime_seconds - Service uptime in secondsversion: '3.8'
services:
bkpnsync:
image: acaranta/backup_n_sync:latest
ports:
- "8080:8080" # Health check port
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# ... rest of configuration
version: '3.8'
services:
bkpnsync:
image: acaranta/backup_n_sync:latest
volumes:
# Configuration files (read-only)
- /srv/backupsconf/bns:/config/bns/:ro
# Rclone configuration must not be readonly
- /srv/backupsconf/rclone/config/rclone:/config/rclone
# Temporary backup directory (only needs space for 1 backup)
- /srv/backups:/backups
# Persistent cache for metrics state (survives container restarts)
- /srv/cache:/var/cache/bkpnsync
# Source data to backup (read-only recommended)
- /srv/dockervolumes:/data:ro
environment:
- SKIPFIRSTRUN=false
- WAKEUPTIME=09:20
- HOSTID=my-server
- SRC_VOL_BASE=/data
- BKP_BASE_DIR=/backups
- MAXBKP=7
- RCL_TARGET=MyCloudStorage
- RCL_PREFIX=Backups
- RCL_SUFFIX=dockervolumes
restart: unless-stopped
docker run -d \
--name backups-n-sync \
--restart unless-stopped \
-p 8080:8080 \
-v /srv/backupsconf/bns:/config/bns:ro \
-v /srv/backupsconf/rclone/config/rclone:/config/rclone \
-v /srv/backups:/backups \
-v /srv/cache:/var/cache/bkpnsync \
-v /srv/dockervolumes:/data:ro \
-e SKIPFIRSTRUN=false \
-e WAKEUPTIME=09:20 \
-e HOSTID=my-server \
-e SRC_VOL_BASE=/data \
-e BKP_BASE_DIR=/backups \
-e MAXBKP=7 \
-e RCL_TARGET=MyCloudStorage \
-e RCL_PREFIX=Backups \
-e RCL_SUFFIX=dockervolumes \
-e LOG_LEVEL=INFO \
-e ENABLE_HEALTH_SERVER=true \
-e HEALTH_PORT=8080 \
acaranta/backup_n_sync:latest
/config/bns/backup_vols.txtList of volume names to backup (one per line). Lines starting with # are ignored.
volume1
volume2
# volume3 - commented out
volume4
/config/bns/backup_pre_script.shBash script executed once before the entire backup cycle starts. Useful for global setup tasks.
#!/bin/bash
# Example: global notification
echo "Starting backup cycle" | mail -s "Backup Started" [email protected]
/config/bns/backup_post_script.shBash script executed once after the entire backup cycle completes. Useful for cleanup or notifications.
#!/bin/bash
# Example: global cleanup or notification
echo "Backup cycle completed" | mail -s "Backup Complete" [email protected]
Behavior:
Each volume can have its own pre/post scripts located within the volume's directory:
<volume_path>/.bkpnsync/prescript.shBash script executed before backing up this specific volume. Useful for database dumps or volume-specific preparation.
#!/bin/bash
# Example: dump PostgreSQL database for this volume
docker exec my-postgres-container pg_dump -U user mydb > /data/myvolume/dump.sql
<volume_path>/.bkpnsync/postscript.shBash script executed after successfully backing up this specific volume. Useful for cleanup tasks.
#!/bin/bash
# Example: remove temporary dump file
rm -f /data/myvolume/dump.sql
Behavior:
.bkpnsync directory is included in the backup archiveExample structure:
/data/
├── volume1/
│ ├── .bkpnsync/
│ │ ├── prescript.sh
│ │ └── postscript.sh
│ └── ... (volume data)
└── volume2/
└── ... (volume data, no scripts)
Content type
Image
Digest
sha256:9213aef5b…
Size
128.5 MB
Last updated
about 15 hours ago
docker pull acaranta/backup_n_sync