#!/bin/sh
# 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-__NAME__-state-$(date +%Y%m%d-%H%M%S).tar.gz"
ssh "$HOST" 'cd /var/lib/ardegazu-__NAME__ 2>/dev/null || cd /var/lib/private/ardegazu-__NAME__; tar czf - */seed models 2>/dev/null' > "$OUT"
chmod 600 "$OUT"
ls -l "$OUT"