# shellcheck shell=bash # Scenarios set what the runner and items read # shellcheck disable=SC2034 DESCRIPTION="A backup with Ubuntu's restic and rclone to a local WebDAV server standing in for Nextcloud" TIER=quick scenario() { local served="$HOME/served" webdav="http://127.0.0.1:8080/remote.php/dav/files/jo" step "Installing restic and rclone" sudo apt-get update > /dev/null && sudo apt-get install -y restic rclone > /dev/null 2>&1 check "restic and rclone are installed" pkg_installed restic rclone echo "restic $(restic version | cut -d' ' -f2), $(rclone version | head -n 1)" # Nextcloud's WebDAV, and status.php, which the backup waits for mkdir -p "$served/remote.php/dav/files/jo" echo '{"installed":true,"maintenance":false}' > "$served/status.php" rclone serve webdav "$served" --addr 127.0.0.1:8080 --user jo --pass app-password > "$HOME/serve.log" 2>&1 & sleep 2 step "Setting up, as configure backup does" mkdir -p "$CONF_DIR" printf 'BACKUP_WEBDAV=%q\nBACKUP_USER=jo\nBACKUP_DIR=.backup-smoke\n' "$webdav" > "$CONF_DIR/backup.conf" printf app-password | secret-tool store --label test federated-connector backup item nextcloud url "$webdav" printf 'pass phrase' | secret-tool store --label test federated-connector backup item passphrase url "$webdav/.backup-smoke" source "$CONNECTOR/system/backup-env.sh" check_eq "restic uses rclone's WebDAV" "rclone::webdav:.backup-smoke" "$RESTIC_REPOSITORY" check "the passphrase comes from the keyring" test -n "$RESTIC_PASSWORD_COMMAND" check "rclone reaches the server with the app password" rclone lsf ":webdav:" check "restic init" restic init step "A backup" mkdir -p "$HOME/Documents" "$HOME/.cache/big" echo "keep me" > "$HOME/Documents/note.txt" echo "leave me out" > "$HOME/.cache/big/file" check "system/backup" "$CONNECTOR/system/backup" check_eq "there's one snapshot" 1 "$(restic snapshots --json | jq length)" check "a file restores from it" restic restore latest --target "$HOME/restored" --include "$HOME/Documents" check_eq "...as it was" "keep me" "$(cat "$HOME/restored$HOME/Documents/note.txt")" check_not "caches are left out" bash -c "restic ls latest | grep -q '/.cache/big'" check_not "the install is left out" bash -c "restic ls latest | grep -q '/.local/share/federated-connector/'" step "Without the passphrase in the keyring" secret-tool clear federated-connector backup item passphrase url "$webdav/.backup-smoke" check_not "system/backup fails" "$CONNECTOR/system/backup" }