58 lines
1.4 KiB
Bash
Executable File
58 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ENV_FILE="${SCRIPT_DIR}/restic-backup.env"
|
|
HOMELAB_ROOT="/srv/homelab"
|
|
STACKS_STOPPED=false
|
|
|
|
start_stacks() {
|
|
if [[ "$STACKS_STOPPED" != true ]]; then
|
|
return 0
|
|
fi
|
|
echo "Starting Docker stacks..."
|
|
cd "$HOMELAB_ROOT"
|
|
docker compose -f stacks/media/compose.yaml up -d
|
|
docker compose -f stacks/monitoring/compose.yaml up -d
|
|
docker compose -f stacks/storage/compose.yaml up -d
|
|
echo "Stacks started."
|
|
}
|
|
trap start_stacks EXIT
|
|
|
|
if [[ -f "$ENV_FILE" ]]; then
|
|
set -a
|
|
# shellcheck source=/dev/null
|
|
source "$ENV_FILE"
|
|
set +a
|
|
fi
|
|
|
|
if [[ -z "${RESTIC_REPOSITORY:-}" ]]; then
|
|
echo "Error: RESTIC_REPOSITORY is not set. Create ${ENV_FILE} or export it." >&2
|
|
echo "Example: RESTIC_REPOSITORY=sftp:user@host:/backups/restic" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -z "${RESTIC_PASSWORD:-}" ]]; then
|
|
echo "Error: RESTIC_PASSWORD is not set. Create ${ENV_FILE} or export it." >&2
|
|
exit 1
|
|
fi
|
|
|
|
CADDYFILE="/etc/caddy/Caddyfile"
|
|
UNBOUND_CONF="/etc/unbound/unbound.conf"
|
|
|
|
echo "Stopping Docker stacks..."
|
|
cd "$HOMELAB_ROOT"
|
|
docker compose -f stacks/media/compose.yaml down
|
|
docker compose -f stacks/monitoring/compose.yaml down
|
|
docker compose -f stacks/storage/compose.yaml down
|
|
STACKS_STOPPED=true
|
|
|
|
echo "Starting restic backup..."
|
|
restic backup \
|
|
"$HOMELAB_ROOT" \
|
|
"$CADDYFILE" \
|
|
"$UNBOUND_CONF"
|
|
|
|
echo "Backup finished. Snapshot list:"
|
|
restic snapshots --latest 5
|