all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Shannon Sterz <s.sterz@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH docs 21/21] examples: add example hook script for host backup jobs
Date: Fri, 28 Aug 2026 15:30:30 +0200	[thread overview]
Message-ID: <20260828133030.351140-22-s.sterz@proxmox.com> (raw)
In-Reply-To: <20260828133030.351140-1-s.sterz@proxmox.com>

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
 Makefile                                   |  1 +
 examples/host-backup-example-hookscript.pl | 90 ++++++++++++++++++++++
 2 files changed, 91 insertions(+)
 create mode 100755 examples/host-backup-example-hookscript.pl

diff --git a/Makefile b/Makefile
index db07f2e..13ddb73 100644
--- a/Makefile
+++ b/Makefile
@@ -218,6 +218,7 @@ doc-install: index.html $(WIKI_IMPORTS) $(API_VIEWER_SOURCES) verify-images exam
 	install -dm755 $(DESTDIR)/usr/share/doc/$(DOC_PACKAGE)
 	install -dm755 $(DESTDIR)/usr/share/$(DOC_PACKAGE)/examples/
 	install -m 755 examples/guest-example-hookscript.pl $(DESTDIR)/usr/share/$(DOC_PACKAGE)/examples/
+	install -m 755 examples/host-backup-example-hookscript.pl $(DESTDIR)/usr/share/$(DOC_PACKAGE)/examples/
 	install -m 0644 index.html $(INDEX_INCLUDES) $(DESTDIR)/usr/share/$(DOC_PACKAGE)
 	install -m 0644 $(WIKI_IMPORTS) $(DESTDIR)/usr/share/$(DOC_PACKAGE)
 	# install images
diff --git a/examples/host-backup-example-hookscript.pl b/examples/host-backup-example-hookscript.pl
new file mode 100755
index 0000000..9791814
--- /dev/null
+++ b/examples/host-backup-example-hookscript.pl
@@ -0,0 +1,90 @@
+#!/usr/bin/perl
+
+# Example host backup hook script. Currently these need to be added
+# manually to a host backup job (or as an API parameter to a one off
+# host backup).
+
+use v5.36;
+
+# First argument is the backup phase.
+
+my $phase = shift;
+
+# A payload is provided via `stdin` as JSON encoded. This will only
+# exist for certain stages. Parameters may be added to the payload
+# over time. Make sure a hook script can handle additional fields,
+# for better compatibility.
+
+my @input = <STDIN>;
+my $payload = join('\n', @input);
+
+if ($phase eq 'job-start') {
+
+    # A backup was started. Other than validating the parameters of
+    # the job, nothing has been done yet.
+
+    # This stage has no payload:
+    die "Unknown payload: '$payload'\n" if $payload ne '';
+
+    # If the script returns only a valid JSON string that contains an
+    # object with a single string member called `base-path`, that
+    # string will be used as the base path of the backup. It needs to
+    # point to a directory.
+    #
+    # The default depends on the root file system. On XFS and ext-4
+    # it is simply `/`. On ZFS and BTRFS it will be a path to a
+    # mounted snapshot of the root file system.
+    #
+    # This can be useful if the root file system supports extra
+    # consistency methods (such as, snapshot support), but the
+    # default backup mechanism cannot use it. For example, because
+    # the file system is not supported by Proxmox VE by default or
+    # taking snapshots comes with an overhead that needs to be
+    # evaluated by the operator.
+    print '{ "base-path": "/path/to/base/path" }';
+
+} elsif ($phase eq 'backup-start') {
+
+    # A backup has been prepared, but nothing has been backed up yet.
+
+    # This stage has a payload that contains the name of the backup
+    # and the backup target. The target is a directory that should
+    # contain all files that should be included in the backup. It
+    # should be created but empty in this phase.
+    #
+    # The payload should be structured as following:
+    # ```js
+    # {
+    #   "backup-name": "host-backup-1234567",
+    #   "backup-target": "/path/to/tmp/backup/dir"
+    # }
+    # ```
+    die "Paylod was undefined.\n" if !defined($payload);
+
+    # Nothing can be communicated back to the job at this stage.
+
+} elsif ($phase eq 'backup-end') {
+
+    # The backup has been completed and uploaded at this stage.
+
+    # A payload should be provided, it will be identical to the
+    # previous stage's payload.
+    die "Paylod was undefined.\n" if !defined($payload);
+
+    # Nothing can be communicated back to the job at this stage.
+
+} elsif ($phase eq 'job-end') {
+
+    # The back up job has completed including cleaning up any
+    # snapshots or temporary files.
+
+    # This stage receives no payload.
+    die "Unknown payload: '$payload'\n" if $payload ne '';
+
+    # Nothing can be communicated back to the job at this stage.
+
+} else {
+    die "Got unknown phase: '$phase'\n";
+}
+
+exit(0);
-- 
2.47.3





      parent reply	other threads:[~2026-08-28 13:33 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 13:30 [RFC cluster/common/container/docs/installer/manager 00/21] add rudimentary host backup mechanism Shannon Sterz
2026-08-28 13:30 ` [PATCH cluster 01/21] pmxcfs: status: fix formatting of parameters in checked_mkdir() Shannon Sterz
2026-08-28 13:30 ` [PATCH cluster 02/21] pmxcfs: correctly log message when directory can't be created Shannon Sterz
2026-08-28 13:30 ` [PATCH cluster 03/21] pmxcfs: add live backup capability Shannon Sterz
2026-08-28 13:30 ` [PATCH cluster 04/21] pmxcfs: add ability to query backup progress Shannon Sterz
2026-08-28 13:30 ` [PATCH common 05/21] systemd: move parse_os_release() helper to PVE::Systemd Shannon Sterz
2026-08-28 13:30 ` [PATCH container 06/21] setup: use parse_os_release from PVE::Systemd Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 07/21] jobs/api: add basic host backup job logic Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 08/21] api: cluster: add endpoints for manage host backup jobs Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 09/21] api: node: add endpoints for listing backups for a node Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 10/21] api: host backup: include global, disk and network options for restore Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 11/21] api: host backup: add warnings in case zfs snapdir is disabled Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 12/21] ui: node: add panel to manage backups of a host Shannon Sterz
2026-08-28 13:30 ` [PATCH manager 13/21] ui: dc: add panel for managing host backup jobs Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 14/21] bump proxmox-installer-types to 0.2 Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 15/21] make tidy and clean up whitespace in unconfigured.sh Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 16/21] installer-common: add option to verify TLS connections via callback Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 17/21] low-level-installer: add support for restoring backups Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 18/21] installer-common/tui-installer: implement restore tui Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 19/21] unconfigured: add restore mode to unconfigured.sh Shannon Sterz
2026-08-28 13:30 ` [PATCH installer 20/21] tui-installer: unmount a potentially mounted backup on abort Shannon Sterz
2026-08-28 13:30 ` Shannon Sterz [this message]

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=20260828133030.351140-22-s.sterz@proxmox.com \
    --to=s.sterz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal