public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 manager 2/2] close #3476: vzdump: add job-init hook
Date: Mon, 17 Jan 2022 12:35:59 +0100	[thread overview]
Message-ID: <20220117113559.77636-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20220117113559.77636-1-f.ebner@proxmox.com>

which allows users to prepare the backup storage for activation (e.g.
by waking up a remote node).

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v1:
    * Different approach: add a new hook rather than trying to re-use
      job-start.
    * Add example to the example hook script to clarify when job-init
      should/can be used.

 PVE/VZDump.pm         | 17 ++++++++++++++++-
 vzdump-hook-script.pl | 12 +++++++++++-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index b5a5fadd..e526eef8 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -497,6 +497,13 @@ sub new {
 	$opts->{storage} = 'local';
     }
 
+    $self->{job_init_log} = '';
+    open my $job_init_fd, '>', \$self->{job_init_log};
+    $self->run_hook_script('job-init', undef, $job_init_fd);
+    close $job_init_fd;
+
+    PVE::Cluster::cfs_update(); # Pick up eventual changes made by the hook script.
+
     my $errors = '';
 
     if ($opts->{storage}) {
@@ -1194,7 +1201,15 @@ sub exec_backup {
 
     my $totaltime = time() - $starttime;
 
-    eval { $self->sendmail ($tasklist, $totaltime, undef, $job_start_log, $job_end_log); };
+    eval {
+	$self->sendmail(
+	    $tasklist,
+	    $totaltime,
+	    undef,
+	    $self->{job_init_log} . $job_start_log,
+	    $job_end_log,
+	);
+    };
     debugmsg ('err', $@) if $@;
 
     die $err if $err;
diff --git a/vzdump-hook-script.pl b/vzdump-hook-script.pl
index 60edbc04..81b9b10f 100755
--- a/vzdump-hook-script.pl
+++ b/vzdump-hook-script.pl
@@ -11,11 +11,13 @@ print "HOOK: " . join (' ', @ARGV) . "\n";
 
 my $phase = shift;
 
-if ($phase eq 'job-start' ||
+if ($phase eq 'job-init' ||
+    $phase eq 'job-start' ||
     $phase eq 'job-end'  ||
     $phase eq 'job-abort') {
 
     # undef for Proxmox Backup Server storages
+    # undef in phase 'job-init' except when --dumpdir is used directly
     my $dumpdir = $ENV{DUMPDIR};
 
     # undef when --dumpdir is used directly
@@ -26,6 +28,14 @@ if ($phase eq 'job-start' ||
     print "storeid=$storeid;" if defined($storeid);
     print "\n";
 
+    # example: wake up remote storage node and enable storage
+    if ($phase eq 'job-init') {
+        #system ("") == 0 ||
+        #    die "waking up remote node failed";
+        #system ("/sbin/pvesm set $storeid --disable 0") == 0 ||
+        #    die "enabling storage $storeid failed";
+    }
+
     # do what you want
 
 } elsif ($phase eq 'backup-start' ||
-- 
2.30.2





  reply	other threads:[~2022-01-17 11:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 11:35 [pve-devel] [PATCH v2 manager 1/2] vzdump: example hook script: avoid undef warnings Fabian Ebner
2022-01-17 11:35 ` Fabian Ebner [this message]
2022-01-17 15:37   ` [pve-devel] [PATCH v2 manager 2/2] close #3476: vzdump: add job-init hook Fabian Grünbichler
2022-01-17 15:54     ` Thomas Lamprecht
2022-01-17 15:32 ` [pve-devel] applied: [PATCH v2 manager 1/2] vzdump: example hook script: avoid undef warnings Fabian Grünbichler

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=20220117113559.77636-2-f.ebner@proxmox.com \
    --to=f.ebner@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