|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 | 3 | # =================================================================
|
4 |
| -# Restic Backup Script v0.37.1 - 2025.10.02 |
| 4 | +# Restic Backup Script v0.37.2 - 2025.10.02 |
5 | 5 | # =================================================================
|
6 | 6 |
|
7 | 7 | set -euo pipefail
|
8 | 8 | umask 077
|
9 | 9 |
|
10 | 10 | # --- Script Constants ---
|
11 |
| -SCRIPT_VERSION="0.37.1" |
| 11 | +SCRIPT_VERSION="0.37.2" |
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"
|
@@ -1045,27 +1045,45 @@ run_uninstall_scheduler() {
|
1045 | 1045 | local service_file="/etc/systemd/system/restic-backup.service"
|
1046 | 1046 | local timer_file="/etc/systemd/system/restic-backup.timer"
|
1047 | 1047 | local cron_file="/etc/cron.d/restic-backup"
|
1048 |
| - local found=false |
1049 |
| - |
| 1048 | + local was_systemd=false |
| 1049 | + local was_cron=false |
| 1050 | + local -a files_to_remove=() |
1050 | 1051 | if [ -f "$timer_file" ]; then
|
1051 |
| - found=true |
1052 |
| - echo "Found systemd timer. Stopping and disabling..." |
1053 |
| - systemctl stop restic-backup.timer |
1054 |
| - systemctl disable restic-backup.timer |
1055 |
| - rm -f "$timer_file" "$service_file" |
1056 |
| - systemctl daemon-reload |
1057 |
| - echo -e "${C_GREEN}✅ systemd timer and service files removed.${C_RESET}" |
| 1052 | + was_systemd=true |
| 1053 | + files_to_remove+=("$timer_file") |
| 1054 | + [ -f "$service_file" ] && files_to_remove+=("$service_file") |
1058 | 1055 | fi
|
1059 |
| - |
1060 | 1056 | if [ -f "$cron_file" ]; then
|
1061 |
| - found=true |
1062 |
| - echo "Found cron file. Removing..." |
1063 |
| - rm -f "$cron_file" |
1064 |
| - echo -e "${C_GREEN}✅ Cron file removed.${C_RESET}" |
| 1057 | + was_cron=true |
| 1058 | + files_to_remove+=("$cron_file") |
1065 | 1059 | fi
|
1066 |
| - |
1067 |
| - if [ "$found" = false ]; then |
| 1060 | + if [ ${#files_to_remove[@]} -eq 0 ]; then |
1068 | 1061 | echo -e "${C_YELLOW}No scheduled backup tasks found to uninstall.${C_RESET}"
|
| 1062 | + return 0 |
| 1063 | + fi |
| 1064 | + echo -e "${C_YELLOW}The following scheduled task files will be PERMANENTLY removed:${C_RESET}" |
| 1065 | + for file in "${files_to_remove[@]}"; do |
| 1066 | + echo " - $file" |
| 1067 | + done |
| 1068 | + echo |
| 1069 | + read -p "Are you sure you want to proceed? (y/n): " confirm |
| 1070 | + if [[ "${confirm,,}" != "y" ]]; then |
| 1071 | + echo "Aborted by user." |
| 1072 | + return 0 |
| 1073 | + fi |
| 1074 | + if [[ "$was_systemd" == "true" ]]; then |
| 1075 | + echo "Stopping and disabling systemd timer..." |
| 1076 | + systemctl stop restic-backup.timer >/dev/null 2>&1 || true |
| 1077 | + systemctl disable restic-backup.timer >/dev/null 2>&1 || true |
| 1078 | + fi |
| 1079 | + echo "Removing files..." |
| 1080 | + rm -f "${files_to_remove[@]}" |
| 1081 | + if [[ "$was_systemd" == "true" ]]; then |
| 1082 | + systemctl daemon-reload |
| 1083 | + echo -e "${C_GREEN}✅ systemd timer and service files removed.${C_RESET}" |
| 1084 | + fi |
| 1085 | + if [[ "$was_cron" == "true" ]]; then |
| 1086 | + echo -e "${C_GREEN}✅ Cron file removed.${C_RESET}" |
1069 | 1087 | fi
|
1070 | 1088 | }
|
1071 | 1089 |
|
|
0 commit comments