[pve-devel] [PATCH pve-docs v3 1/1] examples: add pre/post/failed-snapshot hooks to example hookscript

Stefan Hanreich s.hanreich at proxmox.com
Mon Jan 23 16:58:46 CET 2023


Added a section for each new snapshot hook to the example hookscript,
as well as a short comment explaining when the respective section gets
executed. Additionally added documentation for the different possible
values of the envvar PVE_SNAPSHOT_PHASE.

Signed-off-by: Stefan Hanreich <s.hanreich at proxmox.com>
---
 examples/guest-example-hookscript.pl | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/examples/guest-example-hookscript.pl b/examples/guest-example-hookscript.pl
index adeed59..51c1d61 100755
--- a/examples/guest-example-hookscript.pl
+++ b/examples/guest-example-hookscript.pl
@@ -54,6 +54,32 @@ if ($phase eq 'pre-start') {
 
     print "$vmid stopped. Doing cleanup.\n";
 
+} elsif ($phase eq 'pre-snapshot') {
+
+    # Phase 'pre-snapshot' will be executed before taking a snapshot of
+    # the guest (via UI or CLI)
+
+    print "$vmid will be snapshotted.\n";
+
+} elsif ($phase eq 'post-snapshot') {
+
+    # Phase 'post-snapshot' will be executed after taking a snapshot of
+    # the guest (via UI or CLI)
+
+    print "$vmid has been successfully snapshotted.\n";
+
+} elsif ($phase eq 'failed-snapshot') {
+
+    # Phase 'failed-snapshot' will be executed when taking a snapshot of
+    # the guest fails and 'pre-snapshot' already ran (via UI or CLI)
+    # Envvar PVE_SNAPSHOT_PHASE can be one of the following:
+    # - pre-snapshot (when pre-snapshot hook failed)
+    # - prepare (when preparation step failed)
+    # - snapshot (when snapshotting the disks failed)
+    # - post-snapshot (when post-snapshot hook failed)
+
+    print "$vmid snapshot failed in phase $ENV{PVE_SNAPSHOT_PHASE}.\n";
+
 } else {
     die "got unknown phase '$phase'\n";
 }
-- 
2.30.2





More information about the pve-devel mailing list