def prepare(cls, profile): """ Prepare for running Borg. This function in the base class should be called from all subclasses and calls that define their own `cmd`. The `prepare()` step does these things: - validate if all conditions to run command are met - build borg command `prepare()` is run 2x. First at the global level and then for each subcommand. :return: dict(ok: book, message: str) """ ret = {'ok': False} # Do checks to see if running Borg is possible. if cls.is_running(): ret['message'] = trans_late('messages', 'Backup is already in progress.') return ret if cls.prepare_bin() is None: ret['message'] = trans_late('messages', 'Borg binary was not found.') return ret if profile.repo is None: ret['message'] = trans_late('messages', 'Add a backup repository first.') return ret # Try to get password from chosen keyring backend. logger.debug("Using %s keyring to store passwords.", keyring.__class__.__name__) ret['password'] = keyring.get_password('vorta-repo', profile.repo.url) # Try to fall back to DB Keyring, if we use the system keychain. if ret['password'] is None and keyring.is_primary: logger.debug( 'Password not found in primary keyring. Falling back to VortaDBKeyring.' ) ret['password'] = VortaDBKeyring().get_password( 'vorta-repo', profile.repo.url) # Give warning and continue if password is found there. if ret['password'] is not None: logger.warning( 'Found password in database, but secure storage was available. ' 'Consider re-adding the repo to use it.') ret['ssh_key'] = profile.ssh_key ret['repo_id'] = profile.repo.id ret['repo_url'] = profile.repo.url ret['extra_borg_arguments'] = profile.repo.extra_borg_arguments ret['profile_name'] = profile.name ret['ok'] = True return ret
def prepare(cls, profile): """ Prepare for running Borg. This function in the base class should be called from all subclasses and calls that define their own `cmd`. The `prepare()` step does these things: - validate if all conditions to run command are met - build borg command `prepare()` is run 2x. First at the global level and then for each subcommand. :return: dict(ok: book, message: str) """ ret = {'ok': False} if cls.prepare_bin() is None: ret['message'] = trans_late('messages', 'Borg binary was not found.') return ret if profile.repo is None: ret['message'] = trans_late('messages', 'Add a backup repository first.') return ret if not borg_compat.check('JSON_LOG'): ret['message'] = trans_late('messages', 'Your Borg version is too old. >=1.1.0 is required.') return ret # Try to get password from chosen keyring backend. with keyring_lock: cls.keyring = VortaKeyring.get_keyring() logger.debug("Using %s keyring to store passwords.", cls.keyring.__class__.__name__) ret['password'] = cls.keyring.get_password('vorta-repo', profile.repo.url) # Check if keyring is locked if profile.repo.encryption != 'none' and not cls.keyring.is_unlocked: ret['message'] = trans_late('messages', 'Please unlock your system password manager or disable it under Misc') return ret # Try to fall back to DB Keyring, if we use the system keychain. if ret['password'] is None and cls.keyring.is_system: logger.debug('Password not found in primary keyring. Falling back to VortaDBKeyring.') ret['password'] = VortaDBKeyring().get_password('vorta-repo', profile.repo.url) # Give warning and continue if password is found there. if ret['password'] is not None: logger.warning('Found password in database, but secure storage was available. ' 'Consider re-adding the repo to use it.') # Password is required for encryption, cannot continue if ret['password'] is None and not isinstance(profile.repo, FakeRepo) and profile.repo.encryption != 'none': ret['message'] = trans_late( 'messages', "Your repo passphrase was stored in a password manager which is no longer available.\n" "Try unlinking and re-adding your repo.") return ret ret['ssh_key'] = profile.ssh_key ret['repo_id'] = profile.repo.id ret['repo_url'] = profile.repo.url ret['extra_borg_arguments'] = profile.repo.extra_borg_arguments ret['profile_name'] = profile.name ret['profile_id'] = profile.id ret['ok'] = True return ret