[pve-devel] [PATCH v2 manager 5/8] partially close #438: vzdump: support setting notes-template

Fabian Ebner f.ebner at proxmox.com
Tue Mar 29 14:53:21 CEST 2022


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

Changes from v1:
    * Split into its own patch.
    * Expand certain variables in the text.

Arguably, a warning from failing to set notes is not very visible, but
I didn't want to make it a full-blown error.

 PVE/VZDump.pm | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index eab4f240..ec0f638d 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -70,6 +70,22 @@ sub run_command {
     PVE::Tools::run_command($cmdstr, %param, logfunc => $logfunc);
 }
 
+my $generate_notes = sub {
+    my ($notes_template, $task) = @_;
+
+    my $info = {
+	CLUSTER => PVE::Cluster::get_clinfo()->{cluster}->{name},
+	GUESTNAME => $task->{hostname},
+	NODE => PVE::INotify::nodename(),
+	VMID => $task->{vmid},
+    };
+
+    my $vars = join('|', keys $info->%*);
+    $notes_template =~ s/\$($vars)([^A-Za-z0-9_]|$)/\Q$info->{$1}\E$2/g;
+
+    return $notes_template;
+};
+
 my $parse_prune_backups_maxfiles = sub {
     my ($param, $kind) = @_;
 
@@ -1012,6 +1028,13 @@ sub exec_backup_task {
 	    my $volname = $opts->{pbs} ? $task->{target} : basename($task->{target});
 	    my $volid = "${storeid}:backup/${volname}";
 
+	    if ($opts->{'notes-template'} && $opts->{'notes-template'} ne '') {
+		debugmsg('info', "adding notes to backup", $logfd);
+		my $notes = $generate_notes->($opts->{'notes-template'}, $task);
+		eval { PVE::Storage::update_volume_attribute($cfg, $volid, 'notes', $notes) };
+		debugmsg('warn', "unable to add notes - $@", $logfd) if $@;
+	    }
+
 	    if ($opts->{protected}) {
 		debugmsg('info', "marking backup as protected", $logfd);
 		eval { PVE::Storage::update_volume_attribute($cfg, $volid, 'protected', 1) };
-- 
2.30.2






More information about the pve-devel mailing list