7
This commit is contained in:
60
backup.sh
60
backup.sh
@ -436,28 +436,50 @@ main() {
|
||||
if [ "${CONFIG[ENABLE_PRUNE]}" = "true" ]; then
|
||||
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
|
||||
if ! prune_output=$(restic -r "${CONFIG[RESTIC_REPOSITORY]}" forget --keep-last "${CONFIG[KEEP_LAST]}" --group-by "" --prune 2>&1); then
|
||||
log "Prune operation failed with output:"
|
||||
echo "$prune_output" | while read -r line; do
|
||||
log " $line"
|
||||
done
|
||||
local max_retries=3
|
||||
local retry_count=0
|
||||
local prune_success=false
|
||||
|
||||
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"
|
||||
color="${DISCORD_COLORS[warning]}"
|
||||
prune_status="Prune operation failed"
|
||||
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
|
||||
prune_status="Prune operation failed after $max_retries attempts"
|
||||
fi
|
||||
else
|
||||
log "Pruning disabled"
|
||||
|
Reference in New Issue
Block a user