public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-docs v3 1/1] examples: add pre/post/failed-snapshot hooks to example hookscript
Date: Mon, 23 Jan 2023 16:58:46 +0100	[thread overview]
Message-ID: <20230123155847.598536-2-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20230123155847.598536-1-s.hanreich@proxmox.com>

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@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




  reply	other threads:[~2023-01-23 15:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23 15:58 [pve-devel] [PATCH-SERIES guest-common/docs v3] add pre/post/failed snapshot hooks Stefan Hanreich
2023-01-23 15:58 ` Stefan Hanreich [this message]
2023-01-23 15:58 ` [pve-devel] [PATCH pve-guest-common v3 1/1] partial fix #2530: snapshots: add pre/post/failed-snapshot hooks Stefan Hanreich
2023-01-23 16:07 ` [pve-devel] [PATCH-SERIES guest-common/docs v3] add pre/post/failed snapshot hooks Stefan Hanreich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230123155847.598536-2-s.hanreich@proxmox.com \
    --to=s.hanreich@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal