Skip to content

Commit 47e18ad

Browse files
authored
Merge pull request #28 from buildplan/restore_warning
Restore warning
2 parents ecbc9bc + e5fed81 commit 47e18ad

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

restic-backup.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ RESTIC_CACHE_DIR="/var/cache/restic-backup"
1818
# Each full path should be a separate, quoted element inside the parentheses.
1919
BACKUP_SOURCES=("/home/user_files" "/home/user/my docs")
2020

21+
# --- Safety ---
22+
# Add extra space-separated directories to the critical restore warning list.
23+
# The script already protects core system paths like /etc, /usr, /var.
24+
# Use this to add custom paths like /opt/my-app or /srv/database.
25+
# Example:
26+
# ADDITIONAL_CRITICAL_DIRS="/opt/app /srv/web /home/shared"
27+
ADDITIONAL_CRITICAL_DIRS=""
28+
2129
# --- Backup Options ---
2230
# Backup tag to identify snapshots
2331
BACKUP_TAG="daily-$(hostname)"

restic-backup.sh

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env bash
22

33
# =================================================================
4-
# Restic Backup Script v0.38 - 2025.10.04
4+
# Restic Backup Script v0.38.1 - 2025.10.05
55
# =================================================================
66

77
set -euo pipefail
88
umask 077
99

1010
# --- Script Constants ---
11-
SCRIPT_VERSION="0.38"
11+
SCRIPT_VERSION="0.38.1"
1212
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
1313
CONFIG_FILE="${SCRIPT_DIR}/restic-backup.conf"
1414
LOCK_FILE="/tmp/restic-backup.lock"
@@ -1272,12 +1272,29 @@ run_restore() {
12721272
echo -e "${C_RED}Error: Must be a non-empty, absolute path. Aborting.${C_RESET}" >&2
12731273
return 0
12741274
fi
1275-
if [[ "$restore_dest" == "/" || "$restore_dest" == "/etc" || "$restore_dest" == "/usr" ]]; then
1276-
read -p "${C_RED}WARNING: You are restoring to a critical system directory ('$restore_dest')${C_RESET}. This is highly unusual and could damage your system. Are you absolutely sure? (y/n): " confirm_dangerous_restore
1277-
if [[ "${confirm_dangerous_restore,,}" != "y" ]]; then
1278-
echo "Restore cancelled."
1275+
#--- Dangerous Restore Confirmation ---
1276+
local -a critical_dirs=("/" "/bin" "/boot" "/dev" "/etc" "/lib" "/lib64" "/proc" "/root" "/run" "/sbin" "/sys" "/usr" "/var/lib" "/var/log")
1277+
if [[ -n "${ADDITIONAL_CRITICAL_DIRS:-}" ]]; then
1278+
read -ra additional_dirs <<< "$ADDITIONAL_CRITICAL_DIRS"
1279+
critical_dirs+=("${additional_dirs[@]}")
1280+
fi
1281+
local is_critical=false
1282+
for dir in "${critical_dirs[@]}"; do
1283+
if [[ "$restore_dest" == "$dir" || "$restore_dest" == "$dir"/* ]]; then
1284+
is_critical=true
1285+
break
1286+
fi
1287+
done
1288+
if [[ "$is_critical" == "true" ]]; then
1289+
echo -e "\n${C_RED}${C_BOLD}WARNING: Restoring to critical system directory '$restore_dest'${C_RESET}"
1290+
echo -e "${C_RED}This could damage your system or make it unbootable!${C_RESET}"
1291+
local confirm
1292+
read -p "${C_YELLOW}Type 'DANGEROUS' to proceed or anything else to cancel: ${C_RESET}" confirm
1293+
if [[ "$confirm" != "DANGEROUS" ]]; then
1294+
echo -e "${C_GREEN}Restore cancelled for safety.${C_RESET}"
12791295
return 0
12801296
fi
1297+
log_message "WARNING: User confirmed dangerous restore to: $restore_dest"
12811298
fi
12821299
local include_paths=()
12831300
read -p "Optional: Enter specific file(s) to restore, separated by spaces (leave blank for full restore): " -a include_paths

restic-backup.sh.sha256

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
29187bd2e11bf39a3edb4012b618ff8d17e826023759ee15e49537663163093d restic-backup.sh
1+
e60064159bf9de1519b150b2cc550aaea356e54cefbbb74f65f6110e9d06fb02 restic-backup.sh

0 commit comments

Comments
 (0)