From b89b29daa8cc9190f5fc3aa262e04e7b9bf38c09 Mon Sep 17 00:00:00 2001 From: fascinated Date: Sat, 10 May 2025 04:25:37 +0100 Subject: [PATCH] 7 --- backup.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backup.sh b/backup.sh index 8bdcdcb..590f120 100755 --- a/backup.sh +++ b/backup.sh @@ -291,9 +291,19 @@ main() { # Test restic repository access log "Testing repository access..." 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." - backup_exit_code=1 + log "Repository not initialized. Attempting to initialize..." + if ! restic -r "${CONFIG[RESTIC_REPOSITORY]}" init 2>&1 | tee -a "$BACKUP_LOG"; then + log "Error: Failed to initialize repository. Please check your credentials and repository URL." + backup_exit_code=1 + else + log "Repository initialized successfully" + backup_exit_code=0 + fi else + backup_exit_code=0 + fi + + if [ $backup_exit_code -eq 0 ]; then # Run backup log "Running backup..." log "Command: restic -r ${CONFIG[RESTIC_REPOSITORY]} backup ${CONFIG[BACKUP_PATH]}"