fix(backup-docker): timestamped log, add archive gzip verification, add 30-day rotation

This commit is contained in:
Peter Wood
2026-03-25 21:22:05 -04:00
parent 58d1762815
commit 5f7c0ad866

View File

@@ -26,17 +26,15 @@ BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
BACKUP_TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_ROOT="/home/acedanger/backup/docker-data"
LOG_FILE="$SCRIPT_DIR/logs/docker-backup.log"
LOG_FILE="$SCRIPT_DIR/logs/docker-backup-${BACKUP_TIMESTAMP}.log"
NOTIFICATION_URL="https://notify.peterwood.rocks/lab"
# Container definitions: container_name:volume_path:description
declare -A CONTAINERS=(
["vaultwarden"]="/var/lib/docker/volumes/vaultwarden_data/_data:Password manager data"
["uptime-kuma"]="/var/lib/docker/volumes/uptime-kuma/_data:Uptime monitoring data"
# ["paperless-ng"]="/var/lib/docker/volumes/paperless-ng_data/_data:Document management data"
# ["paperless-media"]="/var/lib/docker/volumes/paperless-ng_media/_data:Document media files"
# ["paperless-pgdata"]="/var/lib/docker/volumes/paperless-ng_pgdata/_data:PostgreSQL database"
)
# Ensure directories exist
@@ -166,9 +164,18 @@ backup_container_volume() {
fi
if tar -czf "$backup_file" -C "$(dirname "$volume_path")" "$(basename "$volume_path")" 2>/dev/null; then
# Verify archive integrity
if ! gzip -t "$backup_file" 2>/dev/null; then
log "Error: Archive verification failed for $(basename "$backup_file")"
rm -f "$backup_file"
if [ "$was_running" = true ]; then
start_container "$container" || true
fi
return 1
fi
local backup_size
backup_size=$(du -h "$backup_file" | cut -f1)
log "Backup completed successfully: $(basename "$backup_file") ($backup_size)"
log "Backup completed and verified: $(basename "$backup_file") ($backup_size)"
# Track file completion in metrics
if [[ "$METRICS_ENABLED" == "true" ]]; then
@@ -322,6 +329,10 @@ main() {
send_notification "failed" "Docker backup completed with errors: $failed_backups failed, $successful_backups succeeded" "${failed_containers[*]}"
fi
# Rotate old archives (keep last 30 days)
log "Cleaning up old backup archives..."
find "$BACKUP_ROOT" -name "*-data-bk-*.tar.gz" -mtime +30 -delete 2>/dev/null || true
# Finalize metrics
if [[ "$METRICS_ENABLED" == "true" ]]; then
cleanup