dargslan-crontab-backup 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dargslan_crontab_backup-1.0.0/PKG-INFO +43 -0
- dargslan_crontab_backup-1.0.0/README.md +25 -0
- dargslan_crontab_backup-1.0.0/dargslan_crontab_backup/__init__.py +80 -0
- dargslan_crontab_backup-1.0.0/dargslan_crontab_backup/cli.py +20 -0
- dargslan_crontab_backup-1.0.0/dargslan_crontab_backup.egg-info/PKG-INFO +43 -0
- dargslan_crontab_backup-1.0.0/dargslan_crontab_backup.egg-info/SOURCES.txt +9 -0
- dargslan_crontab_backup-1.0.0/dargslan_crontab_backup.egg-info/dependency_links.txt +1 -0
- dargslan_crontab_backup-1.0.0/dargslan_crontab_backup.egg-info/entry_points.txt +2 -0
- dargslan_crontab_backup-1.0.0/dargslan_crontab_backup.egg-info/top_level.txt +1 -0
- dargslan_crontab_backup-1.0.0/pyproject.toml +28 -0
- dargslan_crontab_backup-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dargslan-crontab-backup
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Crontab backup manager -- export, restore, and diff user crontabs with timestamped backups.
|
|
5
|
+
Author-email: Dargslan <info@dargslan.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://dargslan.com
|
|
8
|
+
Project-URL: Documentation, https://dargslan.com/blog
|
|
9
|
+
Keywords: linux,crontab,backup,cron,restore,sysadmin
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: System Administrators
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: System :: Systems Administration
|
|
16
|
+
Requires-Python: >=3.7
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# dargslan-crontab-backup
|
|
20
|
+
|
|
21
|
+
**Crontab Backup** -- Part of the Dargslan Linux Sysadmin Toolkit.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install dargslan-crontab-backup
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or install the complete toolkit (72 tools):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install dargslan-toolkit
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## More Resources
|
|
36
|
+
|
|
37
|
+
- **210+ Linux & DevOps eBooks**: [dargslan.com/books](https://dargslan.com/books)
|
|
38
|
+
- **Free Cheat Sheets**: [dargslan.com/cheat-sheets](https://dargslan.com/cheat-sheets)
|
|
39
|
+
- **Blog & Tutorials**: [dargslan.com/blog](https://dargslan.com/blog)
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT -- [dargslan.com](https://dargslan.com)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# dargslan-crontab-backup
|
|
2
|
+
|
|
3
|
+
**Crontab Backup** -- Part of the Dargslan Linux Sysadmin Toolkit.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install dargslan-crontab-backup
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or install the complete toolkit (72 tools):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install dargslan-toolkit
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## More Resources
|
|
18
|
+
|
|
19
|
+
- **210+ Linux & DevOps eBooks**: [dargslan.com/books](https://dargslan.com/books)
|
|
20
|
+
- **Free Cheat Sheets**: [dargslan.com/cheat-sheets](https://dargslan.com/cheat-sheets)
|
|
21
|
+
- **Blog & Tutorials**: [dargslan.com/blog](https://dargslan.com/blog)
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
MIT -- [dargslan.com](https://dargslan.com)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""dargslan-crontab-backup -- Crontab backup manager.
|
|
2
|
+
Export, restore, and diff user crontabs with timestamped backups.
|
|
3
|
+
Part of the Dargslan Linux Sysadmin Toolkit: https://dargslan.com
|
|
4
|
+
"""
|
|
5
|
+
__version__ = "1.0.0"
|
|
6
|
+
import subprocess, os, pwd
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
|
|
9
|
+
BACKUP_DIR = "/var/backups/crontabs"
|
|
10
|
+
|
|
11
|
+
def get_all_users():
|
|
12
|
+
users = []
|
|
13
|
+
try:
|
|
14
|
+
for p in pwd.getpwall():
|
|
15
|
+
if p.pw_uid >= 1000 or p.pw_name == "root":
|
|
16
|
+
users.append(p.pw_name)
|
|
17
|
+
except: pass
|
|
18
|
+
return sorted(users)
|
|
19
|
+
|
|
20
|
+
def get_user_crontab(user="root"):
|
|
21
|
+
try:
|
|
22
|
+
r = subprocess.run(["crontab", "-l", "-u", user], capture_output=True, text=True, timeout=10)
|
|
23
|
+
if r.returncode == 0: return r.stdout
|
|
24
|
+
except (subprocess.SubprocessError, FileNotFoundError): pass
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
def export_all_crontabs(backup_dir=None):
|
|
28
|
+
if not backup_dir: backup_dir = BACKUP_DIR
|
|
29
|
+
os.makedirs(backup_dir, exist_ok=True)
|
|
30
|
+
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
31
|
+
exported = []
|
|
32
|
+
for user in get_all_users():
|
|
33
|
+
crontab = get_user_crontab(user)
|
|
34
|
+
if crontab and crontab.strip():
|
|
35
|
+
fname = f"{user}_{ts}.crontab"
|
|
36
|
+
path = os.path.join(backup_dir, fname)
|
|
37
|
+
try:
|
|
38
|
+
with open(path, "w") as f: f.write(crontab)
|
|
39
|
+
exported.append({"user": user, "file": path, "lines": len(crontab.strip().split("\n"))})
|
|
40
|
+
except OSError: pass
|
|
41
|
+
return exported
|
|
42
|
+
|
|
43
|
+
def list_backups(backup_dir=None):
|
|
44
|
+
if not backup_dir: backup_dir = BACKUP_DIR
|
|
45
|
+
backups = []
|
|
46
|
+
if os.path.isdir(backup_dir):
|
|
47
|
+
for f in sorted(os.listdir(backup_dir)):
|
|
48
|
+
if f.endswith(".crontab"):
|
|
49
|
+
path = os.path.join(backup_dir, f)
|
|
50
|
+
backups.append({"file": f, "path": path, "size": os.path.getsize(path), "modified": datetime.fromtimestamp(os.path.getmtime(path)).strftime("%Y-%m-%d %H:%M")})
|
|
51
|
+
return backups
|
|
52
|
+
|
|
53
|
+
def get_system_cron_jobs():
|
|
54
|
+
jobs = []
|
|
55
|
+
for d in ["/etc/cron.d", "/etc/cron.daily", "/etc/cron.hourly", "/etc/cron.weekly", "/etc/cron.monthly"]:
|
|
56
|
+
if os.path.isdir(d):
|
|
57
|
+
for f in os.listdir(d):
|
|
58
|
+
path = os.path.join(d, f)
|
|
59
|
+
if os.path.isfile(path): jobs.append({"directory": d, "file": f, "path": path})
|
|
60
|
+
return jobs
|
|
61
|
+
|
|
62
|
+
def generate_report():
|
|
63
|
+
users = get_all_users()
|
|
64
|
+
system_jobs = get_system_cron_jobs()
|
|
65
|
+
backups = list_backups()
|
|
66
|
+
lines = ["="*60, "CRONTAB BACKUP REPORT", "="*60]
|
|
67
|
+
lines.append(f"\nSystem users with crontabs:")
|
|
68
|
+
for u in users:
|
|
69
|
+
ct = get_user_crontab(u)
|
|
70
|
+
if ct and ct.strip():
|
|
71
|
+
count = len([l for l in ct.strip().split("\n") if l.strip() and not l.startswith("#")])
|
|
72
|
+
lines.append(f" {u:20s} {count} active jobs")
|
|
73
|
+
if system_jobs:
|
|
74
|
+
lines.append(f"\n--- System Cron Jobs ({len(system_jobs)}) ---")
|
|
75
|
+
for j in system_jobs: lines.append(f" {j['directory']:25s} {j['file']}")
|
|
76
|
+
if backups:
|
|
77
|
+
lines.append(f"\n--- Saved Backups ({len(backups)}) ---")
|
|
78
|
+
for b in backups[-10:]: lines.append(f" {b['modified']} {b['file']}")
|
|
79
|
+
lines += ["\n"+"="*60, "More tools: https://dargslan.com | pip install dargslan-toolkit", "="*60]
|
|
80
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from dargslan_crontab_backup import generate_report, export_all_crontabs, list_backups, get_user_crontab, get_system_cron_jobs
|
|
3
|
+
def main():
|
|
4
|
+
cmd = sys.argv[1] if len(sys.argv) > 1 else "report"
|
|
5
|
+
if cmd == "report": print(generate_report())
|
|
6
|
+
elif cmd == "export":
|
|
7
|
+
exported = export_all_crontabs()
|
|
8
|
+
for e in exported: print(f" Exported {e['user']} ({e['lines']} lines) -> {e['file']}")
|
|
9
|
+
if not exported: print("No crontabs to export.")
|
|
10
|
+
elif cmd == "list":
|
|
11
|
+
for b in list_backups(): print(f" {b['modified']} {b['file']}")
|
|
12
|
+
elif cmd == "show":
|
|
13
|
+
user = sys.argv[2] if len(sys.argv) > 2 else "root"
|
|
14
|
+
ct = get_user_crontab(user)
|
|
15
|
+
print(ct if ct else f"No crontab for {user}")
|
|
16
|
+
elif cmd == "system":
|
|
17
|
+
for j in get_system_cron_jobs(): print(f" {j['directory']:25s} {j['file']}")
|
|
18
|
+
elif cmd in ("help","--help","-h"): print("dargslan-cronbak -- Crontab backup manager\nUsage: dargslan-cronbak [report|export|list|show <user>|system]\nMore: https://dargslan.com")
|
|
19
|
+
else: print(f"Unknown: {cmd}. Use --help"); sys.exit(1)
|
|
20
|
+
if __name__ == "__main__": main()
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dargslan-crontab-backup
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Crontab backup manager -- export, restore, and diff user crontabs with timestamped backups.
|
|
5
|
+
Author-email: Dargslan <info@dargslan.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://dargslan.com
|
|
8
|
+
Project-URL: Documentation, https://dargslan.com/blog
|
|
9
|
+
Keywords: linux,crontab,backup,cron,restore,sysadmin
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: System Administrators
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: System :: Systems Administration
|
|
16
|
+
Requires-Python: >=3.7
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# dargslan-crontab-backup
|
|
20
|
+
|
|
21
|
+
**Crontab Backup** -- Part of the Dargslan Linux Sysadmin Toolkit.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install dargslan-crontab-backup
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or install the complete toolkit (72 tools):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install dargslan-toolkit
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## More Resources
|
|
36
|
+
|
|
37
|
+
- **210+ Linux & DevOps eBooks**: [dargslan.com/books](https://dargslan.com/books)
|
|
38
|
+
- **Free Cheat Sheets**: [dargslan.com/cheat-sheets](https://dargslan.com/cheat-sheets)
|
|
39
|
+
- **Blog & Tutorials**: [dargslan.com/blog](https://dargslan.com/blog)
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT -- [dargslan.com](https://dargslan.com)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
dargslan_crontab_backup/__init__.py
|
|
4
|
+
dargslan_crontab_backup/cli.py
|
|
5
|
+
dargslan_crontab_backup.egg-info/PKG-INFO
|
|
6
|
+
dargslan_crontab_backup.egg-info/SOURCES.txt
|
|
7
|
+
dargslan_crontab_backup.egg-info/dependency_links.txt
|
|
8
|
+
dargslan_crontab_backup.egg-info/entry_points.txt
|
|
9
|
+
dargslan_crontab_backup.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dargslan_crontab_backup
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dargslan-crontab-backup"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Crontab backup manager -- export, restore, and diff user crontabs with timestamped backups."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.7"
|
|
12
|
+
authors = [{name = "Dargslan", email = "info@dargslan.com"}]
|
|
13
|
+
keywords = ["linux", "crontab,backup,cron,restore,sysadmin"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 5 - Production/Stable",
|
|
16
|
+
"Intended Audience :: System Administrators",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: POSIX :: Linux",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: System :: Systems Administration",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
dargslan-cronbak = "dargslan_crontab_backup.cli:main"
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://dargslan.com"
|
|
28
|
+
Documentation = "https://dargslan.com/blog"
|