fix #1594: add "Run now" button to cluster backup page

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@proxmox.com>
This commit is contained in:
Stefan Reiter 2019-08-12 14:50:06 +02:00 committed by Thomas Lamprecht
parent 6cd5ffb06c
commit 389d3cf19b

View File

@ -417,6 +417,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,
@ -424,6 +485,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',
@ -452,7 +538,8 @@ Ext.define('PVE.dc.BackupView', {
}
},
remove_btn,
edit_btn
edit_btn,
run_btn
],
columns: [
{
@ -574,13 +661,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' }
]
});
});