|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | 3 | # ================================================================= |
4 | | -# Restic Backup Script v0.38 - 2025.10.04 |
| 4 | +# Restic Backup Script v0.38.1 - 2025.10.05 |
5 | 5 | # ================================================================= |
6 | 6 |
|
7 | 7 | set -euo pipefail |
8 | 8 | umask 077 |
9 | 9 |
|
10 | 10 | # --- Script Constants --- |
11 | | -SCRIPT_VERSION="0.38" |
| 11 | +SCRIPT_VERSION="0.38.1" |
12 | 12 | SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) |
13 | 13 | CONFIG_FILE="${SCRIPT_DIR}/restic-backup.conf" |
14 | 14 | LOCK_FILE="/tmp/restic-backup.lock" |
@@ -1272,12 +1272,29 @@ run_restore() { |
1272 | 1272 | echo -e "${C_RED}Error: Must be a non-empty, absolute path. Aborting.${C_RESET}" >&2 |
1273 | 1273 | return 0 |
1274 | 1274 | 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}" |
1279 | 1295 | return 0 |
1280 | 1296 | fi |
| 1297 | + log_message "WARNING: User confirmed dangerous restore to: $restore_dest" |
1281 | 1298 | fi |
1282 | 1299 | local include_paths=() |
1283 | 1300 | read -p "Optional: Enter specific file(s) to restore, separated by spaces (leave blank for full restore): " -a include_paths |
|
0 commit comments