vm rollback in hookscript

bingsin

Member
Dec 9, 2021
29
2
8
30
Hello,
I want to auto rollback when vm is stop. the same as PXE.
use hookscript:

Perl:
my $cmd ="qm rollback $vmid snapshot";
......
.......
elsif($phase eq 'post-stop') {
  print "$vmid stopped. Doing cleanup.\n";
  system($cmd);

Both tasks will lock the vm at the same time,and post error
Bash:
GUEST HOOK: 801 pre-stop
801 will be stopped.
trying to acquire lock...
can't lock file '/var/lock/qemu-server/lock-801.conf' - got timeout
 
i did it!
use qemu-img
Code:
my $cmd ="qemu-img snapshot -a snapshot /mnt/pve/Nvme/images/$vmid/vm-$vmid-disk-0.qcow2";
...
...
elsif($phase eq 'post-stop') {
  print "$vmid stopped. Doing cleanup.\n";
  system("$cmd");
 
system("unlink /var/lock/qemu-server/lock-$vmid.conf");
Hello,
I want to auto rollback when vm is stop. the same as PXE.
use hookscript:

Perl:
my $cmd ="qm rollback $vmid snapshot";
......
.......
elsif($phase eq 'post-stop') {
  print "$vmid stopped. Doing cleanup.\n";
  system($cmd);

Both tasks will lock the vm at the same time,and post error
Bash:
GUEST HOOK: 801 pre-stop
801 will be stopped.
trying to acquire lock...
can't lock file '/var/lock/qemu-server/lock-801.conf' - got timeout