2020-03-26 10:17:15 +00:00
|
|
|
Ext.define('pbs-data-store-snapshots', {
|
2019-12-20 11:46:09 +00:00
|
|
|
extend: 'Ext.data.Model',
|
2019-12-20 16:04:45 +00:00
|
|
|
fields: [
|
|
|
|
'backup-type',
|
2019-12-22 09:43:57 +00:00
|
|
|
'backup-id',
|
|
|
|
{
|
2020-03-25 14:17:28 +00:00
|
|
|
name: 'backup-time',
|
2019-12-22 09:43:57 +00:00
|
|
|
type: 'date',
|
|
|
|
dateFormat: 'timestamp'
|
|
|
|
},
|
2019-12-20 16:04:45 +00:00
|
|
|
'files',
|
2020-05-29 13:09:01 +00:00
|
|
|
'owner',
|
2020-03-25 14:17:28 +00:00
|
|
|
{ name: 'size', type: 'int' },
|
2020-06-18 11:55:25 +00:00
|
|
|
{
|
|
|
|
name: 'encrypted',
|
2020-06-23 10:09:46 +00:00
|
|
|
type: 'boolean',
|
2020-06-18 11:55:25 +00:00
|
|
|
calculate: function(data) {
|
|
|
|
let encrypted = 0;
|
|
|
|
let files = 0;
|
|
|
|
data.files.forEach(file => {
|
|
|
|
if (file.filename === 'index.json.blob') return; // is never encrypted
|
|
|
|
if (file.encrypted) {
|
|
|
|
encrypted++;
|
|
|
|
}
|
|
|
|
files++;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (encrypted === 0) {
|
2020-06-23 10:09:46 +00:00
|
|
|
return 0;
|
2020-06-18 11:55:25 +00:00
|
|
|
} else if (encrypted < files) {
|
2020-06-23 10:09:46 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 2;
|
2020-06-18 11:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-26 10:17:15 +00:00
|
|
|
]
|
2019-12-20 11:46:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Ext.define('PBS.DataStoreContent', {
|
2020-03-25 14:17:28 +00:00
|
|
|
extend: 'Ext.tree.Panel',
|
2019-12-20 11:46:09 +00:00
|
|
|
alias: 'widget.pbsDataStoreContent',
|
|
|
|
|
2020-03-25 14:17:28 +00:00
|
|
|
rootVisible: false,
|
2019-12-22 09:43:57 +00:00
|
|
|
|
2020-05-20 10:15:38 +00:00
|
|
|
title: gettext('Content'),
|
|
|
|
|
2019-12-20 16:17:44 +00:00
|
|
|
controller: {
|
|
|
|
xclass: 'Ext.app.ViewController',
|
|
|
|
|
|
|
|
init: function(view) {
|
|
|
|
if (!view.datastore) {
|
|
|
|
throw "no datastore specified";
|
|
|
|
}
|
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
this.store = Ext.create('Ext.data.Store', {
|
2020-03-26 10:17:15 +00:00
|
|
|
model: 'pbs-data-store-snapshots',
|
2020-03-25 14:17:28 +00:00
|
|
|
groupField: 'backup-group',
|
|
|
|
});
|
2020-05-26 10:46:45 +00:00
|
|
|
this.store.on('load', this.onLoad, this);
|
2020-03-25 14:17:28 +00:00
|
|
|
|
2020-06-23 10:09:47 +00:00
|
|
|
view.getStore().setSorters([
|
|
|
|
'backup-group',
|
|
|
|
'text',
|
|
|
|
'backup-time'
|
|
|
|
]);
|
2019-12-20 16:17:44 +00:00
|
|
|
Proxmox.Utils.monStoreErrors(view, view.store, true);
|
|
|
|
this.reload(); // initial load
|
|
|
|
},
|
|
|
|
|
|
|
|
reload: function() {
|
2020-05-26 10:46:45 +00:00
|
|
|
let view = this.getView();
|
|
|
|
|
|
|
|
if (!view.store || !this.store) {
|
|
|
|
console.warn('cannot reload, no store(s)');
|
|
|
|
return;
|
|
|
|
}
|
2019-12-20 16:17:44 +00:00
|
|
|
|
2020-03-25 14:17:28 +00:00
|
|
|
let url = `/api2/json/admin/datastore/${view.datastore}/snapshots`;
|
2020-05-26 10:46:45 +00:00
|
|
|
this.store.setProxy({
|
2019-12-20 16:17:44 +00:00
|
|
|
type: 'proxmox',
|
|
|
|
url: url
|
|
|
|
});
|
2020-03-25 14:17:28 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
this.store.load();
|
|
|
|
},
|
2020-03-25 14:17:28 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
getRecordGroups: function(records) {
|
|
|
|
let groups = {};
|
|
|
|
|
|
|
|
for (const item of records) {
|
|
|
|
var btype = item.data["backup-type"];
|
|
|
|
let group = btype + "/" + item.data["backup-id"];
|
|
|
|
|
|
|
|
if (groups[group] !== undefined) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cls = '';
|
|
|
|
if (btype === 'vm') {
|
|
|
|
cls = 'fa-desktop';
|
|
|
|
} else if (btype === 'ct') {
|
|
|
|
cls = 'fa-cube';
|
|
|
|
} else if (btype === 'host') {
|
|
|
|
cls = 'fa-building';
|
|
|
|
} else {
|
2020-05-30 14:37:33 +00:00
|
|
|
console.warn(`got unknown backup-type '${btype}'`);
|
2020-05-26 10:46:45 +00:00
|
|
|
continue; // FIXME: auto render? what do?
|
|
|
|
}
|
|
|
|
|
|
|
|
groups[group] = {
|
|
|
|
text: group,
|
|
|
|
leaf: false,
|
|
|
|
iconCls: "fa " + cls,
|
|
|
|
expanded: false,
|
|
|
|
backup_type: item.data["backup-type"],
|
|
|
|
backup_id: item.data["backup-id"],
|
|
|
|
children: []
|
2020-03-26 17:01:04 +00:00
|
|
|
};
|
2020-05-26 10:46:45 +00:00
|
|
|
}
|
2020-03-26 17:01:04 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
return groups;
|
|
|
|
},
|
2020-03-25 14:17:28 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
onLoad: function(store, records, success) {
|
|
|
|
let view = this.getView();
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let groups = this.getRecordGroups(records);
|
2020-03-25 14:17:28 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
for (const item of records) {
|
|
|
|
let group = item.data["backup-type"] + "/" + item.data["backup-id"];
|
|
|
|
let children = groups[group].children;
|
|
|
|
|
|
|
|
let data = item.data;
|
|
|
|
|
2020-05-26 16:16:38 +00:00
|
|
|
data.text = group + '/' + PBS.Utils.render_datetime_utc(data["backup-time"]);
|
2020-05-26 10:46:45 +00:00
|
|
|
data.leaf = true;
|
|
|
|
data.cls = 'no-leaf-icons';
|
|
|
|
|
|
|
|
children.push(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
let children = [];
|
|
|
|
for (const [_key, group] of Object.entries(groups)) {
|
|
|
|
let last_backup = 0;
|
2020-06-23 10:09:46 +00:00
|
|
|
let encrypted = 0;
|
2020-05-26 10:46:45 +00:00
|
|
|
for (const item of group.children) {
|
2020-06-23 10:09:46 +00:00
|
|
|
if (item.encrypted > 0) {
|
|
|
|
encrypted++;
|
|
|
|
}
|
2020-05-26 10:46:45 +00:00
|
|
|
if (item["backup-time"] > last_backup) {
|
|
|
|
last_backup = item["backup-time"];
|
|
|
|
group["backup-time"] = last_backup;
|
|
|
|
group.files = item.files;
|
|
|
|
group.size = item.size;
|
2020-05-29 13:09:01 +00:00
|
|
|
group.owner = item.owner;
|
2020-05-26 10:46:45 +00:00
|
|
|
}
|
2020-06-18 11:55:25 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
}
|
2020-06-23 10:09:46 +00:00
|
|
|
if (encrypted === 0) {
|
|
|
|
group.encrypted = 0;
|
|
|
|
} else if (encrypted < group.children.length) {
|
|
|
|
group.encrypted = 1;
|
|
|
|
} else {
|
|
|
|
group.encrypted = 2;
|
|
|
|
}
|
2020-05-26 10:46:45 +00:00
|
|
|
group.count = group.children.length;
|
|
|
|
children.push(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
view.setRootNode({
|
|
|
|
expanded: true,
|
|
|
|
children: children
|
|
|
|
});
|
2019-12-20 16:17:44 +00:00
|
|
|
},
|
2020-03-26 16:23:51 +00:00
|
|
|
|
|
|
|
onPrune: function() {
|
|
|
|
var view = this.getView();
|
|
|
|
|
|
|
|
let rec = view.selModel.getSelection()[0];
|
|
|
|
if (!(rec && rec.data)) return;
|
|
|
|
let data = rec.data;
|
|
|
|
if (data.leaf) return;
|
|
|
|
|
|
|
|
if (!view.datastore) return;
|
|
|
|
|
|
|
|
let win = Ext.create('PBS.DataStorePrune', {
|
|
|
|
datastore: view.datastore,
|
|
|
|
backup_type: data.backup_type,
|
|
|
|
backup_id: data.backup_id,
|
|
|
|
});
|
|
|
|
win.on('destroy', this.reload, this);
|
|
|
|
win.show();
|
2020-06-23 10:09:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
openBackupFileDownloader: function() {
|
|
|
|
let me = this;
|
|
|
|
let view = me.getView();
|
|
|
|
|
|
|
|
let rec = view.selModel.getSelection()[0];
|
|
|
|
if (!(rec && rec.data)) return;
|
|
|
|
let data = rec.data;
|
|
|
|
|
|
|
|
Ext.create('PBS.window.BackupFileDownloader', {
|
|
|
|
baseurl: `/api2/json/admin/datastore/${view.datastore}`,
|
|
|
|
params: {
|
|
|
|
'backup-id': data['backup-id'],
|
|
|
|
'backup-type': data['backup-type'],
|
|
|
|
'backup-time': (data['backup-time'].getTime()/1000).toFixed(0),
|
|
|
|
},
|
|
|
|
files: data.files,
|
|
|
|
}).show();
|
2020-03-26 16:23:51 +00:00
|
|
|
}
|
2019-12-20 16:17:44 +00:00
|
|
|
},
|
|
|
|
|
2020-05-29 13:09:01 +00:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
xtype: 'treecolumn',
|
|
|
|
header: gettext("Backup Group"),
|
|
|
|
dataIndex: 'text',
|
|
|
|
flex: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'datecolumn',
|
|
|
|
header: gettext('Backup Time'),
|
|
|
|
sortable: true,
|
|
|
|
dataIndex: 'backup-time',
|
|
|
|
format: 'Y-m-d H:i:s',
|
|
|
|
width: 150
|
|
|
|
},
|
|
|
|
{
|
|
|
|
header: gettext("Size"),
|
|
|
|
sortable: true,
|
|
|
|
dataIndex: 'size',
|
|
|
|
renderer: Proxmox.Utils.format_size,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'numbercolumn',
|
|
|
|
format: '0',
|
|
|
|
header: gettext("Count"),
|
|
|
|
sortable: true,
|
|
|
|
dataIndex: 'count',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
header: gettext("Owner"),
|
|
|
|
sortable: true,
|
|
|
|
dataIndex: 'owner',
|
|
|
|
},
|
2020-06-18 11:55:25 +00:00
|
|
|
{
|
|
|
|
header: gettext('Encrypted'),
|
|
|
|
dataIndex: 'encrypted',
|
2020-06-23 10:09:46 +00:00
|
|
|
renderer: function(value) {
|
|
|
|
switch (value) {
|
|
|
|
case 0: return Proxmox.Utils.noText;
|
|
|
|
case 1: return gettext('Mixed');
|
|
|
|
case 2: return Proxmox.Utils.yesText;
|
|
|
|
default: Proxmox.Utils.unknownText;
|
|
|
|
}
|
|
|
|
}
|
2020-06-18 11:55:25 +00:00
|
|
|
},
|
2020-05-29 13:09:01 +00:00
|
|
|
{
|
|
|
|
header: gettext("Files"),
|
|
|
|
sortable: false,
|
|
|
|
dataIndex: 'files',
|
2020-06-18 11:55:24 +00:00
|
|
|
renderer: function(files) {
|
|
|
|
return files.map((file) => {
|
2020-06-18 11:55:25 +00:00
|
|
|
let icon = '';
|
|
|
|
let size = '';
|
|
|
|
if (file.encrypted) {
|
|
|
|
icon = '<i class="fa fa-lock"></i> ';
|
|
|
|
}
|
|
|
|
if (file.size) {
|
|
|
|
size = ` (${Proxmox.Utils.format_size(file.size)})`;
|
|
|
|
}
|
|
|
|
return `${icon}${file.filename}${size}`;
|
2020-06-18 11:55:24 +00:00
|
|
|
}).join(', ');
|
|
|
|
},
|
2020-05-29 13:09:01 +00:00
|
|
|
flex: 2
|
|
|
|
},
|
|
|
|
],
|
2020-03-26 12:23:28 +00:00
|
|
|
|
2020-05-29 13:09:01 +00:00
|
|
|
tbar: [
|
|
|
|
{
|
|
|
|
text: gettext('Reload'),
|
|
|
|
iconCls: 'fa fa-refresh',
|
|
|
|
handler: 'reload',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'proxmoxButton',
|
2020-03-26 12:23:28 +00:00
|
|
|
text: gettext('Prune'),
|
|
|
|
disabled: true,
|
2020-06-04 10:38:45 +00:00
|
|
|
parentXType: 'pbsDataStoreContent',
|
2020-03-26 16:23:51 +00:00
|
|
|
enableFn: function(record) { return !record.data.leaf; },
|
|
|
|
handler: 'onPrune',
|
2020-06-23 10:09:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'proxmoxButton',
|
|
|
|
text: gettext('Download Files'),
|
|
|
|
disabled: true,
|
|
|
|
parentXType: 'pbsDataStoreContent',
|
|
|
|
handler: 'openBackupFileDownloader',
|
|
|
|
enableFn: function(record) {
|
|
|
|
return !!record.data.leaf;
|
|
|
|
},
|
2020-05-29 13:09:01 +00:00
|
|
|
}
|
|
|
|
],
|
2019-12-20 11:46:09 +00:00
|
|
|
});
|