Proxmox Hooks

Hi,
where can I find all hook events? I can't find a list in the documentation.
Currently, there are only backup related hooks. For those check /usr/share/pve-docs/examples/guest-example-hookscript.pl on any Proxmox VE installation.
 
the hookscript set in the guest config is called at 4 points in the guest lifecycle at the moment:
- pre-start
- post-start
- pre-stop
- post-stop

with ENV variables indicating things like migration.

the vzdump hook scripts (set via --script for a single vzdump command or a scheduled job) are called during various backup state transitions:
- job-start/-end/-abort (for the whole job)
- backup-start/-end/-abort (for each backup task as part of the job)
- pre-stop/pre-restart/post-restart (of the guest that is backed up)
- log-end

if you have specific other points in mind that have a general use case, feel free to suggest them (either here if you are not sure, or as enhancement request over at https://bugzilla.proxmox.com)
 
Hi Fabian,

I'm wondering if there are PVE Node hooks in the backup tasks? @promoxer has an interesting problem that I'd like to consider a possible solution for: Backup a single VM disk per backup task.

The outline of the solution in my mind would look like:
  1. Create multiple backup tasks
  2. Specify different schedules for each task
  3. Before a task is run, hook into the cluster and have it edit the guest configuration file:
    1. Task 1 Pre-Script: append "backup=no" to disks that need to be excluded with bash script.
    2. Task 2 Pre-Script: append "backup=no" to disks that need to be excluded with bash script.
    3. ...
  4. After a task is run, execute a post script and have it edit the same guest configuration file:
    1. Task 1 Post-Script: remove "backup=no"
    2. Task 2 Post-Script: remove "backup=no"
    3. ...
Some complexities to solve might include:
  • Figuring out which node the VM lives on in a cluster
  • how to cleanly edit the file
But otherwise it seems to solve the problem in my mind at least. API commands would be much cleaner of course but I'm not familiar with them.
Cheers,


Tmanok
 
There is a "HOSTNAME" environment variable that you can read to find out of which node gets backed up. And an argument that contains the the VMID of the VM/LXC as well as "STOREID" environment variable which contains the StorageID of the target backup storage.

So yes, you can do action specific to a node or VM.
 
Last edited:
There is a "HOSTNAME" environment variable that you can read to find out of which node gets backed up. And an argument that contains the the VMID of the VM/LXC as well as "STOREID" environment variable which contains the StorageID of the target backup storage.

So yes, you can do action specific to a node or VM.
Excellent! I'm glad there are variables for this that the cluster can interpret. With the scripting complexities mostly tackled, now we just need to solve the task hookscript.

Cheers!

Tmanok
 
there are hookpoints specific to vzdump, see the example script in /usr/share/doc/pve-manager/examples/vzdump-hook-script.pl . it's only called for backup tasks where 'script' is set to the path of the executable you want to run at the various points. that parameter is not settable for unprivileged users, just for root@pam (since it allows executing arbitrary code).
 
take the example script as template or inspiration. put your own hook script somewhere and make it executable. set the path of your hook script file as "script".
 
there are hookpoints specific to vzdump, see the example script in /usr/share/doc/pve-manager/examples/vzdump-hook-script.pl . it's only called for backup tasks where 'script' is set to the path of the executable you want to run at the various points. that parameter is not settable for unprivileged users, just for root@pam (since it allows executing arbitrary code).
Is there any way to set script parameter for backup job in GUI? Or I need to edit conf file under /etc/pve?
 
you can set one for all jobs and tasks in /etc/vzdump.cfg , or for single jobs in /etc/pve/jobs.cfg . not on the UI and intentionally root only.
 
  • Like
Reactions: rahman
you can set one for all jobs and tasks in /etc/vzdump.cfg , or for single jobs in /etc/pve/jobs.cfg . not on the UI and intentionally root only.
Thank you for the clarification. When I see you mentioned "root@pam", I thought the settings is in the UI if I login as root@pam.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!