Skip to content

Commit e5a8679

Browse files
authored
Merge pull request #17 from buildplan/improve_restore
Improved restore safety check
2 parents 7356514 + 3f8e1e2 commit e5a8679

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

restic-backup.sh

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

33
# =================================================================
4-
# Restic Backup Script v0.31 - 2025.09.27
4+
# Restic Backup Script v0.32 - 2025.09.27
55
# =================================================================
66

77
set -euo pipefail
88
umask 077
99

1010
# --- Script Constants ---
11-
SCRIPT_VERSION="0.31"
11+
SCRIPT_VERSION="0.32"
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"
1515
HOSTNAME=$(hostname -s)
1616

1717
# --- Color Palette ---
1818
if [ -t 1 ]; then
19-
C_RESET='\e[0m'
20-
C_BOLD='\e[1m'
21-
C_DIM='\e[2m'
22-
C_RED='\e[0;31m'
23-
C_GREEN='\e[0;32m'
24-
C_YELLOW='\e[0;33m'
25-
C_CYAN='\e[0;36m'
19+
C_RESET=$'\e[0m'
20+
C_BOLD=$'\e[1m'
21+
C_DIM=$'\e[2m'
22+
C_RED=$'\e[0;31m'
23+
C_GREEN=$'\e[0;32m'
24+
C_YELLOW=$'\e[0;33m'
25+
C_CYAN=$'\e[0;36m'
2626
else
2727
C_RESET=''
2828
C_BOLD=''
@@ -1009,6 +1009,13 @@ run_restore() {
10091009
echo -e "${C_RED}Error: Must be a non-empty, absolute path. Aborting.${C_RESET}" >&2
10101010
return 1
10111011
fi
1012+
if [[ "$restore_dest" == "/" || "$restore_dest" == "/etc" || "$restore_dest" == "/usr" ]]; then
1013+
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
1014+
if [[ "${confirm_dangerous_restore,,}" != "y" ]]; then
1015+
echo "Restore cancelled."
1016+
return 1
1017+
fi
1018+
fi
10121019
local include_paths=()
10131020
read -p "Optional: Enter specific file(s) to restore, separated by spaces (leave blank for full restore): " -a include_paths
10141021
local restic_cmd=(restic restore "$snapshot_id" --target "$restore_dest" --verbose)

restic-backup.sh.sha256

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9a870262d8c680ea1afaf2bef175088f75c599de7fa06f39974f22d6e89e4c8d restic-backup.sh
1+
0d5c7c7bbd9a39cb27588b6b7f6bf33de8a6167f2c7482d3dff20d3710b5b2b1 restic-backup.sh

0 commit comments

Comments
 (0)