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

out_dir=${1:-/var/backups/guanghu/jd-control-plane}
stamp=$(date -u +%Y%m%dT%H%M%SZ)
install -d -m 0700 "$out_dir"

tar -C / -czf "$out_dir/control-plane-${stamp}.tgz" \
  opt/guanghu/lake-lamp-authz \
  etc/guanghu/navigation-maps \
  etc/systemd/system/lake-lamp-authz.service \
  etc/systemd/system/lake-lamp-action-broker.service \
  etc/systemd/system/lake-lamp-owner-access.service
sha256sum "$out_dir/control-plane-${stamp}.tgz" > "$out_dir/control-plane-${stamp}.sha256"

echo "CONTROL_PLANE_BACKUP_READY=${stamp}"
