mirror of
https://github.com/acedanger/shell.git
synced 2026-03-27 06:16:09 -07:00
fix(backup-docker): timestamped log, add archive gzip verification, add 30-day rotation
This commit is contained in:
@@ -26,17 +26,15 @@ BLUE='\033[0;34m'
|
|||||||
NC='\033[0m' # No Color
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
BACKUP_TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||||
BACKUP_ROOT="/home/acedanger/backup/docker-data"
|
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"
|
NOTIFICATION_URL="https://notify.peterwood.rocks/lab"
|
||||||
|
|
||||||
# Container definitions: container_name:volume_path:description
|
# Container definitions: container_name:volume_path:description
|
||||||
declare -A CONTAINERS=(
|
declare -A CONTAINERS=(
|
||||||
["vaultwarden"]="/var/lib/docker/volumes/vaultwarden_data/_data:Password manager data"
|
["vaultwarden"]="/var/lib/docker/volumes/vaultwarden_data/_data:Password manager data"
|
||||||
["uptime-kuma"]="/var/lib/docker/volumes/uptime-kuma/_data:Uptime monitoring 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
|
# Ensure directories exist
|
||||||
@@ -166,9 +164,18 @@ backup_container_volume() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if tar -czf "$backup_file" -C "$(dirname "$volume_path")" "$(basename "$volume_path")" 2>/dev/null; then
|
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
|
local backup_size
|
||||||
backup_size=$(du -h "$backup_file" | cut -f1)
|
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
|
# Track file completion in metrics
|
||||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
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[*]}"
|
send_notification "failed" "Docker backup completed with errors: $failed_backups failed, $successful_backups succeeded" "${failed_containers[*]}"
|
||||||
fi
|
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
|
# Finalize metrics
|
||||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||||
cleanup
|
cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user