recover.sh

 1#!/usr/bin/env bash
 2set -euo pipefail
 3
 4# Restores /var/soft/data from the R2 backup (r2:soft-serve) and rebuilds
 5# the static site, which isn't backed up. Run as root on the forge host.
 6#
 7# `rclone sync` deletes: before restoring onto a new box, make sure no other
 8# box still runs the backup timer against r2:soft-serve, and that this box's
 9# timer hasn't backed up an empty /var/soft/data over it.
10
11RCLONE="${RCLONE:-$(command -v rclone 2>/dev/null)}"
12export RCLONE_CONFIG="${RCLONE_CONFIG:-/var/lib/servers-keys/rclone.conf}"
13GREEN='\033[0;32m'
14RED='\033[0;31m'
15NC='\033[0m'
16
17
18echo "starting soft-serve recovery"
19systemctl stop soft-serve.service
20
21if $RCLONE sync -L r2:soft-serve/ /var/soft/data/; then
22    echo -e "[${GREEN}SUCCESS${NC}] soft-serve recovery complete"
23    systemctl start soft-serve.service
24    echo "rebuilding the static site"
25    forge-rebuild-site >> /var/log/pgit.log 2>&1
26else
27    echo -e "[${RED}FAILED${NC}] soft-serve stopped"
28    exit 1
29fi