diff --git a/README.md b/README.md index 52098ea..0d506e9 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ For those familiar with setting up backup scripts, here is a fast track to get y - `sudo ./restic-backup.sh --background-restore ` — Non-blocking background restore (logs to /tmp). - `sudo ./restic-backup.sh --exact-ownership --restore` — To use with any of the restore flags to perserve files ownership. - `sudo ./restic-backup.sh --sync-restore ` — Blocking restore suitable for cron/automation. +- `sudo ./restic-backup.sh --cache-cleanup` — Remove old/orphaned cache directories. - `sudo ./restic-backup.sh --forget` — Apply retention policy (optionally prunes). - `sudo ./restic-backup.sh --diff` — Summary of changes between the last two snapshots. - `sudo ./restic-backup.sh --stats` — Repository stats (logical/physical sizes). diff --git a/restic-backup.sh b/restic-backup.sh index 72253dd..d765688 100644 --- a/restic-backup.sh +++ b/restic-backup.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # ================================================================= -# Restic Backup Script v0.44 - 2026.03.27 +# Restic Backup Script v0.45 - 2026.05.09 # ================================================================= export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH @@ -9,7 +9,7 @@ set -euo pipefail umask 077 # --- Script Constants --- -SCRIPT_VERSION="0.44" +SCRIPT_VERSION="0.45" SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) PROG_NAME=$(basename "$0"); readonly PROG_NAME CONFIG_FILE="${SCRIPT_DIR}/restic-backup.conf" @@ -58,6 +58,7 @@ display_help() { printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--stats" "Display repository size and file counts." printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--check" "Verify repository integrity (subset)." printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--check-full" "Verify all repository data (slow)." + printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--cache-cleanup" "Remove old/orphaned cache directories." printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--forget" "Apply retention policy; optionally prune." printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--unlock" "Remove stale repository locks." printf " ${C_GREEN}%-20s${C_RESET} %s\n" "--dump " "Dump a single file from a snapshot to stdout." @@ -1421,6 +1422,19 @@ run_forget() { fi } +run_cache_cleanup() { + echo -e "${C_BOLD}--- Cleaning Restic Cache ---${C_RESET}" + log_message "Running restic cache --cleanup" + if restic cache --cleanup; then + echo -e "${C_GREEN}✅ Cache cleanup completed successfully.${C_RESET}" + log_message "Cache cleanup successful." + else + echo -e "${C_RED}❌ Cache cleanup failed.${C_RESET}" >&2 + log_message "ERROR: Cache cleanup failed." + return 1 + fi +} + run_check() { echo -e "${C_BOLD}--- Checking Repository Integrity ---${C_RESET}" log_message "Running integrity check" @@ -1934,6 +1948,10 @@ case "${1:-}" in run_preflight_checks "backup" "quiet" run_forget ;; + --cache-cleanup) + run_preflight_checks "cache" "quiet" + run_cache_cleanup + ;; --diff) run_preflight_checks "diff" "quiet" run_diff diff --git a/restic-backup.sh.sha256 b/restic-backup.sh.sha256 index fa879e3..bbd72a3 100644 --- a/restic-backup.sh.sha256 +++ b/restic-backup.sh.sha256 @@ -1 +1 @@ -d545db8df2f0f3d59b4e59d4cc5f59a2e44adc74f64e188c88540b683811ef57 restic-backup.sh +52a1734972189b3e0509055659678722d58b72eb9baa5a22dbc1b1d207e7c262 restic-backup.sh