Shut down Server after backup

Hi, there are several ways to do this, depends on how clever and complex you want the script to be.

I'll give you the way that I set it up. I just wanted it to be straight forward, therefor excepting that it is not an intelligent script that monitors the end time of a backup job f.e.

Knowing how long my maximum backup time would be (including new dirty bitmaps, so full backup) I set a cron script in my PBS at a specified time to shut it down.

PATH="/usr/sbin:/usr/bin:/sbin:/bin"

# shutdown PBS daily at 6:15
15 06 * * * root shutdown -h now > /dev/null

Additionally for PVE:
While your PBS is down, PVE wil generate a lot of error messages, because the pbs storage isn't available for PVE.
So I set up a cron script in PVE that enables the pbs storage just before the backup starts, and disables just before pbs is shutdown
I also have wakeonlan package installed (etherwake is also possible) to wakeup PBS from PVE.
And at the end because my PBS uses ZFS, I wake up PBS for the preconfigured cron job for ZFS scrubbing every month.

PATH="/usr/sbin:/usr/bin:/sbin:/bin"
# mac from PBS host
PBSHOSTMAC="xx:xx:xx:xx:xx:xx"

# wake up pbs host at 02:50 every day
50 02 * * * root wakeonlan $PBSHOSTMAC > /dev/null

# enable backup storage, every day at 02:55
55 02 * * * root pvesm set <your-pbs-storage> --disable 0

# disable backup storage, every day, at 06:00, even if manually enabled that day
00 06 * * * root pvesm set <your-pbs-storage> --disable 1

# wake up pbs server for ZFS scrub and GC task, every second sunday of the month, at 00:10
10 00 8-14 * * root [ $(date +\%w) -eq 0 ] && wakeonlan $PBSHOSTMAC > /dev/null

The scripts can be placed on the corresponding hosts in /etc/cron.d/
These scripts are of course examples to get you started, you have to adjust values to your own preferences and maintenance windows.
 
Last edited:
Hi, there are several ways to do this, depends on how clever and complex you want the script to be.

I'll give you the way that I set it up. I just wanted it to be straight forward, therefor excepting that it is not an intelligent script that monitors the end time of a backup job f.e.

Knowing how long my maximum backup time would be (including new dirty bitmaps, so full backup) I set a cron script in my PBS at a specified time to shut it down.

PATH="/usr/sbin:/usr/bin:/sbin:/bin"

# shutdown PBS daily at 6:15
15 06 * * * root shutdown -h now > /dev/null

Additionally for PVE:
While your PBS is down, PVE wil generate a lot of error messages, because the pbs storage isn't available for PVE.
So I set up a cron script in PVE that enables the pbs storage just before the backup starts, and disables just before pbs is shutdown
I also have wakeonlan package installed (etherwake is also possible) to wakeup PBS from PVE.
And at the end because my PBS uses ZFS, I wake up PBS for the preconfigured cron job for ZFS scrubbing every month.

PATH="/usr/sbin:/usr/bin:/sbin:/bin"
# mac from PBS host
PBSHOSTMAC="xx:xx:xx:xx:xx:xx"

# wake up pbs host at 02:50 every day
50 02 * * * root wakeonlan $PBSHOSTMAC > /dev/null

# enable backup storage, every day at 02:55
55 02 * * * root pvesm set <your-pbs-storage> --disable 0

# disable backup storage, every day, at 06:00, even if manually enabled that day
00 06 * * * root pvesm set <your-pbs-storage> --disable 1

# wake up pbs server for ZFS scrub and GC task, every second sunday of the month, at 00:10
10 00 8-14 * * root [ $(date +\%w) -eq 0 ] && wakeonlan $PBSHOSTMAC > /dev/null

The scripts can be placed on the corresponding hosts in /etc/cron.d/
These scripts are of course examples to get you started, you have to adjust values to your own preferences and maintenance windows.
Thanks.
 

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!