Hook Script to disable pbs storage

FiskerK

New Member
May 29, 2024
8
0
1
Good day

I have pbs vm for all my backups, the pbs syncs these to an offsite pbs for long term storage.

my problem is that proxmox hangs on shutdown, due to the pbs storage location being offline.
I have seen I can use hook scripts to perform actions depending on vm status, and I have seen other use sripts to unmount nfs storage location, but I don't know how to trigger the pbs storage type.
 
pbs storage isnt like NFS; if its not present it will not hang your host. I would investigate your logs a bit more carefully to see what the actual culprit is- perhaps you have other items in /etc/fstab and/or /etc/pve/storage.cfg?
 
you can use this command for enable: "pvesm set pbs -disable 0" or "pvesm set pbs -disable 1" to disable
where pbs is your storage name
 
Last edited:
I did two tests one where i didn't disable the pbs storage and one where i did disable it.
the log I post here is without disabling the storage location and I ended having to force shutdown the server.

in the test with the pbs storage disabled, the server shut down without problems.
 

Attachments

you can use this command for enable: "pvesm set pbs -disable 0" or "pvesm set pbs -disable 1" to disable
where pbs is your storage name
i tried to create a hook script with with these commands but it doesn't work can you help figure out what needs to be change to make it work.
I have tried inputting the two commands you ponted out and comment out the rest, but I have no experience with perl.

Perl:
#!/usr/bin/perl

 
#!/usr/bin/perl

# Example hook script for PVE guests (hookscript config option)
# You can set this via pct/qm with
# pct set <vmid> --hookscript <volume-id>
# qm set <vmid> --hookscript <volume-id>
# where <volume-id> has to be an executable file in the snippets folder
# of any storage with directories e.g.:
# qm set 100 --hookscript local:snippets/hookscript.pl

# enable: "pvesm set pbs -disable 0" or "pvesm set pbs -disable 1" to disable

use strict;
use warnings;

print "GUEST HOOK: " . join(' ', @ARGV). "\n";

# First argument is the vmid

my $vmid = shift;

# Second argument is the phase

my $phase = shift;

if ($phase eq 'pre-start') {

    # First phase 'pre-start' will be executed before the guest
    # is started. Exiting with a code != 0 will abort the start

    # print "$vmid is starting, doing preparations.\n";

    # print "preparations failed, aborting."
    # exit(1);

} elsif ($phase eq 'post-start') {

    # Second phase 'post-start' will be executed after the guest
    # successfully started.
    pvesm set pbs -disable 0 
    # print "$vmid started successfully.\n";

} elsif ($phase eq 'pre-stop') {

    # Third phase 'pre-stop' will be executed before stopping the guest
    # via the API. Will not be executed if the guest is stopped from
    # within e.g., with a 'poweroff'
    pvesm set pbs -disable 1
    # print "$vmid will be stopped.\n";

} elsif ($phase eq 'post-stop') {

    # Last phase 'post-stop' will be executed after the guest stopped.
    # This should even be executed in case the guest crashes or stopped
    # unexpectedly.

    # print "$vmid stopped. Doing cleanup.\n";

} else {
    die "got unknown phase '$phase'\n";
}

exit(0);
root@pve:~#
 
Last edited:
when start your backup?
you can write a script to start your vm and then enable your pbs in a cron job before your backup job is starting
and to disable the pbs after the backup is finished when the vm is not more running maybe with another script
 
Last edited:
i tried to create a hook script
Firstly, you probably want that command in the post-stop stage.

Secondly what is the storage name you used for pbs. Maybe show your cat /etc/pve/storage.cfg output for that.

Also realize; the hook script will only activate due to VM activity (on or off). So you may want to ensure that by default the pbs storage is not active.
 
The backup process runs in the evening from 21:00 to 01:00 this is the local backup and sending it to the offsite location.
The PBS storage is just called pbs.
My thought process was that the pbs storage was always available while the pbs VM was running, so the storage location is activated after the vm is online and deactivated before the vm goes offline, in case proxmox needs to shut down
 
Not sure how you have responded to my above recommendation/s.

How does your PBS VM turn on at night to carry out the evening backup? How then does it shutdown after the backup is completed?
 
Not sure how you have responded to my above recommendation/s.

How does your PBS VM turn on at night to carry out the evening backup? How then does it shutdown after the backup is completed?
Ah now I understand the question, the vm is currently only starting and stopping in case proxmox needs to start and stop. But I guess this is a waste of resources, I guess I could make a script to start and stop it before and after the backups are run.
In short the pbs has until now just always been online and I have recently found out that this is what caused proxmox to hang on shutdown
 
I have two host installed with Proxmox PVE then created vms (Data Center Manager), I add the 2 Host in the DC Manager, so i want to have an existing storage Unity XT now want the host to access this storage and mapped the LUNS to the host, so i am unable to Map because no Initiator Path visible