This commit is contained in:
Lee
2025-05-10 04:21:59 +01:00
parent c37e21e403
commit 95ff9142b5

View File

@ -279,36 +279,46 @@ main() {
# Initialize backup exit code # Initialize backup exit code
local backup_exit_code=1 local backup_exit_code=1
# Test restic repository access # Check backup path
log "Testing repository access..." log "Checking backup path..."
if ! restic -r "${CONFIG[RESTIC_REPOSITORY]}" snapshots 2>&1 | tee -a "$BACKUP_LOG"; then if [ ! -d "${CONFIG[BACKUP_PATH]}" ]; then
log "Error: Cannot access repository. Please check your credentials and repository URL." log "Error: Backup path does not exist: ${CONFIG[BACKUP_PATH]}"
backup_exit_code=1
elif [ ! -r "${CONFIG[BACKUP_PATH]}" ]; then
log "Error: No read permission for backup path: ${CONFIG[BACKUP_PATH]}"
backup_exit_code=1 backup_exit_code=1
else else
# Run backup # Test restic repository access
log "Running backup..." log "Testing repository access..."
log "Command: restic -r ${CONFIG[RESTIC_REPOSITORY]} backup ${CONFIG[BACKUP_PATH]}" if ! restic -r "${CONFIG[RESTIC_REPOSITORY]}" snapshots 2>&1 | tee -a "$BACKUP_LOG"; then
log "Error: Cannot access repository. Please check your credentials and repository URL."
# Run the backup command and capture both stdout and stderr
if ! restic -r "${CONFIG[RESTIC_REPOSITORY]}" backup "${CONFIG[BACKUP_PATH]}" 2>&1 | tee -a "$BACKUP_LOG"; then
log "Backup failed. Last few lines of the log:"
tail -n 5 "$BACKUP_LOG" | while read -r line; do
log " $line"
done
backup_exit_code=1 backup_exit_code=1
else else
# Check if backup was actually successful by looking for "snapshot" in the output # Run backup
if grep -q "snapshot" "$BACKUP_LOG"; then log "Running backup..."
log "Backup completed successfully" log "Command: restic -r ${CONFIG[RESTIC_REPOSITORY]} backup ${CONFIG[BACKUP_PATH]}"
backup_exit_code=0
# Add a small delay to ensure the snapshot is registered # Run the backup command and capture both stdout and stderr
sleep 2 if ! restic -r "${CONFIG[RESTIC_REPOSITORY]}" backup "${CONFIG[BACKUP_PATH]}" 2>&1 | tee -a "$BACKUP_LOG"; then
else log "Backup failed. Last few lines of the log:"
log "Backup command completed but no snapshot was created. Check the log for details:"
tail -n 5 "$BACKUP_LOG" | while read -r line; do tail -n 5 "$BACKUP_LOG" | while read -r line; do
log " $line" log " $line"
done done
backup_exit_code=1 backup_exit_code=1
else
# Check if backup was actually successful by looking for "snapshot" in the output
if grep -q "snapshot" "$BACKUP_LOG"; then
log "Backup completed successfully"
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. Full log:"
cat "$BACKUP_LOG" | while read -r line; do
log " $line"
done
backup_exit_code=1
fi
fi fi
fi fi
fi fi