Bläddra i källkod

backup: use proper API for getting volumes list and size

Do not assume static list of volume (although it is true for now), and
also use proper API for getting volume size, instead of assuming it's a
normal file.
Marek Marczykowski-Górecki 6 år sedan
förälder
incheckning
579d90e174
1 ändrade filer med 12 tillägg och 13 borttagningar
  1. 12 13
      qubes/backup.py

+ 12 - 13
qubes/backup.py

@@ -250,8 +250,9 @@ class Backup(object):
     # pylint: disable=too-many-instance-attributes
     # pylint: disable=too-many-instance-attributes
     class FileToBackup(object):
     class FileToBackup(object):
         # pylint: disable=too-few-public-methods
         # pylint: disable=too-few-public-methods
-        def __init__(self, file_path, subdir=None, name=None):
-            file_size = qubes.storage.file.get_disk_usage(file_path)
+        def __init__(self, file_path, subdir=None, name=None, size=None):
+            if size is None:
+                size = qubes.storage.file.get_disk_usage(file_path)
 
 
             if subdir is None:
             if subdir is None:
                 abs_file_path = os.path.abspath(file_path)
                 abs_file_path = os.path.abspath(file_path)
@@ -269,7 +270,7 @@ class Backup(object):
             #: real path to the file
             #: real path to the file
             self.path = file_path
             self.path = file_path
             #: size of the file
             #: size of the file
-            self.size = file_size
+            self.size = size
             #: directory in backup archive where file should be placed
             #: directory in backup archive where file should be placed
             self.subdir = subdir
             self.subdir = subdir
             #: use this name in the archive (aka rename)
             #: use this name in the archive (aka rename)
@@ -362,24 +363,22 @@ class Backup(object):
             subdir = 'vm%d/' % vm.qid
             subdir = 'vm%d/' % vm.qid
 
 
             vm_files = []
             vm_files = []
-            if vm.volumes['private'] is not None:
-                path_to_private_img = vm.storage.export('private')
-                vm_files.append(self.FileToBackup(path_to_private_img, subdir,
-                        'private.img'))
+            for name, volume in vm.volumes.items():
+                if not volume.save_on_stop:
+                    continue
+                vm_files.append(self.FileToBackup(
+                    volume.export(),
+                    subdir,
+                    name + '.img',
+                    volume.usage))
 
 
-            vm_files.append(self.FileToBackup(vm.icon_path, subdir))
             vm_files.extend(self.FileToBackup(i, subdir)
             vm_files.extend(self.FileToBackup(i, subdir)
                 for i in vm.fire_event('backup-get-files'))
                 for i in vm.fire_event('backup-get-files'))
 
 
-            # TODO: drop after merging firewall.xml into qubes.xml
             firewall_conf = os.path.join(vm.dir_path, vm.firewall_conf)
             firewall_conf = os.path.join(vm.dir_path, vm.firewall_conf)
             if os.path.exists(firewall_conf):
             if os.path.exists(firewall_conf):
                 vm_files.append(self.FileToBackup(firewall_conf, subdir))
                 vm_files.append(self.FileToBackup(firewall_conf, subdir))
 
 
-            if vm.updateable:
-                path_to_root_img = vm.storage.export('root')
-                vm_files.append(self.FileToBackup(path_to_root_img, subdir,
-                    'root.img'))
             files_to_backup[vm.qid] = self.VMToBackup(vm, vm_files, subdir)
             files_to_backup[vm.qid] = self.VMToBackup(vm, vm_files, subdir)
 
 
         # Dom0 user home
         # Dom0 user home