backups: fix backup of templates

Template is saved as single archive of the whole VM directory. Preserve
backup directory structure regardless of its content - in this case it
means we need "." archive (with template directory content) placed in
"vm-tempates/<template-name>/" backup directory. This allows restore
process to select right files to restore regardless of VM type.
This commit is contained in:
Marek Marczykowski-Górecki 2013-11-26 16:46:34 +01:00
parent 50662bf090
commit 2d68b79bff

View File

@ -170,7 +170,14 @@ def backup_prepare(vms_list = None, exclude_list = [], print_callback = print_st
# already handled # already handled
continue continue
vm_sz = vm.get_disk_utilization() vm_sz = vm.get_disk_utilization()
files_to_backup += file_to_backup (vm.dir_path, vm_sz) template_subdir = os.path.relpath(
vm.dir_path,
system_path["qubes_base_dir"]) + '/'
template_to_backup = [ {
"path": vm.dir_path + '/.',
"size": vm_sz,
"subdir": template_subdir } ]
files_to_backup += template_to_backup
s = "" s = ""
fmt="{{0:>{0}}} |".format(fields_to_display[0]["width"] + 1) fmt="{{0:>{0}}} |".format(fields_to_display[0]["width"] + 1)
@ -258,6 +265,10 @@ def backup_prepare(vms_list = None, exclude_list = [], print_callback = print_st
if (there_are_running_vms): if (there_are_running_vms):
raise QubesException("Please shutdown all VMs before proceeding.") raise QubesException("Please shutdown all VMs before proceeding.")
for fileinfo in files_to_backup:
assert len(fileinfo["subdir"]) == 0 or fileinfo["subdir"][-1] == '/', \
"'subdir' must ends with a '/': %s" % str(fileinfo)
return files_to_backup return files_to_backup
class Send_Worker(Process): class Send_Worker(Process):
@ -383,7 +394,7 @@ def backup_do(base_backup_dir, files_to_backup, passphrase,\
"-f", backup_pipe, "-f", backup_pipe,
'--tape-length', str(100000), '--tape-length', str(100000),
'-C', os.path.dirname(filename["path"]), '-C', os.path.dirname(filename["path"]),
'--xform', 's:^[a-z]:%s\\0:' % filename["subdir"], '--xform', 's:^[^/]:%s\\0:' % filename["subdir"],
os.path.basename(filename["path"]) os.path.basename(filename["path"])
] ]