dom0/qvm-backup: Support for NetVMs backup (#345)
This commit is contained in:
parent
02ca39458a
commit
fde8bc35fa
@ -88,6 +88,7 @@ def main():
|
||||
files_to_backup = file_to_backup (qubes_store_filename)
|
||||
|
||||
appvms_to_backup = [vm for vm in vms_list if vm.is_appvm() and not vm.name.endswith('-dvm')]
|
||||
netvms_to_backup = [vm for vm in vms_list if vm.is_netvm()]
|
||||
there_are_running_vms = False
|
||||
|
||||
fields_to_display = [
|
||||
@ -113,8 +114,8 @@ def main():
|
||||
s += fmt.format('-')
|
||||
print s
|
||||
|
||||
if len (appvms_to_backup):
|
||||
for vm in appvms_to_backup:
|
||||
if len (appvms_to_backup + netvms_to_backup):
|
||||
for vm in appvms_to_backup + netvms_to_backup:
|
||||
|
||||
vm_sz = vm.get_disk_usage (vm.private_img)
|
||||
files_to_backup += file_to_backup(vm.private_img, vm_sz )
|
||||
@ -148,7 +149,10 @@ def main():
|
||||
s += fmt.format(vm.name)
|
||||
|
||||
fmt="{{0:>{0}}} |".format(fields_to_display[1]["width"] + 1)
|
||||
s += fmt.format("AppVM" + (" + Sys" if vm.is_updateable() else ""))
|
||||
if vm.is_netvm():
|
||||
s += fmt.format("NetVM" + (" + Sys" if vm.is_updateable() else ""))
|
||||
else:
|
||||
s += fmt.format("AppVM" + (" + Sys" if vm.is_updateable() else ""))
|
||||
|
||||
fmt="{{0:>{0}}} |".format(fields_to_display[2]["width"] + 1)
|
||||
s += fmt.format(size_to_human(vm_sz))
|
||||
|
@ -26,6 +26,7 @@ from qubes.qubes import qubes_store_filename
|
||||
from qubes.qubes import qubes_base_dir
|
||||
from qubes.qubes import qubes_templates_dir
|
||||
from qubes.qubes import qubes_appvms_dir
|
||||
from qubes.qubes import qubes_servicevms_dir
|
||||
from optparse import OptionParser
|
||||
|
||||
import os
|
||||
@ -321,6 +322,56 @@ def main():
|
||||
host_collection.pop(vm.qid)
|
||||
continue
|
||||
|
||||
# ... then NetVMs...
|
||||
for vm in [ vm for vm in vms_to_restore if vm.is_netvm()]:
|
||||
|
||||
print "-> Restoring NetVM {0}...".format(vm.name)
|
||||
retcode = subprocess.call (["mkdir", "-p", vm.dir_path])
|
||||
if retcode != 0:
|
||||
print ("*** Cannot create directory: {0}?!".format(dest_dir))
|
||||
print ("Skiping...")
|
||||
continue
|
||||
|
||||
restore_vm_dir (backup_dir, vm.dir_path, qubes_servicevms_dir);
|
||||
|
||||
template_vm = None
|
||||
if vm.template_vm is not None:
|
||||
template_name = find_template_name(vm.template_vm.name, options.replace_template)
|
||||
template_vm = host_collection.get_vm_by_name(template_name)
|
||||
|
||||
if not vm.uses_default_netvm:
|
||||
uses_default_netvm = False
|
||||
netvm_vm = host_collection.get_vm_by_name (vm.netvm_vm.name) if vm.netvm_vm is not None else None
|
||||
else:
|
||||
uses_default_netvm = True
|
||||
|
||||
updateable = vm.updateable
|
||||
|
||||
try:
|
||||
vm = host_collection.add_new_netvm(vm.name, template_vm,
|
||||
conf_file=vm.conf_file,
|
||||
dir_path=vm.dir_path,
|
||||
updateable=updateable,
|
||||
label=vm.label)
|
||||
except Exception as err:
|
||||
print "ERROR: {0}".format(err)
|
||||
print "*** Skiping VM: {0}".format(vm.name)
|
||||
if vm:
|
||||
host_collection.pop(vm.qid)
|
||||
continue
|
||||
|
||||
if not uses_default_netvm:
|
||||
vm.uses_default_netvm = False
|
||||
vm.netvm_vm = netvm_vm
|
||||
|
||||
try:
|
||||
vm.verify_files()
|
||||
except Exception as err:
|
||||
print "ERROR: {0}".format(err)
|
||||
print "*** Skiping VM: {0}".format(vm.name)
|
||||
host_collection.pop(vm.qid)
|
||||
continue
|
||||
|
||||
# ... then appvms...
|
||||
for vm in [ vm for vm in vms_to_restore if vm.is_appvm()]:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user