#!/bin/bash # Script to initialize Restic repository for quantumrick backups set -e # Configuration should be sourced before running: source backup.env REPO_PATH="$BACKUP_REPOSITORY" CONFIG_FILE="$RESTIC_CONFIG_FILE" echo "=== Initializing Restic Repository ===" # Check if repository directory exists if [ ! -d "$(dirname "$REPO_PATH")" ]; then echo "Creating backup directory..." sudo mkdir -p "$(dirname "$REPO_PATH")" sudo chown $(whoami):$(whoami) "$(dirname "$REPO_PATH")" fi # Check if config file exists if [ ! -f "$CONFIG_FILE" ]; then echo "Error: Configuration file $CONFIG_FILE not found!" echo "Please run generate-restic-config.sh first to create the configuration." exit 1 fi # Source the configuration source "$CONFIG_FILE" # Check if repository is already initialized if restic -r "$REPO_PATH" cat config &>/dev/null; then echo "Repository already initialized at $REPO_PATH" exit 0 fi echo "Initializing new Restic repository at $REPO_PATH" # Initialize the repository restic init -r "$REPO_PATH" if [ $? -eq 0 ]; then echo "✅ Repository successfully initialized!" echo "Repository path: $REPO_PATH" echo "Configuration: $CONFIG_FILE" else echo "❌ Failed to initialize repository" exit 1 fi echo "=== Repository Information ===" restic -r "$REPO_PATH" stats