PBS Sync-Job : Pre- and Post-Hook Support for Sync Jobs in Proxmox Backup Server

msalese

New Member
Apr 22, 2025
2
0
1
Hello everyone,

I am currently working with Proxmox Backup Server (PBS) and I have a situation where I would like to automatically change ZFS dataset properties (e.g., setting readonly=off) before a sync job starts, and then set them back (e.g., readonly=on) after the sync job finishes.

However, it seems that sync jobs currently do not offer any option for pre- or post-execution hooks.

My questions are:

Is there any hidden method or workaround to run pre/post scripts for sync jobs?

Is native pre/post hook support for sync jobs planned for future versions of PBS?

If not, would it be possible to request this feature for future releases?

This functionality would be extremely useful for dynamically managing the environment before and after large data sync operations.

Thanks a lot for your help and for the fantastic work on PBS!

Best regards,
Massimo
 
Hello everyone,

I am currently working with Proxmox Backup Server (PBS) and I have a situation where I would like to automatically change ZFS dataset properties (e.g., setting readonly=off) before a sync job starts, and then set them back (e.g., readonly=on) after the sync job finishes.

However, it seems that sync jobs currently do not offer any option for pre- or post-execution hooks.

My questions are:

Is there any hidden method or workaround to run pre/post scripts for sync jobs?

Is native pre/post hook support for sync jobs planned for future versions of PBS?

If not, would it be possible to request this feature for future releases?

This functionality would be extremely useful for dynamically managing the environment before and after large data sync operations.

Thanks a lot for your help and for the fantastic work on PBS!

Best regards,
Massimo
I have used this workaround:
Since PBS does not support pre- or post-execution hooks for sync jobs, and you cannot delay sync start from inside the GUI, this shell script solves the problem by:

Turning readonly=off on the target ZFS dataset
Manually running the sync job via CLI
Waiting for it to complete
Re-enabling readonly=on to protect the target again

Important:
You must create the sync job from the PBS GUI, but do not schedule it.

This script is meant to be scheduled separately, e.g. via cron or systemd timer

Bash:
#!/bin/bash

# === CONFIGURATION ===
ZFS_DATASET="iscsi_disk_dataset_name"
PBS_SYNC_JOB_ID="sync-job-id"
LOGDIR="/var/log"
LOGFILE="${LOGDIR}/pbs_sync_zfs_$(date +'%Y%m%d_%H%M%S').log"

echo "[INFO] $(date) - Setting readonly=off on ZFS dataset ${ZFS_DATASET}" | tee -a "$LOGFILE"
zfs set readonly=off ${ZFS_DATASET}

echo "[INFO] $(date) - Starting PBS sync job with ID: ${PBS_SYNC_JOB_ID}" | tee -a "$LOGFILE"
proxmox-backup-manager sync-job run --id ${PBS_SYNC_JOB_ID} >> "$LOGFILE" 2>&1

if [ $? -eq 0 ]; then
    echo "[INFO] $(date) - Sync job completed successfully" | tee -a "$LOGFILE"
else
    echo "[ERROR] $(date) - Sync job failed" | tee -a "$LOGFILE"
fi

echo "[INFO] $(date) - Setting readonly=on on ZFS dataset ${ZFS_DATASET}" | tee -a "$LOGFILE"
zfs set readonly=on ${ZFS_DATASET}

echo "[INFO] $(date) - Script execution finished" | tee -a "$LOGFILE"