This commit is contained in:
Lee
2025-05-10 04:31:14 +01:00
parent 7de24f1aa9
commit e04bdea498

View File

@ -436,28 +436,50 @@ main() {
if [ "${CONFIG[ENABLE_PRUNE]}" = "true" ]; then if [ "${CONFIG[ENABLE_PRUNE]}" = "true" ]; then
log "Applying retention policy (keeping last ${CONFIG[KEEP_LAST]} backups globally)..." log "Applying retention policy (keeping last ${CONFIG[KEEP_LAST]} backups globally)..."
# Run the prune # First try to unlock the repository if it's locked
log "Checking for stale locks..."
if ! restic -r "${CONFIG[RESTIC_REPOSITORY]}" unlock 2>&1 | tee -a "$BACKUP_LOG"; then
log "Warning: Failed to unlock repository, but continuing with prune attempt"
fi
# Run the prune with retries
local prune_output local prune_output
if ! prune_output=$(restic -r "${CONFIG[RESTIC_REPOSITORY]}" forget --keep-last "${CONFIG[KEEP_LAST]}" --group-by "" --prune 2>&1); then local max_retries=3
log "Prune operation failed with output:" local retry_count=0
echo "$prune_output" | while read -r line; do local prune_success=false
log " $line"
done while [ $retry_count -lt $max_retries ] && [ "$prune_success" = false ]; do
if [ $retry_count -gt 0 ]; then
log "Retry $retry_count of $max_retries..."
sleep 5 # Wait 5 seconds between retries
fi
if ! prune_output=$(restic -r "${CONFIG[RESTIC_REPOSITORY]}" forget --keep-last "${CONFIG[KEEP_LAST]}" --group-by "" --prune 2>&1); then
log "Prune attempt $((retry_count + 1)) failed with output:"
echo "$prune_output" | while read -r line; do
log " $line"
done
retry_count=$((retry_count + 1))
else
prune_success=true
log "Prune output: $prune_output"
if echo "$prune_output" | grep -q "no snapshots were removed"; then
log "No snapshots to prune"
prune_status="No snapshots to prune"
elif echo "$prune_output" | grep -q "removed"; then
log "Successfully pruned old backups"
prune_status="Successfully pruned old backups"
else
log "Prune completed but no clear status found in output"
prune_status="Prune completed"
fi
fi
done
if [ "$prune_success" = false ]; then
status="⚠️ Backup OK, Prune Failed" status="⚠️ Backup OK, Prune Failed"
color="${DISCORD_COLORS[warning]}" color="${DISCORD_COLORS[warning]}"
prune_status="Prune operation failed" prune_status="Prune operation failed after $max_retries attempts"
else
log "Prune output: $prune_output"
if echo "$prune_output" | grep -q "no snapshots were removed"; then
log "No snapshots to prune"
prune_status="No snapshots to prune"
elif echo "$prune_output" | grep -q "removed"; then
log "Successfully pruned old backups"
prune_status="Successfully pruned old backups"
else
log "Prune completed but no clear status found in output"
prune_status="Prune completed"
fi
fi fi
else else
log "Pruning disabled" log "Pruning disabled"