Running scripts before and after a back job for a specific vm in Proxmox VE

cmkrs

Active Member
Jan 18, 2021
7
0
41
Hi there,
I am seeking for advice on how to stop a service prior to a backup job (PBS is used for backup) and start it afterwards. I'd like to accomplish this from the Proxmox host as opposed to from inside the VM itself. (as in coordinating the schedules of the script's and backup job's start and stop times)

I have a VM that runs a docker based db engine and I need to stop this service before the backup job starts and start again once the backup job is completed. The Proxmox VE GUI for the backup (under the backup section of the VM or the DataCenter/Backup section) does not provide any option to address this challenge.

Any ideas?

Thank you

ck
 

 
  • Like
Reactions: waltar
Just edit:
/etc/pve/jobs.cfg

You see something like this:
vzdump: backup-24904b8b-985d
comment Backup snapshots
schedule mon..sat 04:00
compress zstd
enabled 1
fleecing 0
mode snapshot
notes-template {{guestname}}
notification-mode notification-system
prune-backups keep-daily=7,keep-monthly=2
script /root/backup-hook.sh
storage NH-Backup
vmid 5001,5031,5006,5005,5015,5016,5030,5035,5036,5040,5045,5038,5042,5018,5032,5009

Notice the line with: script.

inside backup-hook.sh:
#!/bin/bash
PHASE=$1

case "$PHASE" in
job-start)
curl -s -X POST "http://192.168.5.9:7575/api/snooze?minutes=120"
curl -s -X POST "http://192.168.6.9:7575/api/snooze?minutes=120"
;;
job-end|job-abort)
curl -s -X POST "http://192.168.5.9:7575/api/snooze?minutes=0"
curl -s -X POST "http://192.168.6.9:7575/api/snooze?minutes=0"
;;
esac

De curl's are a example, include whatever you want. It will be executed before and after the backup job. Make sure to use chmod +X on backup-hook.sh