#!/bin/bash
# Daily config backup with 7-day retention. Run via /etc/cron.d/hermes-config-backup.
set -u
TS=$(date -u +%Y%m%d-%H%M%S)
DST=/root/.config-backups
mkdir -p "$DST"
cp /root/.hermes/config.yaml "$DST/hermes-config.${TS}.yaml" 2>/dev/null
cp /root/.clawdbot-opsman/openclaw.json "$DST/opsman-openclaw.${TS}.json" 2>/dev/null
sha256sum "$DST/hermes-config.${TS}.yaml" "$DST/opsman-openclaw.${TS}.json" > "$DST/manifest.${TS}.sha256" 2>/dev/null
# Prune anything older than 7 days, but only files matching our naming scheme
find "$DST" -maxdepth 1 -type f -mtime +7 \( -name "hermes-config.*.yaml" -o -name "opsman-openclaw.*.json" -o -name "manifest.*.sha256" \) -delete
