#!/usr/bin/env bash
set -euo pipefail

if [ $# -ne 1 ]; then
  echo "Usage: $0 <backup-archive.tar.gz>"
  exit 1
fi

ARCHIVE="$1"
HERE=$(cd "$(dirname "$0")/.." && pwd)

cd "$HERE"

echo "[restore] stopping containers..."
docker compose down

echo "[restore] wiping data/..."
rm -rf data

echo "[restore] extracting $ARCHIVE"
tar -xzf "$ARCHIVE" -C "$HERE"

echo "[restore] starting containers..."
docker compose up -d --build

echo "[restore] done"
