Menu
AkurAI-Build
publicLatest change b2fb6810b8844f39a9752f65118c05ffecf28160 - Fold AkurAI EC2 operations into Build CLI by Ólafur Búi Ólafsson
set -euo pipefail
retention="$1"
[[ "$retention" =~ ^[0-9]+$ ]] && [ "$retention" -ge 2 ] && [ "$retention" -le 365 ]
[ "$(sudo stat -c %a /etc/omp-workbench-backup/gnupg)" = 700 ]
[ "$(sudo stat -c %U:%G /etc/omp-workbench-backup/gnupg)" = root:root ]
sudo gpg --batch --homedir /etc/omp-workbench-backup/gnupg --with-colons --list-secret-keys \
titan-omp-workbench-offsite@olibuijr.com 2>/dev/null | grep -q '^sec:'
latest="$(sudo find /var/backups/omp-workbench -maxdepth 1 -type f -name 'workbench-*.sqlite.gpg' -printf '%T@ %p\n' | sort -nr | head -1 | cut -d' ' -f2-)"
[ -n "$latest" ] && sudo test -s "$latest"
scratch="$(sudo mktemp -d /var/backups/omp-workbench/.verify-XXXXXXXX)"
cleanup() { sudo rm -rf "$scratch"; }
trap cleanup EXIT
sudo install -o root -g root -m 0600 "$latest" "$scratch/candidate.sqlite.gpg"
[ "$(sudo stat -c %a "$scratch/candidate.sqlite.gpg")" = 600 ]
[ "$(sudo stat -c %U:%G "$scratch/candidate.sqlite.gpg")" = root:root ]
header="$(sudo od -An -N16 -tx1 "$scratch/candidate.sqlite.gpg" | tr -d ' \n')"
[ "$header" != 53514c69746520666f726d6174203300 ]
sudo gpg --batch --homedir /etc/omp-workbench-backup/gnupg \
--output "$scratch/restored.sqlite" --decrypt "$scratch/candidate.sqlite.gpg" >/dev/null 2>&1
[ "$(sudo sqlite3 "$scratch/restored.sqlite" 'PRAGMA quick_check;')" = ok ]
count="$(sudo find /var/backups/omp-workbench -maxdepth 1 -type f -name 'workbench-*.sqlite.gpg' | wc -l)"
[ "$count" -le "$retention" ]
mtime="$(sudo stat -c %y "$latest" | cut -d. -f1)Z"
printf 'timer=active latest=%s backups=%s encryption=gpg recovery=verified\n' "$mtime" "$count"