#!/bin/sh
# SUPERSEDED by deploy/backup-fleet.sh, which also captures kv.json, rooms/,
# the per-bot configs, the unit files and the code pins — i.e. enough to rebuild
# the fleet on another host. This one remains because it is the smallest
# possible "just the irreplaceable bits" grab: seeds + model checkpoints only.
#
# Pull the fleet's precious state — the bots' identity seeds and the model
# checkpoints — from the server to a local tarball. Run it from your machine:
#
# sh deploy/backup-state.sh <ssh-host> [out-dir]
#
# Seeds are secrets: the tarball lands mode 0600, keep it out of any repo.
set -eu
HOST="${1:?usage: backup-state.sh <ssh-host> [out-dir]}"
OUT="${2:-.}/ardegazu-bot-state-$(date +%Y%m%d-%H%M%S).tar.gz"
ssh "$HOST" 'cd /var/lib/ardegazu-bot 2>/dev/null || cd /var/lib/private/ardegazu-bot; tar czf - */seed models 2>/dev/null' > "$OUT"
chmod 600 "$OUT"
ls -l "$OUT"