From fb6dbdfbcb6b27a2e97fed7a0c4eb4155e8385ab Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Jan 2026 03:41:04 +0000 Subject: [PATCH] Add Kopia to disaster recovery for ongoing backups - Install Kopia in Step 1 (core utilities) - Add Step 9: Reconnect Kopia repository after restore - Backups now work immediately after disaster recovery - Update README with 9-step recovery process --- README.md | 18 ++++++++++++------ ubuntu-post-install.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b499648..5d551cd 100644 --- a/README.md +++ b/README.md @@ -231,11 +231,15 @@ sudo ./ubuntu-post-install.sh --restore ### What the Recovery Does -1. **Finds your backup drive** - Shows available drives, auto-detects Kopia repo -2. **Installs Docker** - If not already installed -3. **Lists snapshots** - Shows all available backups, lets you choose -4. **Restores services** - Detects which apps were backed up, restores them all -5. **Starts containers** - Optionally starts all services immediately +1. **Installs core utilities** - openssh-server, git, curl, Kopia, etc. +2. **Finds your backup drive** - Shows available drives, auto-detects Kopia repo +3. **Gets Kopia password** - For repository access +4. **Installs Docker** - If not already installed +5. **Lists snapshots** - Shows all available backups, lets you choose +6. **Restores from backup** - Extracts files to temp location +7. **Selects services** - Whiptail checklist to pick which services to restore +8. **Starts containers** - Optionally starts all services immediately +9. **Reconnects Kopia** - Sets up ongoing backups to the same repository ### What Gets Restored @@ -1044,12 +1048,14 @@ This script is provided as-is for Ubuntu 24.04 Desktop installations. ## Changelog -- **v2.9**: Immich photo library, Watchtower, documentation +- **v2.9**: Immich photo library, Watchtower, recovery improvements - **Immich**: Now asks for photo storage location (default: `~/drives/primary/photos`) - **Immich**: External library support for existing photos (read-only, no duplication) - **Immich**: Storage template guidance for yyyy/mm folder organization - Added Watchtower for container update monitoring (notify-only by default) - Documented what Docker data lives where and what gets backed up + - **Recovery**: Now installs Kopia during recovery (Step 1) + - **Recovery**: Reconnects Kopia repository after restore (Step 9) for ongoing backups - **v2.8**: MeshCentral Server and improved recovery - Added MeshCentral Server (self-hosted remote management, web-based RDP/terminal) - Recovery mode now installs core utilities first (openssh-server, git, curl, etc.) diff --git a/ubuntu-post-install.sh b/ubuntu-post-install.sh index 39f3ef1..8b07c8e 100644 --- a/ubuntu-post-install.sh +++ b/ubuntu-post-install.sh @@ -139,6 +139,15 @@ run_disaster_recovery() { whiptail \ 2>/dev/null || echo " ⚠ Some packages may have failed" + # Install Kopia for backup management + echo "Installing Kopia..." + if ! command -v kopia &> /dev/null; then + curl -s https://kopia.io/signing-key | gpg --dearmor -o /usr/share/keyrings/kopia-keyring.gpg 2>/dev/null + echo "deb [signed-by=/usr/share/keyrings/kopia-keyring.gpg] https://packages.kopia.io/apt/ stable main" | tee /etc/apt/sources.list.d/kopia.list + apt-get update + apt-get install -y kopia 2>/dev/null || echo " ⚠ Kopia install failed" + fi + # Start SSH systemctl enable ssh 2>/dev/null || true systemctl start ssh 2>/dev/null || true @@ -449,6 +458,36 @@ run_disaster_recovery() { echo "✓ Cleaned up temp files" fi + # Step 9: Reconnect Kopia for future backups + echo "" + echo "Step 9: Setting up future backups" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo "" + echo "Reconnecting Kopia to backup repository for future backups..." + + if command -v kopia &> /dev/null && [ -n "$KOPIA_REPO" ]; then + # Reconnect to the repository + if kopia repository connect filesystem --path="$KOPIA_REPO" --password="$KOPIA_PASSWORD" 2>/dev/null; then + echo "✓ Kopia reconnected to repository" + echo " Repository: $KOPIA_REPO" + + # Verify backup scripts exist + if [ -f "$DOCKER_DIR/kopia/backup-containers.sh" ]; then + chmod +x "$DOCKER_DIR/kopia/backup-containers.sh" 2>/dev/null || true + echo "✓ Backup script ready: $DOCKER_DIR/kopia/backup-containers.sh" + else + echo " ⚠ Backup script not found - run normal install to set up" + fi + else + echo " ⚠ Could not reconnect to repository" + echo " Run manually: kopia repository connect filesystem --path=\"$KOPIA_REPO\"" + fi + else + echo " ⚠ Kopia not available or repository not found" + echo " Run the normal install script to set up backups" + fi + echo "" + echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "DISASTER RECOVERY COMPLETE" @@ -456,6 +495,9 @@ run_disaster_recovery() { echo "" echo "Services restored to: $DOCKER_DIR" echo "" + echo "Backups: $(command -v kopia &>/dev/null && kopia repository status &>/dev/null && echo "✓ Connected" || echo "⚠ Not connected")" + echo " Run backups: $DOCKER_DIR/kopia/backup-containers.sh" + echo "" echo "To check running containers:" echo " docker ps" echo ""