How to create Backup Notes template via cli/api?

pve-Joseph

Member
Oct 21, 2019
10
0
21
37
The title pretty much says it all, I'm trying to determine if proxmox provides the capability to create your own custom "backup notes" templates, either via the cli or api since I'm not able to find this feature in the ui.

I should clarify that when I say template, I mean a pre-defined/reusable template that I select from a dropdown or set as the default instead of having to define my template "structure" on demand for every backup operation.

Thanks for any help or suggestions.
 
Last edited:
Hi,
the default notes template can be set in /etc/vzdump.conf on each node, just like other vzdump defaults. It is also re-used for jobs that don't define their own template. E.g.
Code:
root@pve701 ~ # cat /etc/vzdump.conf
# vzdump default settings

#tmpdir: DIR
...
#pigz: N
notes-template: custom template\nwith {{cluster}} and {{guestname}}
 
Hi,

Thanks for the reply, I was able to update the template. However, do have any idea of how to format the template with newlines??

I tried your above example with the "\n" character but that didn't work. It reads the raw string without any interpretation or processing besides the template variables.
 
It should replace \n by an actual newline. Can you share the template as it is in the config? What's your pveversion -v?
 
Hi Fabian,

This is the template I entered in the vzdump.conf:

Guest Name: {{guestname}}\nProxmox Node: {{node}}\nVM Id: {{vmid}}

and below is the output in the *.notes file upon backup:

Guest Name: WHVDI01D\nProxmox Node: pvehpe08\nVM Id: 301

My full vzdump.conf for reference:

Bash:
GNU nano 5.4                       /etc/vzdump.conf                             
# vzdump default settings

#tmpdir: DIR
#dumpdir: DIR
#storage: STORAGE_ID
#mode: snapshot|suspend|stop
#bwlimit: KBPS
#ionice: PRI
#lockwait: MINUTES
#stopwait: MINUTES
#stdexcludes: BOOLEAN
#mailto: ADDRESSLIST
#prune-backups: keep-INTERVAL=N[,...]
#script: FILENAME
#exclude-path: PATHLIST
#pigz: N
notes-template: Guest Name: {{guestname}}\nProxmox Node: {{node}}\nVM Id: {{vmid}}
 
Last edited:
Very strange, it works here with your template. Could you open /usr/share/perl5/PVE/VZDump.pm, look for the line
Code:
my $generate_notes = sub {
and share the following lines here, up until
Code:
return $notes_template;
 
Hi Fabian, please find below the code snippet you requested:

Bash:
my $generate_notes = sub {
    my ($notes_template, $task) = @_;

    $verify_notes_template->($notes_template);

    my $info = {
        cluster => PVE::Cluster::get_clinfo()->{cluster}->{name} // 'standalone node',
        guestname => $task->{hostname} // "VM $task->{vmid}", # is always set for CTs
        node => PVE::INotify::nodename(),
        vmid => $task->{vmid},
    };

    my $unescape = sub {
        my ($char) = @_;
        return '\\' if $char eq '\\';
        return "\n" if $char eq 'n';
        die "unexpected escape character '$char'\n";
    };

    $notes_template =~ s/\\(.)/$unescape->($1)/eg;

    my $vars = join('|', keys $info->%*);
    $notes_template =~ s/\{\{($vars)\}\}/$info->{$1}/g;

    return $notes_template;
};
 
That is correct. Does it work if you pass the parameter to vzdump manually? E.g.
Code:
vzdump 123 --storage backupstore --notes-template 'Guest Name: {{guestname}}\nProxmox Node: {{node}}\nVM Id: {{vmid}}'

What do you get if you run the following (i.e. create a file test-replace.pl with the contents as below and execute it with perl):
Code:
root@pve701 ~ # cat test-replace.pl 
use strict;
use warnings;

my $notes_template = "Guest Name: {{guestname}}\nProxmox Node: {{node}}\nVM Id: {{vmid}}";

my $unescape = sub {
my ($char) = @_;
return '\\' if $char eq '\\';
return "\n" if $char eq 'n';
die "unexpected escape character '$char'\n";
};

$notes_template =~ s/\\(.)/$unescape->($1)/eg;

print "$notes_template\n";
root@pve701 ~ # perl test-replace.pl
Guest Name: {{guestname}}
Proxmox Node: {{node}}
VM Id: {{vmid}}
 
Hi Fabian,

It looks like we're getting closer to the root of the problem; running vzdump command manually with the relevant parameters yields the expected results.

However, running the backup through the Proxmox Web GUI somehow alters the template (I'm assuming) and causes the replace not to work correctly.

It is worth noting that when initiating the backup through the web gui, the notes template section still shows the newline character and not the processed template as I would expect, is this the normal behavior??

Please see the below screenshot:
1656332178924.png
 
Thanks for the help. I found the issue now and sent a patch. Except for the variables, the UI already shows strings as they will be in the backup. This means you'd need to insert real newlines instead of \n in the UI (with the patch that will happen when the template is loaded from the config).
 
  • Like
Reactions: ahayes
Awesome, glad to hear. I look forward to the patch and will report back. Thanks again.
 
Last edited:
@fabian , Just following-up to confirm that this has been resolved with the patch in update for pve-manager 7.2-6. Thanks again for the help.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!