7
This commit is contained in:
32
backup.sh
32
backup.sh
@ -436,17 +436,32 @@ 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
|
||||||
|
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
|
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:"
|
log "Prune attempt $((retry_count + 1)) failed with output:"
|
||||||
echo "$prune_output" | while read -r line; do
|
echo "$prune_output" | while read -r line; do
|
||||||
log " $line"
|
log " $line"
|
||||||
done
|
done
|
||||||
status="⚠️ Backup OK, Prune Failed"
|
retry_count=$((retry_count + 1))
|
||||||
color="${DISCORD_COLORS[warning]}"
|
|
||||||
prune_status="Prune operation failed"
|
|
||||||
else
|
else
|
||||||
|
prune_success=true
|
||||||
log "Prune output: $prune_output"
|
log "Prune output: $prune_output"
|
||||||
if echo "$prune_output" | grep -q "no snapshots were removed"; then
|
if echo "$prune_output" | grep -q "no snapshots were removed"; then
|
||||||
log "No snapshots to prune"
|
log "No snapshots to prune"
|
||||||
@ -459,6 +474,13 @@ main() {
|
|||||||
prune_status="Prune completed"
|
prune_status="Prune completed"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$prune_success" = false ]; then
|
||||||
|
status="⚠️ Backup OK, Prune Failed"
|
||||||
|
color="${DISCORD_COLORS[warning]}"
|
||||||
|
prune_status="Prune operation failed after $max_retries attempts"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
log "Pruning disabled"
|
log "Pruning disabled"
|
||||||
prune_status="Pruning disabled"
|
prune_status="Pruning disabled"
|
||||||
|
Reference in New Issue
Block a user