Rollback to snapshot on pre-start

Mar 1, 2018
22
1
43
I want a qemu vm to rollback to a snapshot named "default" on pre-start.
The vm only holds static data and can therefore be easily recovered if somebody screws up something by booting. If I want to make a persistent change, I would just have to delete the snapshot, do the changes and create it again.

I have created a hook script which does the following on pre-start:
Perl:
if (/* condition */) {
        print "Start rollback to default ...\n\n";
        system("/usr/sbin/qm rollback $vmid default");
        print "Finished rollback to default.\n";
    }
    else {
        print "Snapshot default not present. Skipping ...\n";
    }

Unfortunately, this does not work. On start, I get the following message in the logs:

GUEST HOOK: 203 pre-start
203 is starting, doing preparations.
Restoring Snapshot default, if present
Start rollback to default ...

trying to acquire lock...
can't lock file '/var/lock/qemu-server/lock-203.conf' - got timeout
Finished rollback to default.
GUEST HOOK: 203 post-start
1301 started successfully.
TASK OK

Obviously, the VM is already locked in the pre-start phase so that I cannot do the restore in the hook script. Is there any other way to accomplish what I want?
 
I want a qemu vm to rollback to a snapshot named "default" on pre-start.
The vm only holds static data and can therefore be easily recovered if somebody screws up something by booting. If I want to make a persistent change, I would just have to delete the snapshot, do the changes and create it again.

I have created a hook script which does the following on pre-start:
Perl:
if (/* condition */) {
        print "Start rollback to default ...\n\n";
        system("/usr/sbin/qm rollback $vmid default");
        print "Finished rollback to default.\n";
    }
    else {
        print "Snapshot default not present. Skipping ...\n";
    }

Unfortunately, this does not work. On start, I get the following message in the logs:



Obviously, the VM is already locked in the pre-start phase so that I cannot do the restore in the hook script. Is there any other way to accomplish what I want?

Why not simply making a shell script as follows:

Code:
#!/bin/bash
qm rollback default $1
qm start $1