]> git.proxmox.com Git - pve-manager.git/commitdiff
start backup/restore GUI
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 18 Oct 2011 10:48:34 +0000 (12:48 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 18 Oct 2011 10:49:14 +0000 (12:49 +0200)
PVE/API2/VZDump.pm
PVE/VZDump.pm
www/manager/Makefile
www/manager/qemu/Backup.js [new file with mode: 0644]
www/manager/qemu/Config.js

index b4fefbd668974bb556ca0c7f39471367b5f05533..f16ae5b45ddea7cca37950145e1d57726e3679c7 100644 (file)
@@ -22,6 +22,7 @@ __PACKAGE__->register_method ({
     path => '',
     method => 'POST',
     description => "Create backup.",
+    protected => 1,
     parameters => {
        additionalProperties => 0,
        properties => {
index ea4b2fcd1d7855c10eb97dffb2d99470fe6d384b..ebe56db61bef9c9ecfbaed12b4ec68e7f2922ca2 100644 (file)
@@ -88,7 +88,7 @@ sub storage_info {
     PVE::Storage::activate_storage($cfg, $storage);
 
     return {
-       dumpdir => $scfg->{path},
+       dumpdir => PVE::Storage::get_backup_dir($cfg, $storage),
     };
 }
 
@@ -828,7 +828,7 @@ sub exec_backup_task {
 
        if ($opts->{stdout}) {
            debugmsg ('info', "sending archive to stdout", $logfd);
-           $plugin->archive ($task, $vmid, $task->{tmptar});
+           $plugin->archive($task, $vmid, $task->{tmptar});
            $self->run_hook_script ('backup-end', $task, $logfd);
            return;
        }
@@ -853,8 +853,9 @@ sub exec_backup_task {
            my $dir = $opts->{dumpdir};
            foreach my $fn (<$dir/${bkname}-*>) {
                next if $fn eq $task->{tarfile};
-               if ($fn =~ m!/${bkname}-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|tar)$!) {
-                   my $t = timelocal ($6, $5, $4, $3, $2 - 1, $1 - 1900);
+               if ($fn =~ m!/(${bkname}-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|tar))$!) {
+                   $fn = "$dir/$1"; # untaint
+                   my $t = timelocal ($7, $6, $5, $4, $3 - 1, $2 - 1900);
                    push @bklist, [$fn, $t];
                }
            }
index ad1f57f9d7d309fb779d02196e9cfe4886752d30..022d021947b44ec57d286cfe9b62604ac5b1ff42 100644 (file)
@@ -80,6 +80,7 @@ JSSRC=                                                        \
        qemu/KeyboardEdit.js                            \
        qemu/HardwareView.js                            \
        qemu/Options.js                                 \
+       qemu/Backup.js                                  \
        qemu/Config.js                                  \
        qemu/CreateWizard.js                            \
        openvz/StatusView.js                            \
diff --git a/www/manager/qemu/Backup.js b/www/manager/qemu/Backup.js
new file mode 100644 (file)
index 0000000..a0ddc81
--- /dev/null
@@ -0,0 +1,150 @@
+Ext.define('PVE.qemu.Backup', {
+    extend: 'Ext.grid.GridPanel',
+
+    alias: ['widget.pveQemuBackup'],
+
+
+    initComponent : function() {
+       var me = this;
+
+       var nodename = me.pveSelNode.data.node;
+       if (!nodename) {
+           throw "no node name specified";
+       }
+
+       var vmid = me.pveSelNode.data.vmid;
+       if (!vmid) {
+           throw "no VM ID specified";
+       }
+
+       me.store = Ext.create('Ext.data.Store', {
+           model: 'pve-storage-content',
+           sorters: { 
+               property: 'volid', 
+               order: 'DESC' 
+           }
+       });
+
+       var reload = Ext.Function.createBuffered(function() {
+           if (me.store.proxy.url) {
+               me.store.load();
+           }
+       }, 100);
+
+       var setStorage = function(storage) {
+           var url = '/api2/json/nodes/' + nodename + '/storage/' + storage + '/content';
+           url += '?content=backup';
+
+           me.store.setProxy({
+               type: 'pve',
+               url: url
+           });
+
+           reload();
+       };
+
+       var storagesel = Ext.create('PVE.form.StorageSelector', {
+           nodename: nodename,
+           fieldLabel: 'Storage',
+           labelAlign: 'right',
+           storageContent: 'backup',
+           allowBlank: false,
+           listeners: {
+               change: function(f, value) {
+                   setStorage(value);
+               }
+           }
+       });
+
+       var backup_btn = new Ext.Button({
+           text: 'Backup now',
+           handler: function(){
+               var storage = storagesel.getValue();
+               var msg = 'Start backup to storage "' + storage + '"';
+               Ext.Msg.confirm('Backup Confirmation', msg, function(btn) {
+                   if (btn !== 'yes') {
+                       return;
+                   }
+
+                   PVE.Utils.API2Request({
+                       url: '/nodes/' + nodename + '/vzdump',
+                       params: {
+                           storage: storage,
+                           vmid: vmid,
+                           compress: 1,
+                           snapshot: 1
+                       },
+                       method: 'POST',
+                       failure: function (response, opts) {
+                           Ext.Msg.alert('Error',response.htmlStatus);
+                       },
+                       success: function(response, options) {
+                           var upid = response.result.data;
+
+                           var win = Ext.create('PVE.window.TaskViewer', { 
+                               upid: upid
+                           });
+                           win.show();
+                       }
+                   });
+               });
+           }
+       });
+
+       var restore_btn = new Ext.Button({
+           text: 'Restore',
+           disabled: true,
+           handler: function(){
+               var sm = me.getSelectionModel();
+               var rec = sm.getSelection()[0];
+               if (!rec) {
+                   return;
+               }
+
+               var volid = rec.data.volid;
+
+               console.log("RESRORE " + volid);
+           }
+       });
+
+       var set_button_status = function() {
+           var sm = me.getSelectionModel();
+           var rec = sm.getSelection()[0];
+
+           restore_btn.setDisabled(!(rec && rec.data.volid));
+       }
+
+       Ext.apply(me, {
+           stateful: false,
+           tbar: [ backup_btn, restore_btn, '->', storagesel ],
+           columns: [
+               {
+                   header: 'Name',
+                   flex: 1,
+                   sortable: true,
+                   renderer: PVE.Utils.render_storage_content,
+                   dataIndex: 'volid'
+               },
+               {
+                   header: 'Format',
+                   width: 100,
+                   dataIndex: 'format'
+               },
+               {
+                   header: 'Size',
+                   width: 100,
+                   renderer: PVE.Utils.format_size,
+                   dataIndex: 'size'
+               }
+           ],
+           listeners: {
+               show: reload,
+               selectionchange: set_button_status
+           }
+       });
+
+       me.callParent();
+
+       //setStorage('local');
+    }
+});
index 41510efc6139fc3f2668b914ea46c1859f9c37fb..e274b526ce639c3d68a64173bd4c653cb14fba00 100644 (file)
@@ -46,9 +46,9 @@ Ext.define('PVE.qemu.Config', {
                    vmid: vmid
                },
                {
+                   xtype: 'pveQemuBackup',
                    title: 'Backup',
-                   itemId: 'backup',
-                   html: 'Backup and restore - not implemented!'
+                   itemId: 'backup'
                },
                {
                    title: 'Permissions',