Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <snapshot> <dest>` — 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 <snapshot> <dest>` — 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).
Expand Down
22 changes: 20 additions & 2 deletions restic-backup.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/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
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"
Expand Down Expand Up @@ -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 <id> <path>" "Dump a single file from a snapshot to stdout."
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion restic-backup.sh.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d545db8df2f0f3d59b4e59d4cc5f59a2e44adc74f64e188c88540b683811ef57 restic-backup.sh
52a1734972189b3e0509055659678722d58b72eb9baa5a22dbc1b1d207e7c262 restic-backup.sh
Loading