-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestic-stop-backups.py
More file actions
109 lines (89 loc) · 3.94 KB
/
restic-stop-backups.py
File metadata and controls
109 lines (89 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
"""
restic-stop-backups.py - Unregister Restic backup scheduled tasks.
Removes the Windows Task Scheduler tasks created by restic-start-backups.py
and restic-health-check.py. Use this when you want to temporarily or
permanently stop automatic backups.
Features:
- Unregisters backup task (ResticHelperBackup)
- Unregisters health check task (ResticHelperHealthCheck)
- Safe to run multiple times
- Requires Administrator privileges on Windows
Usage:
python restic-stop-backups.py # Unregister all tasks
python restic-stop-backups.py --backup # Only unregister backup task
python restic-stop-backups.py --health # Only unregister health check task
python restic-stop-backups.py --dry-run # Show what would be done
Requires Administrator privileges on Windows to modify Task Scheduler.
"""
import os
import sys
import logging
import argparse
import restic_utils as utils
# Task names (must match restic-start-backups.py and restic-health-check.py)
BACKUP_TASK_NAME = "ResticHelperBackup"
HEALTH_TASK_NAME = "ResticHelperHealthCheck"
def main():
parser = argparse.ArgumentParser(description="Unregister Restic backup scheduled tasks")
parser.add_argument("--backup", action="store_true",
help="Only unregister backup task")
parser.add_argument("--health", action="store_true",
help="Only unregister health check task")
parser.add_argument("--dry-run", action="store_true",
help="Show what would be done without making changes")
parser.add_argument("--log-level", default="INFO",
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
help="Set logging level (default: INFO)")
args = parser.parse_args()
# Configure logging
logging.basicConfig(
level=getattr(logging, args.log_level),
format='%(message)s',
handlers=[logging.StreamHandler(sys.stdout)]
)
# Check platform
if sys.platform != "win32":
print("Task Scheduler is only supported on Windows.")
print("On other platforms, remove entries from cron or systemd manually.")
sys.exit(1)
# Check admin privileges
if not utils.is_admin():
print("ERROR: Administrator privileges required to unregister scheduled tasks.")
print("Please run this script as Administrator.")
sys.exit(1)
# Determine which tasks to unregister
unregister_backup = args.backup or not (args.backup or args.health)
unregister_health = args.health or not (args.backup or args.health)
print("Restic Helpers - Unregister Scheduled Tasks")
print("=" * 50)
success = True
if unregister_backup:
if args.dry_run:
is_registered = utils.is_task_registered(BACKUP_TASK_NAME)
if is_registered:
print(f"[DRY-RUN] Would unregister task: {BACKUP_TASK_NAME}")
else:
print(f"[DRY-RUN] Task not registered: {BACKUP_TASK_NAME}")
else:
if not utils.unregister_scheduled_task(BACKUP_TASK_NAME):
success = False
if unregister_health:
if args.dry_run:
is_registered = utils.is_task_registered(HEALTH_TASK_NAME)
if is_registered:
print(f"[DRY-RUN] Would unregister task: {HEALTH_TASK_NAME}")
else:
print(f"[DRY-RUN] Task not registered: {HEALTH_TASK_NAME}")
else:
if not utils.unregister_scheduled_task(HEALTH_TASK_NAME):
success = False
print("=" * 50)
if success:
print("Done. Automatic backups are now disabled.")
print("\nTo re-enable, run: python restic-start-backups.py --register")
else:
print("Some tasks could not be unregistered.")
sys.exit(0 if success else 1)
if __name__ == "__main__":
main()