[pve-devel] [PATCH v3 manager 1/3] fix #1594: add "Run now" button to cluster backup page

Stefan Reiter s.reiter at proxmox.com
Mon Aug 12 14:50:06 CEST 2019


Iterate all (online) nodes client-side and call vzdump with the correct
parameters (according to the job selected) for each one.

Then, show a progress bar in a non-closeable modal-dialog, to ensure the
user stays on the Backup page during the /vzdump API calls. Any errors
that occurred will be displayed in a consolidated message box.

Includes a "confirm" dialog to not accidentally run a potentially large
backup job.

Curiously, the "pve-cluster-backup" data model seems to have been broken
entirely.  I'm not sure how it was working before, but the changes in
this patch need it fixed, so include that as well (use "mode" instead of
individual flags + "compress" is not a boolean).

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
 www/manager6/dc/Backup.js | 97 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 90 insertions(+), 7 deletions(-)

diff --git a/www/manager6/dc/Backup.js b/www/manager6/dc/Backup.js
index 79e9cace..f644e364 100644
--- a/www/manager6/dc/Backup.js
+++ b/www/manager6/dc/Backup.js
@@ -419,6 +419,67 @@ Ext.define('PVE.dc.BackupView', {
             win.show();
 	};
 
+	var run_backup_now = function(job) {
+	    job = Ext.clone(job);
+
+	    var allNodes = PVE.data.ResourceStore.getNodes();
+	    var jobNode = job.node;
+
+	    // Remove properties related to scheduling
+	    delete job.enabled;
+	    delete job.starttime;
+	    delete job.dow;
+	    delete job.id;
+	    delete job.node;
+	    job.all = job.all === true ? 1 : 0;
+
+	    var errors = [];
+	    var inProgress = allNodes.length;
+
+	    Ext.Msg.show({
+		title: gettext('Please wait...'),
+		closable: false,
+		progress: true
+	    });
+	    Ext.Msg.updateProgress(0, '0/' + allNodes.length);
+
+	    var postRequest = function () {
+		inProgress++;
+
+		Ext.Msg.updateProgress(inProgress/allNodes.length,
+		    inProgress + '/' + allNodes.length);
+
+		if (inProgress == allNodes.length) {
+		    Ext.Msg.hide();
+		    if (errors !== undefined && errors.length > 0) {
+			Ext.Msg.alert('Error', 'Some errors have been encountered:<br />---<br />'
+			    + errors.join('<br />---<br />'));
+		    }
+		}
+	    }
+
+	    allNodes.forEach(node => {
+		if (node.status !== 'online' ||
+		    (jobNode !== undefined && jobNode !== node.node)) {
+		    errors.push(node.node + ": " + gettext("Node is offline"));
+		    return;
+		}
+
+		inProgress--;
+
+		Proxmox.Utils.API2Request({
+		    url: '/nodes/' + node.node + '/vzdump',
+		    method: 'POST',
+		    params: job,
+		    failure: function (response, opts) {
+			errors.push(node.node + ': ' + response.htmlStatus);
+			postRequest();
+		    },
+		    success: postRequest
+		});
+	    });
+	}
+
 	var edit_btn = new Proxmox.button.Button({
 	    text: gettext('Edit'),
 	    disabled: true,
@@ -426,6 +487,31 @@ Ext.define('PVE.dc.BackupView', {
 	    handler: run_editor
 	});
 
+	var run_btn = new Proxmox.button.Button({
+	    text: gettext('Run now'),
+	    disabled: true,
+	    selModel: sm,
+	    handler: function() {
+		var rec = sm.getSelection()[0];
+		if (!rec) {
+		    return;
+		}
+
+		Ext.Msg.show({
+		    title: gettext('Confirm'),
+		    icon: Ext.Msg.QUESTION,
+		    msg: gettext('Start the selected backup job now?'),
+		    buttons: Ext.Msg.YESNO,
+		    callback: function(btn) {
+			if (btn !== 'yes') {
+			    return;
+			}
+			run_backup_now(rec.data);
+		    }
+		});
+	    }
+	});
+
 	var remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
 	    selModel: sm,
 	    baseurl: '/cluster/backup',
@@ -454,7 +540,8 @@ Ext.define('PVE.dc.BackupView', {
 		    }
 		},
 		remove_btn,
-		edit_btn
+		edit_btn,
+		run_btn
 	    ],
 	    columns: [
 		{
@@ -576,13 +663,9 @@ Ext.define('PVE.dc.BackupView', {
 	fields: [
 	    'id', 'starttime', 'dow',
 	    'storage', 'node', 'vmid', 'exclude',
-	    'mailto', 'pool',
+	    'mailto', 'pool', 'compress', 'mode',
 	    { name: 'enabled', type: 'boolean' },
-	    { name: 'all', type: 'boolean' },
-	    { name: 'snapshot', type: 'boolean' },
-	    { name: 'stop', type: 'boolean' },
-	    { name: 'suspend', type: 'boolean' },
-	    { name: 'compress', type: 'boolean' }
+	    { name: 'all', type: 'boolean' }
 	]
     });
 });
-- 
2.20.1





More information about the pve-devel mailing list