#!/usr/bin/env bash set -euo pipefail # === METADATA === SCRIPT_NAME="$(basename "$0")" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SKILL_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" # === CONFIGURATION === : "${OUTPUT_DIR:=$SKILL_ROOT/outputs}" # === FUNCTIONS === log_info() { echo "[INFO] $(date -Iseconds) $*"; } log_warn() { echo "[WARN] $(date -Iseconds) $*" >&2; } log_error() { echo "[ERROR] $(date -Iseconds) $*" >&2; } die() { log_error "$@"; exit 1; } main() { local last_run_file="$OUTPUT_DIR/last_run_dir.txt" if [[ ! -f "$last_run_file" ]]; then log_warn "No last run pointer found. Nothing to undo." exit 0 fi local run_dir run_dir="$(cat "$last_run_file")" if [[ ! -d "$run_dir" ]]; then log_warn "Run directory does not exist: $run_dir" rm -f "$last_run_file" exit 0 fi log_warn "This will remove the last backup run:" log_warn " $run_dir" echo "" echo "Type 'DELETE' to confirm:" read -r confirm [[ "$confirm" == "DELETE" ]] || die "Aborted." # Clean up restore drill temp directory if it exists if [[ -f "$run_dir/last_restore_dir.txt" ]]; then local restore_dir restore_dir="$(cat "$run_dir/last_restore_dir.txt")" if [[ -d "$restore_dir" ]]; then log_info "Removing restore drill temp: $restore_dir" rm -rf "$restore_dir" fi fi log_info "Removing run directory: $run_dir" rm -rf "$run_dir" log_info "Removing last run pointer" rm -f "$last_run_file" log_info "Undo complete." } [[ "${BASH_SOURCE[0]}" == "$0" ]] && main "$@"