]> git.proxmox.com Git - pve-manager.git/commitdiff
partially close #438: vzdump: support setting notes-template
authorFabian Ebner <f.ebner@proxmox.com>
Wed, 27 Apr 2022 15:41:10 +0000 (17:41 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 28 Apr 2022 11:45:53 +0000 (13:45 +0200)
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/VZDump.pm

index de29ca60022637e9293a614b9e44988c39c5a2c1..5f78746dbf3bd7a70da46f3bbef0f773767e9baf 100644 (file)
@@ -70,6 +70,29 @@ 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 $unescape = {
+       '\\\\' => '\\', # replace \\ by \
+       '\n' => "\n", # turn literal \n into real newline
+    };
+
+    $notes_template =~ s/(\Q\\\E|\Q\n\E)/$unescape->{$1}/g;
+
+    my $vars = join('|', keys $info->%*);
+    $notes_template =~ s/\{\{($vars)\}\}/\Q$info->{$1}\E/g;
+
+    return $notes_template;
+};
+
 my $parse_prune_backups_maxfiles = sub {
     my ($param, $kind) = @_;
 
@@ -1017,6 +1040,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) };