From 58e3cbc00b860b7ae394729e11965bb93a4ead6b Mon Sep 17 00:00:00 2001 From: alzyras Date: Fri, 19 Dec 2025 15:14:54 +0200 Subject: [PATCH] Initial backup runner setup --- backup_configs.sh | 6 +++++ backup_home.sh | 6 +++++ backup_vms.sh | 6 +++++ run_backup.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100755 backup_configs.sh create mode 100755 backup_home.sh create mode 100755 backup_vms.sh create mode 100644 run_backup.py diff --git a/backup_configs.sh b/backup_configs.sh new file mode 100755 index 0000000..2e30f2b --- /dev/null +++ b/backup_configs.sh @@ -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" \ No newline at end of file diff --git a/backup_home.sh b/backup_home.sh new file mode 100755 index 0000000..b2206e6 --- /dev/null +++ b/backup_home.sh @@ -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" \ No newline at end of file diff --git a/backup_vms.sh b/backup_vms.sh new file mode 100755 index 0000000..787b12f --- /dev/null +++ b/backup_vms.sh @@ -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" \ No newline at end of file diff --git a/run_backup.py b/run_backup.py new file mode 100644 index 0000000..6c06af1 --- /dev/null +++ b/run_backup.py @@ -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()