#!/bin/bash
# usage: cloud-copy-maint prune|check   -- 30-day retention per source (grouped by paths), monthly read-data-subset check
set -u
export RESTIC_REPOSITORY=/tmpool/cloud-copy/restic RESTIC_PASSWORD_FILE=/etc/cloud-copy/restic.pw GOMEMLIMIT=2GiB XDG_CACHE_HOME=/var/cache/cloud-copy; STATE=/var/lib/ctg-backup-cloud; mkdir -p $STATE
case ${1:-} in
 prune) restic forget --host cloud-copy --group-by host,paths --keep-within 30d --prune ;;
 check) if restic check --read-data-subset=5%; then date +%s > $STATE/last-check-ok; else date +%s > $STATE/last-check-fail; exit 1; fi ;;
 *) echo usage; exit 2 ;;
esac
