backup/restore: improve error reporting

This commit is contained in:
Marek Marczykowski-Górecki 2017-07-29 04:48:46 +02:00
parent 07cffc340c
commit 213760f263
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -971,10 +971,12 @@ class BackupRestore(object):
"ERROR: verify file {0}: {1}".format(filename, hmac_stderr)) "ERROR: verify file {0}: {1}".format(filename, hmac_stderr))
else: else:
self.log.debug("Loading hmac for file %s", filename) self.log.debug("Loading hmac for file %s", filename)
try:
with open(os.path.join(self.tmpdir, hmacfile), 'r', with open(os.path.join(self.tmpdir, hmacfile), 'r',
encoding='ascii') as f_hmac: encoding='ascii') as f_hmac:
hmac = load_hmac(f_hmac.read()) hmac = load_hmac(f_hmac.read())
except UnicodeDecodeError as err:
raise QubesException('Cannot load hmac file: ' + str(err))
if hmac and load_hmac(hmac_stdout.decode('ascii')) == hmac: if hmac and load_hmac(hmac_stdout.decode('ascii')) == hmac:
os.unlink(os.path.join(self.tmpdir, hmacfile)) os.unlink(os.path.join(self.tmpdir, hmacfile))
self.log.debug( self.log.debug(
@ -1753,14 +1755,13 @@ class BackupRestore(object):
try: try:
self._restore_vm_data(vms_dirs=vms_dirs, vms_size=vms_size, self._restore_vm_data(vms_dirs=vms_dirs, vms_size=vms_size,
handlers=handlers) handlers=handlers)
except QubesException: except QubesException as err:
if self.options.verify_only: if self.options.verify_only:
raise raise
else: else:
self.log.error('Error extracting data: ' + str(err))
self.log.warning( self.log.warning(
"Some errors occurred during data extraction, " "Continuing anyway to restore at least some VMs")
"continuing anyway to restore at least some "
"VMs")
if self.options.verify_only: if self.options.verify_only:
shutil.rmtree(self.tmpdir) shutil.rmtree(self.tmpdir)