Compare commits

...

3 Commits

Author SHA1 Message Date
521d08969b Added information about ongoing-blocking tasks 2026-08-09 11:00:16 +02:00
74ba296cda Added missing ipmitool 2026-08-09 10:59:07 +02:00
a5fb874a20 fixed a problem where scheduler didn't got the TZ 2026-08-09 10:34:48 +02:00
3 changed files with 28 additions and 10 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
venv
docker-compose.dev.yaml

View File

@@ -1,6 +1,7 @@
FROM python:3.14.7-alpine3.24
RUN apk update && \
apk add ipmitool
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

32
main.py
View File

@@ -32,6 +32,7 @@ AUTO_ADD_NAME: Final[str] = os.getenv("AUTO_ADD_NAME", "autoBackupScript_one-sho
RUN_SCHEDULE: Final[str] = os.getenv("RUN_SCHEDULE", "45 17 * * 5")
RUN_SCHEDULE_TZ: Final[str] = os.getenv("RUN_SCHEDULE_TZ", "Europe/Stockholm")
RUN_ONE_SHOT: Final[bool] = bool(os.getenv("RUN_ONE_SHOT", False))
@@ -160,21 +161,21 @@ def theCodeBasically():
# print(epoch_time)
# Check if power is on
PWR_STATE = subprocess.run(["ipmitool", "-I", "lanplus","-H", IDRAC,"-U", IDRAC_USR,"-P", IDRAC_PWD,"chassis", "power", "status",],capture_output=True,text=True,)
PWR_STATE = subprocess.run(["/usr/sbin/ipmitool", "-I", "lanplus","-H", IDRAC,"-U", IDRAC_USR,"-P", IDRAC_PWD,"chassis", "power", "status",],capture_output=True,text=True,)
if PWR_STATE.returncode != 0:
raise RuntimeError(f"ipmitool failed: {PWR_STATE.stderr.strip()}")
raise RuntimeError(f"/usr/sbin/ipmitool failed: {PWR_STATE.stderr.strip()}")
if "off" in PWR_STATE.stdout.lower():
subprocess.run(["ipmitool", "-I", "lanplus","-H", IDRAC,"-U", IDRAC_USR,"-P", IDRAC_PWD,"chassis", "power", "on",],check=True,)
subprocess.run(["/usr/sbin/ipmitool", "-I", "lanplus","-H", IDRAC,"-U", IDRAC_USR,"-P", IDRAC_PWD,"chassis", "power", "on",],check=True,)
# PWR_STATE = subprocess.run(["ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "status"], capture_output=True)
# PWR_STATE = subprocess.run(["/usr/sbin/ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "status"], capture_output=True)
# try:
# # power on if needed
# if "off" in str(PWR_STATE.stdout.decode()[-4:]):
# subprocess.run(["ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "on"]) # , capture_output=True
# subprocess.run(["/usr/sbin/ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "on"]) # , capture_output=True
# except Exception as e:
# print("Most likely wrong password, username or hostname has been passed for idrac.\nExiting\n")
# sys.exit(1)
@@ -345,6 +346,10 @@ def theCodeBasically():
(stdin, stdout, stderr) = ssh.exec_command(f"proxmox-backup-manager sync-job run {AUTO_ADD_NAME}")
# (stdin, stdout, stderr) = ssh.exec_command(
# f"nohup proxmox-backup-manager sync-job run {AUTO_ADD_NAME} >/var/log/{AUTO_ADD_NAME}.log 2>&1 </dev/null &"
# )
# ssh.exec_command(f"proxmox-backup-manager sync-job run {AUTO_ADD_NAME}")
# print("here it runs the sync-job")
# print(stdout.read().decode())
@@ -354,6 +359,9 @@ def theCodeBasically():
if syncJobRunExitCode != 0:
raise RuntimeError(f"Sync job failed: {stderr.read().decode()}")
# raise RuntimeError(f"Failed to start sync job: {stderr.read().decode()}")
else:
print("Sync successful")
# Give some time for PBS to "start" the sync-job task
time.sleep(10)
@@ -377,6 +385,11 @@ def theCodeBasically():
while currenttasks:
print("Waiting 1 minute before checking tasks again")
print("Remaining jobs:")
for job in currenttasks:
print(f"Task {job} Amount {currenttasks[job]}")
time.sleep(60)
currenttasks = getCurrentTasks(ssh, limitOfTasks=PBS_TASK_LIMIT)
@@ -384,6 +397,7 @@ def theCodeBasically():
if time.monotonic() - SYNC_JOB_DATE >= (PBS_MAX_RUNTIME_MIN * 60):
# print(SYNC_JOB_DATE - time.monotonic())
# Forcefully skip if these tasks are running. reader task is, I think, PVE backup
# Also otherjob is something else and it is better to wait if there is one otherjob
if (
@@ -412,15 +426,17 @@ def theCodeBasically():
print("PBS is powered off")
else:
subprocess.run(["ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "off"])
subprocess.run(["/usr/sbin/ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "off"])
# sys.exit(0)
if RUN_ONE_SHOT:
theCodeBasically()
exit(0)
scheduler = BlockingScheduler()
scheduler = BlockingScheduler(timezone=RUN_SCHEDULE_TZ)
scheduler.add_job(
theCodeBasically,
CronTrigger.from_crontab(