backup: code cleanup
This commit is contained in:
parent
89fde55cd9
commit
5edca4ac90
@ -1249,16 +1249,11 @@ def backup_restore_header(restore_target, encrypt=False, appvm=None):
|
|||||||
fp = open(restore_target,'rb')
|
fp = open(restore_target,'rb')
|
||||||
headers = fp.read(4096*4)
|
headers = fp.read(4096*4)
|
||||||
|
|
||||||
is_encrypted = False
|
if encrypt:
|
||||||
|
|
||||||
command = subprocess.Popen(['file','-'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
stdout,stderr = command.communicate(headers)
|
|
||||||
if not stdout.find('gzip compressed data') >= 0:
|
|
||||||
command = subprocess.Popen(['gpg2','--decrypt'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
command = subprocess.Popen(['gpg2','--decrypt'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||||
stdout,stderr = command.communicate(headers)
|
stdout,stderr = command.communicate(headers)
|
||||||
if len(stdout) > 0:
|
if len(stdout) > 0:
|
||||||
headers = stdout
|
headers = stdout
|
||||||
is_encrypted = True
|
|
||||||
else:
|
else:
|
||||||
print stderr
|
print stderr
|
||||||
raise QubesException("ERROR: unable to decrypt the backup {0}. Is it really encrypted?".format(restore_target))
|
raise QubesException("ERROR: unable to decrypt the backup {0}. Is it really encrypted?".format(restore_target))
|
||||||
@ -1280,26 +1275,13 @@ def backup_restore_header(restore_target, encrypt=False, appvm=None):
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
return is_encrypted, vms_in_backup, headers
|
return vms_in_backup, headers
|
||||||
|
|
||||||
def backup_restore_prepare(backup_dir, backup_content, qubes_xml, options = {}, host_collection = None, encrypt=False, appvm=None):
|
def backup_restore_prepare(backup_dir, backup_content, qubes_xml, options = {}, host_collection = None, encrypt=False, appvm=None):
|
||||||
# Defaults
|
# Defaults
|
||||||
backup_restore_set_defaults(options)
|
backup_restore_set_defaults(options)
|
||||||
|
|
||||||
#### Private functions begin
|
#### Private functions begin
|
||||||
'''
|
|
||||||
def is_vm_included_in_backup (backup_dir, vm):
|
|
||||||
if vm.qid == 0:
|
|
||||||
# Dom0 is not included, obviously
|
|
||||||
return False
|
|
||||||
|
|
||||||
backup_vm_dir_path = vm.dir_path.replace (qubes_base_dir, backup_dir)
|
|
||||||
|
|
||||||
if os.path.exists (backup_vm_dir_path):
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
'''
|
|
||||||
def is_vm_included_in_backup (backup_dir, vm):
|
def is_vm_included_in_backup (backup_dir, vm):
|
||||||
for item in backup_content.keys():
|
for item in backup_content.keys():
|
||||||
if vm.name == item:
|
if vm.name == item:
|
||||||
@ -1313,12 +1295,8 @@ def backup_restore_prepare(backup_dir, backup_content, qubes_xml, options = {},
|
|||||||
return m.group(2)
|
return m.group(2)
|
||||||
|
|
||||||
return template
|
return template
|
||||||
|
|
||||||
#### Private functions end
|
#### Private functions end
|
||||||
'''
|
|
||||||
if not os.path.exists (backup_dir):
|
|
||||||
raise QubesException("The backup directory doesn't exist!")
|
|
||||||
'''
|
|
||||||
backup_collection = QubesVmCollection()
|
backup_collection = QubesVmCollection()
|
||||||
import StringIO
|
import StringIO
|
||||||
backup_collection.qubes_store_file=StringIO.StringIO(qubes_xml)
|
backup_collection.qubes_store_file=StringIO.StringIO(qubes_xml)
|
||||||
|
Loading…
Reference in New Issue
Block a user