* [pve-devel] [PATCH v4 manager 1/7] partially close #438: vzdump: support setting notes-template
2022-04-27 15:41 [pve-devel] [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump Fabian Ebner
@ 2022-04-27 15:41 ` Fabian Ebner
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 2/7] ui: util: add helpers for (un)escaping notes-template Fabian Ebner
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Fabian Ebner @ 2022-04-27 15:41 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
Changes from v3:
* also escape \\ and \n
PVE/VZDump.pm | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index de29ca60..5f78746d 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -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) };
--
2.30.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [pve-devel] [PATCH v4 manager 2/7] ui: util: add helpers for (un)escaping notes-template
2022-04-27 15:41 [pve-devel] [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump Fabian Ebner
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 1/7] partially close #438: vzdump: support setting notes-template Fabian Ebner
@ 2022-04-27 15:41 ` Fabian Ebner
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 3/7] ui: backup: allow setting protected and notes-template for manual backup Fabian Ebner
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Fabian Ebner @ 2022-04-27 15:41 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
www/manager6/Utils.js | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 4611ff0f..08778f5c 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1784,6 +1784,22 @@ Ext.define('PVE.Utils', {
return undefined;
},
+
+ escapeNotesTemplate: function(value) {
+ let replace = {
+ '\\': '\\\\',
+ '\n': '\\n',
+ };
+ return value.replace(/(\\|[\n])/g, match => replace[match]);
+ },
+
+ unEscapeNotesTemplate: function(value) {
+ let replace = {
+ '\\\\': '\\',
+ '\\n': '\n',
+ };
+ return value.replace(/(\\\\|\\n)/g, match => replace[match]);
+ },
},
singleton: true,
--
2.30.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [pve-devel] [PATCH v4 manager 3/7] ui: backup: allow setting protected and notes-template for manual backup
2022-04-27 15:41 [pve-devel] [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump Fabian Ebner
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 1/7] partially close #438: vzdump: support setting notes-template Fabian Ebner
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 2/7] ui: util: add helpers for (un)escaping notes-template Fabian Ebner
@ 2022-04-27 15:41 ` Fabian Ebner
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 4/7] close #438: ui: backup job: allow setting a notes-template for a job Fabian Ebner
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Fabian Ebner @ 2022-04-27 15:41 UTC (permalink / raw)
To: pve-devel
Setting a width, so the text area can fill the horizontal space.
Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
www/manager6/window/Backup.js | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/www/manager6/window/Backup.js b/www/manager6/window/Backup.js
index 726122c8..f77e9ffa 100644
--- a/www/manager6/window/Backup.js
+++ b/www/manager6/window/Backup.js
@@ -154,19 +154,41 @@ Ext.define('PVE.window.Backup', {
},
});
+ let protectedCheckbox = Ext.create('Proxmox.form.Checkbox', {
+ name: 'protected',
+ checked: false,
+ uncheckedValue: 0,
+ fieldLabel: gettext('Protected'),
+ });
+
me.formPanel = Ext.create('Proxmox.panel.InputPanel', {
bodyPadding: 10,
border: false,
column1: [
storagesel,
modeSelector,
- removeCheckbox,
+ protectedCheckbox,
],
column2: [
compressionSelector,
mailtoField,
+ removeCheckbox,
],
columnB: [
+ {
+ xtype: 'textareafield',
+ name: 'notes-template',
+ fieldLabel: gettext('Notes'),
+ anchor: '100%',
+ value: '{{guestname}}',
+ autoEl: {
+ tag: 'div',
+ 'data-qtip': Ext.String.format(
+ gettext('Notes added to the backup. Possible variables are {0}'),
+ '{{cluster}}, {{guestname}}, {{node}}, {{vmid}}',
+ ),
+ },
+ },
{
xtype: 'label',
name: 'pruneLabel',
@@ -229,6 +251,15 @@ Ext.define('PVE.window.Backup', {
params.compress = values.compress;
}
+ if (values.protected) {
+ params.protected = values.protected;
+ }
+
+ if (values['notes-template']) {
+ params['notes-template'] = PVE.Utils.escapeNotesTemplate(
+ values['notes-template']);
+ }
+
Proxmox.Utils.API2Request({
url: '/nodes/' + me.nodename + '/vzdump',
params: params,
@@ -272,6 +303,7 @@ Ext.define('PVE.window.Backup', {
modal: true,
layout: 'auto',
border: false,
+ width: 600,
items: [me.formPanel],
buttons: [helpBtn, '->', submitBtn],
listeners: {
--
2.30.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [pve-devel] [PATCH v4 manager 4/7] close #438: ui: backup job: allow setting a notes-template for a job
2022-04-27 15:41 [pve-devel] [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump Fabian Ebner
` (2 preceding siblings ...)
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 3/7] ui: backup: allow setting protected and notes-template for manual backup Fabian Ebner
@ 2022-04-27 15:41 ` Fabian Ebner
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 5/7] ui: dc/backup: move note template to own tab and adapt Fabian Ebner
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Fabian Ebner @ 2022-04-27 15:41 UTC (permalink / raw)
To: pve-devel
Add a tooltip to the comment field, to better distinguish it from the
notes-template.
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
www/manager6/dc/Backup.js | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/www/manager6/dc/Backup.js b/www/manager6/dc/Backup.js
index 2b892c6f..9b129266 100644
--- a/www/manager6/dc/Backup.js
+++ b/www/manager6/dc/Backup.js
@@ -231,6 +231,24 @@ Ext.define('PVE.dc.BackupEdit', {
name: 'comment',
fieldLabel: gettext('Comment'),
deleteEmpty: !me.isCreate,
+ autoEl: {
+ tag: 'div',
+ 'data-qtip': gettext('Description of the job'),
+ },
+ },
+ {
+ xtype: 'proxmoxtextfield',
+ name: 'notes-template',
+ fieldLabel: gettext('Notes'),
+ deleteEmpty: !me.isCreate,
+ value: me.isCreate ? '{{guestname}}' : undefined,
+ autoEl: {
+ tag: 'div',
+ 'data-qtip': Ext.String.format(
+ gettext('Notes added to the backup. Possible variables are {0}'),
+ '{{cluster}}, {{guestname}}, {{node}}, {{vmid}}',
+ ),
+ },
},
],
onGetValues: function(values) {
--
2.30.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [pve-devel] [PATCH v4 manager 5/7] ui: dc/backup: move note template to own tab and adapt
2022-04-27 15:41 [pve-devel] [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump Fabian Ebner
` (3 preceding siblings ...)
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 4/7] close #438: ui: backup job: allow setting a notes-template for a job Fabian Ebner
@ 2022-04-27 15:41 ` Fabian Ebner
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 6/7] ui: dc/backup: (un)escape notes-template Fabian Ebner
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Fabian Ebner @ 2022-04-27 15:41 UTC (permalink / raw)
To: pve-devel
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
www/manager6/dc/Backup.js | 49 +++++++++++++++++++++++++++------------
1 file changed, 34 insertions(+), 15 deletions(-)
diff --git a/www/manager6/dc/Backup.js b/www/manager6/dc/Backup.js
index 9b129266..df4a70fd 100644
--- a/www/manager6/dc/Backup.js
+++ b/www/manager6/dc/Backup.js
@@ -229,27 +229,13 @@ Ext.define('PVE.dc.BackupEdit', {
{
xtype: 'proxmoxtextfield',
name: 'comment',
- fieldLabel: gettext('Comment'),
+ fieldLabel: gettext('Job Comment'),
deleteEmpty: !me.isCreate,
autoEl: {
tag: 'div',
'data-qtip': gettext('Description of the job'),
},
},
- {
- xtype: 'proxmoxtextfield',
- name: 'notes-template',
- fieldLabel: gettext('Notes'),
- deleteEmpty: !me.isCreate,
- value: me.isCreate ? '{{guestname}}' : undefined,
- autoEl: {
- tag: 'div',
- 'data-qtip': Ext.String.format(
- gettext('Notes added to the backup. Possible variables are {0}'),
- '{{cluster}}, {{guestname}}, {{node}}, {{vmid}}',
- ),
- },
- },
],
onGetValues: function(values) {
if (!values.node) {
@@ -390,6 +376,39 @@ Ext.define('PVE.dc.BackupEdit', {
showPBSHint: false,
fallbackHintHtml: gettext('Without any keep option, the storage\'s configuration or node\'s vzdump.conf is used as fallback'),
},
+ {
+ xtype: 'inputpanel',
+ title: gettext('Note Template'),
+ region: 'center',
+ layout: {
+ type: 'vbox',
+ align: 'stretch',
+ },
+ items: [
+ {
+ xtype: 'textarea',
+ name: 'notes-template',
+ fieldLabel: gettext('Backup Notes'),
+ height: 100,
+ maxLength: 512,
+ deleteEmpty: !me.isCreate,
+ value: me.isCreate ? '{{guestname}}' : undefined,
+ },
+ {
+ xtype: 'box',
+ style: {
+ margin: '8px 0px',
+ 'line-height': '1.5em',
+ },
+ html: gettext('The notes are added to each backup created by this job.')
+ + '<br>'
+ + Ext.String.format(
+ gettext('Possible template variables are: {0}'),
+ ['cluster', 'guestname', 'node', 'vmid'].map(v => `<code>{{${v}}}</code>`).join(', '),
+ ),
+ },
+ ],
+ },
],
},
],
--
2.30.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [pve-devel] [PATCH v4 manager 6/7] ui: dc/backup: (un)escape notes-template
2022-04-27 15:41 [pve-devel] [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump Fabian Ebner
` (4 preceding siblings ...)
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 5/7] ui: dc/backup: move note template to own tab and adapt Fabian Ebner
@ 2022-04-27 15:41 ` Fabian Ebner
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 7/7] vzdump: generate notes: die upon unexpected escape character or variable Fabian Ebner
2022-04-28 16:30 ` [pve-devel] applied-series: [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump Thomas Lamprecht
7 siblings, 0 replies; 9+ messages in thread
From: Fabian Ebner @ 2022-04-27 15:41 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
Technically should come earlier, but I didn't want to write a
second version for before Thomas's patch and rebase after.
www/manager6/dc/Backup.js | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/www/manager6/dc/Backup.js b/www/manager6/dc/Backup.js
index df4a70fd..b081be8c 100644
--- a/www/manager6/dc/Backup.js
+++ b/www/manager6/dc/Backup.js
@@ -384,6 +384,13 @@ Ext.define('PVE.dc.BackupEdit', {
type: 'vbox',
align: 'stretch',
},
+ onGetValues: function(values) {
+ if (values['notes-template']) {
+ values['notes-template'] = PVE.Utils.escapeNotesTemplate(
+ values['notes-template']);
+ }
+ return values;
+ },
items: [
{
xtype: 'textarea',
@@ -453,6 +460,11 @@ Ext.define('PVE.dc.BackupEdit', {
delete data.maxfiles;
}
+ if (data['notes-template']) {
+ data['notes-template'] = PVE.Utils.unEscapeNotesTemplate(
+ data['notes-template']);
+ }
+
me.setValues(data);
},
});
--
2.30.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [pve-devel] [PATCH v4 manager 7/7] vzdump: generate notes: die upon unexpected escape character or variable
2022-04-27 15:41 [pve-devel] [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump Fabian Ebner
` (5 preceding siblings ...)
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 6/7] ui: dc/backup: (un)escape notes-template Fabian Ebner
@ 2022-04-27 15:41 ` Fabian Ebner
2022-04-28 16:30 ` [pve-devel] applied-series: [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump Thomas Lamprecht
7 siblings, 0 replies; 9+ messages in thread
From: Fabian Ebner @ 2022-04-27 15:41 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
PVE/VZDump.pm | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index 5f78746d..fcbd87d5 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -80,16 +80,20 @@ my $generate_notes = sub {
vmid => $task->{vmid},
};
- my $unescape = {
- '\\\\' => '\\', # replace \\ by \
- '\n' => "\n", # turn literal \n into real newline
+ my $unescape = sub {
+ my ($char) = @_;
+ return '\\' if $char eq '\\';
+ return "\n" if $char eq 'n';
+ die "unexpected escape character '$char'\n";
};
- $notes_template =~ s/(\Q\\\E|\Q\n\E)/$unescape->{$1}/g;
+ $notes_template =~ s/\\(.)/$unescape->($1)/eg;
my $vars = join('|', keys $info->%*);
$notes_template =~ s/\{\{($vars)\}\}/\Q$info->{$1}\E/g;
+ die "unexpected variable name '$1'" if $notes_template =~ m/\{\{([^\s]+)\}\}/;
+
return $notes_template;
};
@@ -1042,9 +1046,13 @@ sub exec_backup_task {
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 $@;
+ my $notes = eval { $generate_notes->($opts->{'notes-template'}, $task); };
+ if (my $err = $@) {
+ debugmsg('warn', "unable to add notes - $err", $logfd);
+ } else {
+ eval { PVE::Storage::update_volume_attribute($cfg, $volid, 'notes', $notes) };
+ debugmsg('warn', "unable to add notes - $@", $logfd) if $@;
+ }
}
if ($opts->{protected}) {
--
2.30.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [pve-devel] applied-series: [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump
2022-04-27 15:41 [pve-devel] [PATCH-SERIES v4 manager] add protected and notes-template parameters for vzdump Fabian Ebner
` (6 preceding siblings ...)
2022-04-27 15:41 ` [pve-devel] [PATCH v4 manager 7/7] vzdump: generate notes: die upon unexpected escape character or variable Fabian Ebner
@ 2022-04-28 16:30 ` Thomas Lamprecht
7 siblings, 0 replies; 9+ messages in thread
From: Thomas Lamprecht @ 2022-04-28 16:30 UTC (permalink / raw)
To: Proxmox VE development discussion, Fabian Ebner
On 27.04.22 17:41, Fabian Ebner wrote:
> Introduce 'protected' to automatically mark a backup as protected
> upon completion, and 'notes-template' to generate notes from a
> template string with certain variables.
>
> Add both to the UI for manual backups and add 'notes-template' to the
> UI for backup jobs.
>
> Changes from v3:
> * dropped already applied patches
> * also expand \\ and \n and have notes-template be a single line
> so that it can be written to job config
> * die on unexpected variable or escape character
>
>
> Missing adapt description in common and add something to docs (will do
> so tomorrow).
>
>
> Fabian Ebner (6):
> partially close #438: vzdump: support setting notes-template
> ui: util: add helpers for (un)escaping notes-template
> ui: backup: allow setting protected and notes-template for manual
> backup
> close #438: ui: backup job: allow setting a notes-template for a job
> ui: dc/backup: (un)escape notes-template
> vzdump: generate notes: die upon unexpected escape character or
> variable
>
> Thomas Lamprecht (1):
> ui: dc/backup: move note template to own tab and adapt
>
> PVE/VZDump.pm | 38 ++++++++++++++++++++++++++
> www/manager6/Utils.js | 16 +++++++++++
> www/manager6/dc/Backup.js | 51 ++++++++++++++++++++++++++++++++++-
> www/manager6/window/Backup.js | 34 ++++++++++++++++++++++-
> 4 files changed, 137 insertions(+), 2 deletions(-)
>
applied, thanks!
^ permalink raw reply [flat|nested] 9+ messages in thread