From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id E02B161A21
 for <pve-devel@lists.proxmox.com>; Tue, 18 Jan 2022 09:21:23 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id D681122A54
 for <pve-devel@lists.proxmox.com>; Tue, 18 Jan 2022 09:21:23 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 9DF9622A46
 for <pve-devel@lists.proxmox.com>; Tue, 18 Jan 2022 09:21:22 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 698A045250
 for <pve-devel@lists.proxmox.com>; Tue, 18 Jan 2022 09:21:22 +0100 (CET)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 18 Jan 2022 09:21:14 +0100
Message-Id: <20220118082114.17978-1-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.135 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [vzdump-hook-script.pl, vzdump.pm]
Subject: [pve-devel] [PATCH v3 manager] close #3476: vzdump: add job-init
 hook
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 18 Jan 2022 08:21:23 -0000

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>
Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Acked-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v2:
    * Fix wording in comment.
    * More complete example commands in dummy hook script.

 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..65867325 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 possible 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..4d530cef 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("wakeonlan AA:BB:CC:DD:EE:FF");
+	#sleep(30);
+	#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