]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/window/Restore.js
afac38bafa0f9e712c8f6c5b9689c46bab560b4f
1 Ext
.define('PVE.window.Restore', {
2 extend
: 'Ext.window.Window', // fixme: Proxmox.window.Edit?
11 xclass
: 'Ext.app.ViewController',
14 change: function(el
, newVal
) {
15 let liveWarning
= this.lookupReference('liveWarning');
16 liveWarning
.setHidden(!newVal
);
17 let start
= this.lookupReference('start');
18 start
.setDisabled(newVal
);
22 validitychange: function(f
, valid
) {
23 this.lookupReference('doRestoreBtn').setDisabled(!valid
);
28 doRestore: function() {
30 let view
= me
.getView();
32 let values
= view
.down('form').getForm().getValues();
35 vmid
: view
.vmid
|| values
.vmid
,
36 force
: view
.vmid
? 1 : 0,
41 if (values
.start
&& !values
['live-restore']) {
44 if (values
['live-restore']) {
45 params
['live-restore'] = 1;
48 params
.storage
= values
.storage
;
51 ['bwlimit', 'cores', 'name', 'memory', 'sockets'].forEach(opt
=> {
52 if ((values
[opt
] ?? '') !== '') {
53 params
[opt
] = values
[opt
];
57 if (params
.name
&& view
.vmtype
=== 'lxc') {
58 params
.hostname
= params
.name
;
63 if (view
.vmtype
=== 'lxc') {
64 params
.ostemplate
= view
.volid
;
66 if (values
.unprivileged
!== 'keep') {
67 params
.unprivileged
= values
.unprivileged
;
69 confirmMsg
= Proxmox
.Utils
.format_task_description('vzrestore', params
.vmid
);
70 } else if (view
.vmtype
=== 'qemu') {
71 params
.archive
= view
.volid
;
72 confirmMsg
= Proxmox
.Utils
.format_task_description('qmrestore', params
.vmid
);
74 throw 'unknown VM type';
77 let executeRestore
= () => {
78 Proxmox
.Utils
.API2Request({
79 url
: `/nodes/${view.nodename}/${view.vmtype}`,
83 failure
: response
=> Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
),
84 success: function(response
, options
) {
85 Ext
.create('Proxmox.window.TaskViewer', {
87 upid
: response
.result
.data
,
95 confirmMsg
+= '. ' + gettext('This will permanently erase current VM data.');
96 Ext
.Msg
.confirm(gettext('Confirm'), confirmMsg
, function(btn
) {
106 afterRender: function() {
107 let view
= this.getView();
109 Proxmox
.Utils
.API2Request({
110 url
: `/nodes/${view.nodename}/vzdump/extractconfig`,
116 failure
: response
=> Ext
.Msg
.alert('Error', response
.htmlStatus
),
117 success: function(response
, options
) {
118 let allStoragesAvailable
= true;
120 response
.result
.data
.split('\n').forEach(line
=> {
121 let [_
, key
, value
] = line
.match(/^([^:]+):\s*(\S+)\s*$/) ?? [];
127 if (key
=== '#qmdump#map') {
128 let match
= value
.match(/^(\S+):(\S+):(\S*):(\S*):$/) ?? [];
129 // if a /dev/XYZ disk was backed up, ther is no storage hint
130 allStoragesAvailable
&&= !!match
[3] && !!PVE
.data
.ResourceStore
.getById(
131 `storage/${view.nodename}/${match[3]}`);
132 } else if (key
=== 'name' || key
=== 'hostname') {
133 view
.lookupReference('nameField').setEmptyText(value
);
134 } else if (key
=== 'memory' || key
=== 'cores' || key
=== 'sockets') {
135 view
.lookupReference(`${key}Field`).setEmptyText(value
);
139 if (!allStoragesAvailable
) {
140 let storagesel
= view
.down('pveStorageSelector[name=storage]');
141 storagesel
.allowBlank
= false;
142 storagesel
.setEmptyText('');
149 initComponent: function() {
153 throw "no node name specified";
156 throw "no volume ID specified";
159 throw "no vmtype specified";
162 let storagesel
= Ext
.create('PVE.form.StorageSelector', {
163 nodename
: me
.nodename
,
166 fieldLabel
: gettext('Storage'),
167 storageContent
: me
.vmtype
=== 'lxc' ? 'rootdir' : 'images',
168 // when restoring a container without specifying a storage, the backend defaults
169 // to 'local', which is unintuitive and 'rootdir' might not even be allowed on it
170 allowBlank
: me
.vmtype
!== 'lxc',
171 emptyText
: me
.vmtype
=== 'lxc' ? '' : gettext('From backup configuration'),
172 autoSelect
: me
.vmtype
=== 'lxc',
177 xtype
: 'displayfield',
178 value
: me
.volidText
|| me
.volid
,
179 fieldLabel
: gettext('Source'),
183 xtype
: 'pmxDisplayEditField',
185 fieldLabel
: me
.vmtype
=== 'lxc' ? 'CT' : 'VM',
189 xtype
: 'pveGuestIDSelector',
190 guestType
: me
.vmtype
,
191 loadNextFreeID
: true,
192 validateExists
: false,
196 xtype
: 'pveBandwidthField',
200 fieldLabel
: gettext('Bandwidth Limit'),
201 emptyText
: gettext('Defaults to target storage restore limit'),
204 'data-qtip': gettext("Use '0' to disable all bandwidth limits."),
208 xtype
: 'fieldcontainer',
211 xtype
: 'proxmoxcheckbox',
213 fieldLabel
: gettext('Unique'),
217 'data-qtip': gettext('Autogenerate unique properties, e.g., MAC addresses'),
222 xtype
: 'proxmoxcheckbox',
226 fieldLabel
: gettext('Start after restore'),
233 if (me
.vmtype
=== 'lxc') {
237 fieldLabel
: gettext('Privilege Level'),
238 reference
: 'noVNCScalingGroup',
239 height
: '15px', // renders faster with value assigned
247 gettext('Choose if you want to keep or override the privilege level of the restored Container.'),
252 name
: 'unprivileged',
254 boxLabel
: gettext('From Backup'),
260 name
: 'unprivileged',
262 boxLabel
: gettext('Unprivileged'),
267 name
: 'unprivileged',
269 boxLabel
: gettext('Privileged'),
271 //margin: '0 0 0 10',
276 } else if (me
.vmtype
=== 'qemu') {
278 xtype
: 'proxmoxcheckbox',
279 name
: 'live-restore',
280 itemId
: 'liveRestore',
282 fieldLabel
: gettext('Live restore'),
287 xtype
: 'displayfield',
288 reference
: 'liveWarning',
289 // TODO: Remove once more tested/stable?
290 value
: gettext('Note: If anything goes wrong during the live-restore, new data written by the VM may be lost.'),
298 title
: `${gettext('Override Settings')}:`,
307 fieldLabel
: me
.vmtype
=== 'lxc' ? gettext('Hostname') : gettext('Name'),
309 reference
: 'nameField',
313 xtype
: 'pveMemoryField',
314 fieldLabel
: gettext('Memory'),
316 reference
: 'memoryField',
321 xtype
: 'proxmoxintegerfield',
322 fieldLabel
: gettext('Cores'),
324 reference
: 'coresField',
330 xtype
: 'proxmoxintegerfield',
331 fieldLabel
: gettext('Sockets'),
333 reference
: 'socketsField',
337 hidden
: me
.vmtype
!== 'qemu',
338 disabled
: me
.vmtype
!== 'qemu',
343 let title
= gettext('Restore') + ": " + (me
.vmtype
=== 'lxc' ? 'CT' : 'VM');
345 title
= `${gettext('Overwrite')} ${title} ${me.vmid}`;
364 text
: gettext('Restore'),
365 reference
: 'doRestoreBtn',
366 handler
: 'doRestore',