def __do_backup__(self, thread_monitor): msg = [] try: backup.backup_do(unicode(self.dir_line_edit.text()), self.files_to_backup, unicode(self.passphrase_line_edit.text()), progress_callback=self.update_progress_bar, encrypted=self.encryption_checkbox.isChecked(), appvm=self.target_appvm) #simulate_long_lasting_proces(10, self.update_progress_bar) except backup.BackupCanceledError as ex: msg.append(str(ex)) self.canceled = True if ex.tmpdir: self.tmpdir_to_remove = ex.tmpdir except Exception as ex: print "Exception:",ex msg.append(str(ex)) if len(msg) > 0 : thread_monitor.set_error_msg('\n'.join(msg)) thread_monitor.set_finished()
def __do_backup__(self, thread_monitor): msg = [] try: backup.backup_do(unicode(self.dir_line_edit.text()), self.files_to_backup, unicode(self.passphrase_line_edit.text()), progress_callback=self.update_progress_bar, encrypted=self.encryption_checkbox.isChecked(), appvm=self.target_appvm) #simulate_long_lasting_proces(10, self.update_progress_bar) except backup.BackupCanceledError as ex: msg.append(str(ex)) self.canceled = True if ex.tmpdir: self.tmpdir_to_remove = ex.tmpdir except Exception as ex: print "Exception:", ex msg.append(str(ex)) if len(msg) > 0: thread_monitor.set_error_msg('\n'.join(msg)) thread_monitor.set_finished()
def make_backup(self, vms, target=None, expect_failure=False, **kwargs): if target is None: target = self.backupdir try: backup = qubes.backup.Backup(self.app, vms, **kwargs) except qubes.exc.QubesException as e: if not expect_failure: self.fail("QubesException during backup_prepare: %s" % str(e)) else: raise if 'passphrase' not in kwargs: backup.passphrase = 'qubes' backup.target_dir = target try: self.loop.run_until_complete(backup.backup_do()) except qubes.exc.QubesException as e: if not expect_failure: self.fail("QubesException during backup_do: %s" % str(e)) else: raise
def main(args=None): args = parser.parse_args(args) appvm = None if args.appvm: try: appvm = args.app.domains[args.appvm] except KeyError: parser.error('no such domain: {!r}'.format(args.appvm)) args.app.log.info(("NOTE: VM {} will be excluded because it is " "the backup destination.").format(args.appvm)) if appvm: args.exclude_list.append(appvm.name) if args.appvm or args.crypto_algorithm: args.encrypted = True if args.no_encrypt: args.encrypted = False try: backup = qubes.backup.Backup(args.app, args.domains if args.domains else None, exclude_list=args.exclude_list) except qubes.exc.QubesException as e: parser.error_runtime(str(e)) # unreachable - error_runtime will raise SystemExit return 1 backup.target_dir = args.backup_location if not appvm: if os.path.isdir(args.backup_location): stat = os.statvfs(args.backup_location) else: stat = os.statvfs(os.path.dirname(args.backup_location)) backup_fs_free_sz = stat.f_bsize * stat.f_bavail print() if backup.total_backup_bytes > backup_fs_free_sz: parser.error_runtime("Not enough space available on the " "backup filesystem!") args.app.log.info("Available space: {0}".format( qubes.utils.size_to_human(backup_fs_free_sz))) else: stat = os.statvfs('/var/tmp') backup_fs_free_sz = stat.f_bsize * stat.f_bavail print() if backup_fs_free_sz < 1000000000: parser.error_runtime("Not enough space available " "on the local filesystem (1GB required for temporary files)!") if not appvm.is_running(): appvm.start() if not args.encrypted: args.app.log.info("WARNING: The backup will NOT be encrypted!") if args.pass_file is not None: pass_f = open(args.pass_file) if args.pass_file != "-" else sys.stdin passphrase = pass_f.readline().rstrip() if pass_f is not sys.stdin: pass_f.close() else: if input("Do you want to proceed? [y/N] ").upper() != "Y": return 0 prompt = ("Please enter the passphrase that will be used to {}verify " "the backup: ").format('encrypt and ' if args.encrypted else '') passphrase = getpass.getpass(prompt) if getpass.getpass("Enter again for verification: ") != passphrase: parser.error_runtime("Passphrase mismatch!") backup.encrypted = args.encrypted backup.compressed = args.compressed if args.compression_filter: backup.compression_filter = args.compression_filter encoding = sys.stdin.encoding or locale.getpreferredencoding() backup.passphrase = passphrase.decode(encoding) if args.hmac_algorithm: backup.hmac_algorithm = args.hmac_algorithm if args.crypto_algorithm: backup.crypto_algorithm = args.crypto_algorithm if args.tmpdir: backup.tmpdir = args.tmpdir if appvm: backup.target_vm = appvm try: backup.backup_do() except qubes.exc.QubesException as e: parser.error_runtime(str(e)) print() args.app.log.info("Backup completed.") return 0