Skip to content

Commit 1518712

Browse files
authored
Merge pull request #26 from buildplan/wip
improved uninstall cron systemd timer
2 parents 31e260a + 0185645 commit 1518712

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

restic-backup.sh

Lines changed: 36 additions & 18 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.37.1 - 2025.10.02
4+
# Restic Backup Script v0.37.2 - 2025.10.02
55
# =================================================================
66

77
set -euo pipefail
88
umask 077
99

1010
# --- Script Constants ---
11-
SCRIPT_VERSION="0.37.1"
11+
SCRIPT_VERSION="0.37.2"
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"
@@ -1045,27 +1045,45 @@ run_uninstall_scheduler() {
10451045
local service_file="/etc/systemd/system/restic-backup.service"
10461046
local timer_file="/etc/systemd/system/restic-backup.timer"
10471047
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=()
10501051
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")
10581055
fi
1059-
10601056
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")
10651059
fi
1066-
1067-
if [ "$found" = false ]; then
1060+
if [ ${#files_to_remove[@]} -eq 0 ]; then
10681061
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}"
10691087
fi
10701088
}
10711089

restic-backup.sh.sha256

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13fbd6d320257c96393649e81a104449f354cdc5e5235743943f241b84017eac restic-backup.sh
1+
a100fda7096eb3a95322df2759e9bb3ca2da49bf43206cc8068737e9b1aa1b1a restic-backup.sh

0 commit comments

Comments
 (0)