e
This commit is contained in:
35
backup.sh
35
backup.sh
@ -276,6 +276,9 @@ main() {
|
|||||||
log "Exporting configuration..."
|
log "Exporting configuration..."
|
||||||
export_config
|
export_config
|
||||||
|
|
||||||
|
# Initialize backup exit code
|
||||||
|
local backup_exit_code=1
|
||||||
|
|
||||||
# Test restic repository access
|
# Test restic repository access
|
||||||
log "Testing repository access..."
|
log "Testing repository access..."
|
||||||
if ! restic -r "${CONFIG[RESTIC_REPOSITORY]}" snapshots 2>&1 | tee -a "$BACKUP_LOG"; then
|
if ! restic -r "${CONFIG[RESTIC_REPOSITORY]}" snapshots 2>&1 | tee -a "$BACKUP_LOG"; then
|
||||||
@ -294,23 +297,37 @@ main() {
|
|||||||
done
|
done
|
||||||
backup_exit_code=1
|
backup_exit_code=1
|
||||||
else
|
else
|
||||||
backup_exit_code=0
|
# Check if backup was actually successful by looking for "snapshot" in the output
|
||||||
log "Backup completed successfully"
|
if grep -q "snapshot" "$BACKUP_LOG"; then
|
||||||
# Add a small delay to ensure the snapshot is registered
|
log "Backup completed successfully"
|
||||||
sleep 2
|
backup_exit_code=0
|
||||||
|
# Add a small delay to ensure the snapshot is registered
|
||||||
|
sleep 2
|
||||||
|
else
|
||||||
|
log "Backup command completed but no snapshot was created. Check the log for details:"
|
||||||
|
tail -n 5 "$BACKUP_LOG" | while read -r line; do
|
||||||
|
log " $line"
|
||||||
|
done
|
||||||
|
backup_exit_code=1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get snapshot information
|
# Get snapshot information
|
||||||
log "Getting snapshot information..."
|
log "Getting snapshot information..."
|
||||||
local snapshot_id
|
local snapshot_id
|
||||||
if ! snapshot_id=$(restic -r "${CONFIG[RESTIC_REPOSITORY]}" snapshots --json 2>/dev/null | jq -r 'sort_by(.time) | reverse | .[0].id // "unknown"'); then
|
if [ $backup_exit_code -eq 0 ]; then
|
||||||
log "Error getting snapshot ID"
|
if ! snapshot_id=$(restic -r "${CONFIG[RESTIC_REPOSITORY]}" snapshots --json 2>/dev/null | jq -r 'sort_by(.time) | reverse | .[0].id // "unknown"'); then
|
||||||
|
log "Error getting snapshot ID"
|
||||||
|
snapshot_id="unknown"
|
||||||
|
fi
|
||||||
|
# Trim the snapshot ID to first 8 characters
|
||||||
|
snapshot_id="${snapshot_id:0:8}"
|
||||||
|
log "Snapshot ID: $snapshot_id"
|
||||||
|
else
|
||||||
snapshot_id="unknown"
|
snapshot_id="unknown"
|
||||||
|
log "Skipping snapshot info due to backup failure"
|
||||||
fi
|
fi
|
||||||
# Trim the snapshot ID to first 8 characters
|
|
||||||
snapshot_id="${snapshot_id:0:8}"
|
|
||||||
log "Snapshot ID: $snapshot_id"
|
|
||||||
|
|
||||||
# Initialize variables
|
# Initialize variables
|
||||||
local status="❌ Failed"
|
local status="❌ Failed"
|
||||||
|
Reference in New Issue
Block a user