Initial backup runner setup

This commit is contained in:
2025-12-19 15:14:54 +02:00
commit 58e3cbc00b
4 changed files with 85 additions and 0 deletions

6
backup_configs.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
echo "[$(date)] Starting config backup"
echo "Backing up /etc configuration files"
echo "[$(date)] Config backup completed"

6
backup_home.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
echo "[$(date)] Starting home backup"
echo "Backing up /home to /backups/home"
echo "[$(date)] Home backup completed"

6
backup_vms.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
echo "[$(date)] Starting VM backup"
echo "Snapshotting KVM virtual machines"
echo "[$(date)] VM backup completed"

67
run_backup.py Normal file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/env python3
import subprocess
import datetime
import pathlib
import sys
import os
# ================= CONFIG =================
SCRIPTS = [
"backup_configs.sh",
"backup_home.sh",
"backup_vms.sh",
]
LOG_DIR = "job-runner"
# ==========================================
def timestamp():
return datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
def safe_name(path):
return pathlib.Path(path).stem
def run_script(script_path, run_ts):
name = safe_name(script_path)
out_file = pathlib.Path(LOG_DIR) / f"{name}_{run_ts}.out"
err_file = pathlib.Path(LOG_DIR) / f"{name}_{run_ts}.err"
with open(out_file, "wb") as out, open(err_file, "wb") as err:
proc = subprocess.Popen(
["/bin/bash", script_path],
stdout=out,
stderr=err,
env={
"PATH": "/usr/sbin:/usr/bin:/bin",
"LANG": "C",
},
)
return proc.wait()
def main():
os.makedirs(LOG_DIR, exist_ok=True)
run_ts = timestamp()
for script in SCRIPTS:
if not os.path.isfile(script) or not os.access(script, os.X_OK):
print(f"ERROR: Script not executable: {script}", file=sys.stderr)
sys.exit(1)
rc = run_script(script, run_ts)
if rc != 0:
print(f"ERROR: {script} failed with exit code {rc}", file=sys.stderr)
sys.exit(rc)
sys.exit(0)
if __name__ == "__main__":
main()