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

# === Restic Config ===
export RESTIC_REPOSITORY="/mnt/windows/OneDrive/backup/pi"
export RESTIC_PASSWORD_FILE="/root/.restic-pass"

# === Logging ===
LOGFILE="/var/log/restic-backup.log"

echo "[$(date)] === Restic backup started ===" | tee -a "$LOGFILE"

# === Run backup ===
restic backup \
  /mnt/data/docker/ \
  /mnt/data/nextcloud/ \
  >> "$LOGFILE" 2>&1

# === Retention: Keep only last 2 days ===
restic forget \
  --keep-within 48h \
  --prune \
  >> "$LOGFILE" 2>&1

echo "[$(date)] === Restic backup finished ===" | tee -a "$LOGFILE"
