I thought I'd share this and hopefully receive feedback or... maybe others exploring the same will find this thread.
You can set the backup hook script in the vzdump config. Consult the documentation on same.
For testing you can swap the comments for the variables:
SHUTDOWN_COMMAND
and
UMOUNT_COMMAND
My own feedback is: It could be a little tighter on errors. It can skip a lot of steps if the host happens to be up already.
It could probably take advantage of more PVE API integration.
BUG / ANNOYANCE: Sometimes, even though the NFS share is synced, disabled and unmounted, PVE tries to access it and causes all hell to break loose. This may be caused by me re-enabling the storage to make a change.
Feature Request: Allow edits of backup jobs which target currently disabled storage. Not "create", but "edit" of existing ones.
You can set the backup hook script in the vzdump config. Consult the documentation on same.
For testing you can swap the comments for the variables:
SHUTDOWN_COMMAND
and
UMOUNT_COMMAND
My own feedback is: It could be a little tighter on errors. It can skip a lot of steps if the host happens to be up already.
It could probably take advantage of more PVE API integration.
BUG / ANNOYANCE: Sometimes, even though the NFS share is synced, disabled and unmounted, PVE tries to access it and causes all hell to break loose. This may be caused by me re-enabling the storage to make a change.
Feature Request: Allow edits of backup jobs which target currently disabled storage. Not "create", but "edit" of existing ones.
Bash:
#!/bin/bash
phase=$1
STORAGE_TARGET="remote-backups"
STORAGE_NFS_MNT="/mnt/pve/remote-backups"
NFS_HOST="backups"
REMOTE_NFS_NAME="/backup-zpool/pve/dump"
MAC_FOR_WOL="98:xx:xx:c1:36:xx"
ATTEMPTS_BEFORE_TIMEOUT=30
ATTEMPTS_DELAY_SECONDS=5
#SHUTDOWN_COMMAND="echo DISABLED: ssh root@backups shutdown -h now"
SHUTDOWN_COMMAND="ssh root@backups shutdown -h now"
#UMOUNT_COMMAND="echo umount"
UMOUNT_COMMAND="umount"
if [ "$phase " == " " ]
then
echo "No phase provided"
exit 1;
fi
if [ "$phase " == "job-init " ] && [ "$STOREID " == "${STORAGE_TARGET} " ]
then
echo "job-init phase waking ${NFS_HOST} if necessary"
ping -c 1 ${NFS_HOST}
avail=$?
if [ ${avail} -eq 0 ]
then
echo "NFS Host ${NFS_HOST} already awake."
else
t_out=${ATTEMPTS_BEFORE_TIMEOUT}
while [ $avail -ne 0 ] && [ $t_out -ne 0 ]
do
t_out=$(( $t_out - 1 ))
wakeonlan ${MAC_FOR_WOL}
sleep ${ATTEMPTS_DELAY_SECONDS}
ping -c 1 ${NFS_HOST}
avail=$?
done
if [ $t_out -eq 1 ]
then
echo "Could not wake the ${NFS_HOST} NFS machine."
exit 2;
fi
fi
pvesm scan nfs ${NFS_HOST} | grep ${REMOTE_NFS_NAME}
avail=$?
t_out=${ATTEMPTS_BEFORE_TIMEOUT}
while [ $avail -ne 0 ] && [ $t_out -ne 0 ]
do
t_out=$(( $t_out - 1 ))
sleep ${ATTEMPTS_DELAY_SECONDS}
pvesm scan nfs ${NFS_HOST} | grep ${REMOTE_NFS_NAME}
avail=$?
done
if [ $t_out -eq 0 ]
then
echo "Could not find the storage export ${REMOTE_NFS_NAME} on host ${NFS_HOST}"
exit 2;
fi
avail=1
t_out=${ATTEMPTS_BEFORE_TIMEOUT}
while [ $avail -ne 0 ] && [ $t_out -ne 0 ]
do
t_out=$(( $t_out - 1 ))
pvesm set ${STORAGE_TARGET} --disable false
sleep ${ATTEMPTS_DELAY_SECONDS}
mount | grep ${STORAGE_NFS_MNT}
avail=$?
done
if [ $t_out -eq 0 ]
then
echo "Could not mount the ${STORAGE_TARGET} share."
exit 2;
fi
exit 0
fi
if [ "$phase " == "job-end " ] || [ "$phase " == "job-abort " ]
then
if [ "$STOREID " == "${STORAGE_TARGET} " ]
then
echo "$phase phase syncing disks"
sync
echo "disabling storage $STORAGE_TARGET}"
pvesm set ${STORAGE_TARGET} --disable true
echo "Unmounting ${STORAGE_NFS_MNT} in case pvesm didnt"
umount ${STORAGE_NFS_MNT}
${SHUTDOWN_COMMAND}
exit 0;
fi
fi
echo "Phase: $phase - no action"
Last edited: