#!/usr/bin/env bash
# Daily backup of Claude Code session transcripts to the external backup drive.
# Fail-closed: refuses to run unless the drive is a real mountpoint and writable.
# Never deletes on the destination (no --delete): local cleanup can never propagate.
set -euo pipefail

SRC="$HOME/.claude/projects/"
DRIVE="/run/media/user/edad72d3-fa43-4363-af5d-cd2598090e321"
DEST="$DRIVE/user/claude-transcripts/projects/"

if ! mountpoint -q "$DRIVE"; then
  echo "SKIP: backup drive not mounted at $DRIVE — nothing copied" >&2
  exit 1
fi
if [[ ! -w "$DRIVE/user" ]]; then
  echo "FAIL: $DRIVE/user not writable" >&2
  exit 1
fi

mkdir -p "$DEST"
rsync -a --no-specials --no-devices "$SRC" "$DEST"
echo "OK: $(date -Is) rsynced $SRC -> $DEST ($(du -sh "$DEST" | cut -f1))"
