def test_get_stream(mock_popen, input_file, keyring_file): recipient = '*****@*****.**' with open(str(input_file)) as stream: gpg = Gpg(stream, recipient, str(keyring_file)) with gpg.get_stream() as s: cmd = [ 'gpg', '--no-default-keyring', '--trust-model', 'always', '--keyring', gpg.keyring, '--recipient', gpg.recipient, '--encrypt', '--yes', '--batch' ] mock_popen.assert_called_once_with(cmd, stdin=gpg.input, stdout=PIPE, stderr=PIPE)
def backup_files(run_type, config): """Backup local directories :param run_type: Run type :type run_type: str :param config: Configuration :type config: ConfigParser.ConfigParser """ for directory in get_directories_to_backup(config): LOG.debug('copying %s', directory) src = FileSource(directory, run_type) dst = get_destination(config) stream = src.get_stream() # Gzip modifier stream = Gzip(stream).get_stream() src.suffix += '.gz' # KeepLocal modifier try: keep_local_path = config.get('destination', 'keep_local_path') # src.suffix = 'tar.gz.aaa' dst_name = src.get_name() kl_modifier = KeepLocal(stream, os.path.join(keep_local_path, dst_name)) stream = kl_modifier.get_stream() except ConfigParser.NoOptionError: pass # GPG modifier try: keyring = config.get('gpg', 'keyring') recipient = config.get('gpg', 'recipient') gpg = Gpg(stream, recipient, keyring) stream = gpg.get_stream() src.suffix += '.gpg' except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): pass except ModifierException as err: LOG.warning(err) LOG.warning('Will skip encryption') dst.save(stream, src.get_name()) src.apply_retention_policy(dst, config, run_type)
def _backup_stream(config, src, dst, callbacks=None): """ :param config: Tool config :type config: TwinDBBackupConfig :param src: :param dst: :param callbacks: :return: """ stream = src.get_stream() # Compression modifier cmp_modifier = config.compression.get_modifier(stream) stream = cmp_modifier.get_stream() src.suffix += cmp_modifier.suffix # KeepLocal modifier if config.keep_local_path: keep_local_path = config.keep_local_path kl_modifier = KeepLocal( stream, osp.join( keep_local_path, src.get_name() ) ) stream = kl_modifier.get_stream() if callbacks is not None: callbacks.append((kl_modifier, { 'keep_local_path': keep_local_path, 'dst': dst })) else: LOG.debug('keep_local_path is not present in the config file') # GPG modifier if config.gpg: gpg_modifier = Gpg( stream, config.gpg.recipient, config.gpg.keyring ) stream = gpg_modifier.get_stream() src.suffix += '.gpg' dst.save(stream, src.get_name())
def _backup_stream(config, src, dst, callbacks=None): """ :param config: Tool config :type config: TwinDBBackupConfig :param src: :param dst: :param callbacks: :return: """ stream = src.get_stream() # Compression modifier cmp_modifier = config.compression.get_modifier(stream) stream = cmp_modifier.get_stream() src.suffix += cmp_modifier.suffix # KeepLocal modifier if config.keep_local_path: keep_local_path = config.keep_local_path kl_modifier = KeepLocal(stream, osp.join(keep_local_path, src.get_name())) stream = kl_modifier.get_stream() if callbacks is not None: callbacks.append((kl_modifier, { "keep_local_path": keep_local_path, "dst": dst })) else: LOG.debug("keep_local_path is not present in the config file") # GPG modifier if config.gpg: gpg_modifier = Gpg(stream, config.gpg.recipient, config.gpg.keyring) stream = gpg_modifier.get_stream() src.suffix += ".gpg" dst.save(stream, src.get_name())