dom0: edit qvm-backup to use backup_do_copy, throw error when appvm is not found

This commit is contained in:
Andrew Sorensen 2013-06-22 18:02:40 -07:00
parent 65822f6033
commit 7cacc3db48
2 changed files with 12 additions and 3 deletions

View File

@ -1005,6 +1005,15 @@ def backup_do(base_backup_dir, files_to_backup, progress_callback = None):
def backup_do_copy(appvm, base_backup_dir, files_to_backup, progress_callback = None): def backup_do_copy(appvm, base_backup_dir, files_to_backup, progress_callback = None):
# does the vm exist?
qvm_collection = QubesVmCollection()
qvm_collection.lock_db_for_reading()
qvm_collection.load()
vm = qvm_collection.get_vm_by_name(appvm)
if vm is None or vm.qid not in qvm_collection:
raise QubesException("VM {0} does not exist".format(appvm))
total_backup_sz = 0 total_backup_sz = 0
for file in files_to_backup: for file in files_to_backup:
total_backup_sz += file["size"] total_backup_sz += file["size"]
@ -1026,7 +1035,7 @@ def backup_do_copy(appvm, base_backup_dir, files_to_backup, progress_callback =
progress_callback(progress) progress_callback(progress)
dest_dir = backup_dir + '/' + file["subdir"] dest_dir = backup_dir + '/' + file["subdir"]
if file["subdir"] != "": if file["subdir"] != "":
retcode = subprocess.call (["qvm-run", "-p", appvm, "mkdir -p " + dest_dir]) retcode = vm.run(["qvm-run", "-p", appvm, "mkdir -p " + dest_dir])
if retcode != 0: if retcode != 0:
raise QubesException("Cannot create directory: {0}?!".format(dest_dir)) raise QubesException("Cannot create directory: {0}?!".format(dest_dir))

View File

@ -22,7 +22,7 @@
from qubes.qubes import QubesVmCollection from qubes.qubes import QubesVmCollection
from qubes.qubes import QubesException from qubes.qubes import QubesException
from qubes.qubesutils import backup_prepare, backup_do from qubes.qubesutils import backup_prepare, backup_do_copy
from optparse import OptionParser from optparse import OptionParser
import os import os
import sys import sys
@ -72,7 +72,7 @@ def main():
exit (0) exit (0)
try: try:
backup_do(base_backup_dir, files_to_backup, progress_callback=print_progress) backup_do_copy("storage", base_backup_dir, files_to_backup, progress_callback=print_progress)
except QubesException as e: except QubesException as e:
print >>sys.stderr, "ERROR: %s" % str(e) print >>sys.stderr, "ERROR: %s" % str(e)
exit(1) exit(1)