#!/usr/bin/env bash # Run the backup once on the Kvitt Pi (SPEC ยง10.9) and wait for it: /opt/kvitt/backup-now.sh # Succeeds only when backup.sh succeeded and /backups/last-success changed: the snapshot passed integrity_check, # both files are confirmed on Drive and their local copies are deleted (D-002). Lists the newest files on Drive. set -euo pipefail here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=lib.sh . "$here/lib.sh" before=$(compose exec -T backup cat /backups/last-success 2>/dev/null || true) compose exec -T backup /backup.sh || die "backup.sh failed (lines above)" after=$(compose exec -T backup cat /backups/last-success 2>/dev/null || true) [[ -n "$after" && "$after" != "$before" ]] || die "last-success did not change (was '${before:-none}', is '${after:-none}')" say "last-success: $after" remote=$(env_value RCLONE_REMOTE); folder=$(env_value RCLONE_FOLDER_ID) say "Newest files in the Drive folder:" # shellcheck disable=SC2016 # the script runs inside the backup container, with its own \$1 and \$2 compose exec -T backup sh -c 'c=$(mktemp); cp /config/rclone/rclone.conf "$c"; RCLONE_CONFIG=$c rclone lsf "$1" --drive-root-folder-id "$2" --files-only --log-level ERROR; s=$?; rm -f "$c"; exit $s' \ sh "${remote:-gdrive:}" "$folder" | sort | tail -n 4