This commit is contained in:
Lee
2025-05-10 04:20:26 +01:00
parent 56c56736e5
commit 67b4dc4607

View File

@ -276,22 +276,29 @@ main() {
log "Exporting configuration..." log "Exporting configuration..."
export_config export_config
# 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]}" >> "$BACKUP_LOG" 2>&1; 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
backup_exit_code=0 # Run backup
log "Backup completed successfully" log "Running backup..."
# Add a small delay to ensure the snapshot is registered log "Command: restic -r ${CONFIG[RESTIC_REPOSITORY]} backup ${CONFIG[BACKUP_PATH]}"
sleep 2
# 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
else
backup_exit_code=0
log "Backup completed successfully"
# Add a small delay to ensure the snapshot is registered
sleep 2
fi
fi fi
# Get snapshot information # Get snapshot information