Snippet pre-start runs during backup

Elliott Partridge

Well-Known Member
Oct 7, 2018
56
11
48
I have a VM that has a snippet configured with pre-start and post-stop actions. The VM is currently stopped. When my backup job runs (which includes all VMs & containers), the pre-start action in the snippet is executed. Is this intentional? How do I distinguish between pre-start due to backup vs actually starting the VM/container?

Code:
INFO: Starting Backup of VM 104 (qemu)
INFO: Backup started at 2021-04-06 22:13:45
INFO: status = stopped
INFO: backup mode: stop
INFO: ionice priority: 7
INFO: VM Name: pbs1-vm
INFO: include disk 'scsi0' 'vm-prod:vm-104-disk-0' 8G
INFO: creating vzdump archive '/var/lib/vz/dump/vzdump-qemu-104-2021_04_06-22_13_45.vma.zst'
INFO: starting kvm to execute backup task
ZPOOL MOUNT HOOK: 104 pre-start
104 is starting, mounting zpool 'backup'.
cannot export 'backup': pool is busy
cannot import 'backup': a pool with that name already exists
use the form 'zpool import <pool | id> <newpool>' to give it a new name
zpool import failed with error: 256
ERROR: Backup of VM 104 failed - hookscript error for 104 on pre-start: command '/var/lib/vz/snippets/backup-hook.pl 104 pre-start' failed: exit code 1
INFO: Failed at 2021-04-06 22:13:47

Some background on this particular job - I ran Proxmox Backup Server in a VM, then decided to try it in LXC. The snippet imports the backup pool on pre-start, then exports it on post-stop (allowing for hot-swap of backup drives). The snippet fails while backing up the deprecated, stopped VM in this case because the pool cannot be exported/imported since the new PBS container is running with a bind mount to it.
 
hi,

How do I distinguish between pre-start due to backup vs actually starting the VM/container?

with your hookscript like this:

Code:
#!/usr/bin/perl

use strict;
use warnings;

use PVE::QemuConfig;

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

my $vmid = shift;

my $conf = PVE::QemuConfig->load_config($vmid);

my $phase = shift;

if ($phase eq 'pre-start') {
    print "doing preparations for $vmid\n";
    if ($conf->{lock} eq 'backup') {
            print "this is a backup!\n";
    } else {
            print "this isn't a backup, normal start!\n"
    }
}
 
  • Like
Reactions: Elliott Partridge
hi,



with your hookscript like this:

Code:
#!/usr/bin/perl

use strict;
use warnings;

use PVE::QemuConfig;

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

my $vmid = shift;

my $conf = PVE::QemuConfig->load_config($vmid);

my $phase = shift;

if ($phase eq 'pre-start') {
    print "doing preparations for $vmid\n";
    if ($conf->{lock} eq 'backup') {
            print "this is a backup!\n";
    } else {
            print "this isn't a backup, normal start!\n"
    }
}
Thanks for that, works great! How would I adapt the script to handle both LXC and VMs? I have used this script on both. I see the equivalent perl module under /usr/share/perl5/PVE/LXC/Config.pm, but not sure how to check which one to use based on $vmid.
 
Nevermind, I found an example of how to determine VM/LXC type in API2/BackupInfo.pm:

Code:
my $vmlist = PVE::Cluster::get_vmlist();
my $type = $vmlist->{ids}->{$vmid}->{type};
my $node = $vmlist->{ids}->{$vmid}->{node};

my $conf;
my $name = "";

if ($type eq 'qemu') {
    $conf = PVE::QemuConfig->load_config($vmid, $node);
    $name = $conf->{name};
} elsif ($type eq 'lxc') {
    $conf = PVE::LXC::Config->load_config($vmid, $node);
    $name = $conf->{hostname};
} else {
    die "VMID $vmid is neither Qemu nor LXC guest\n";
}
 
Last edited:

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!