Exemplo n.º 1
0
def backup_data():
    """
  Backs up the knox data as part of the upgrade process.
  :return: Returns the path to the absolute backup directory.
  """
    Logger.info('Backing up Knox data directory before upgrade...')
    directoryMappings = _get_directory_mappings_during_upgrade()

    absolute_backup_dir = os.path.join(tempfile.gettempdir(), BACKUP_TEMP_DIR)
    if not os.path.isdir(absolute_backup_dir):
        os.makedirs(absolute_backup_dir)

    for directory in directoryMappings:
        if not os.path.isdir(directory):
            raise Fail(
                "Unable to backup missing directory {0}".format(directory))

        archive = os.path.join(absolute_backup_dir,
                               directoryMappings[directory])
        Logger.info('Compressing {0} to {1}'.format(directory, archive))

        if os.path.exists(archive):
            os.remove(archive)

        # backup the directory, following symlinks instead of including them
        tar_archive.archive_directory_dereference(archive, directory)

    return absolute_backup_dir
Exemplo n.º 2
0
def post_stop_backup():
    """
  Backs up the flume config, config dir, file/spillable channels as part of the
  upgrade process.
  :return:
  """
    Logger.info('Backing up Flume data and configuration before upgrade...')
    directoryMappings = _get_directory_mappings()

    absolute_backup_dir = os.path.join(tempfile.gettempdir(), BACKUP_TEMP_DIR)
    if not os.path.isdir(absolute_backup_dir):
        os.makedirs(absolute_backup_dir)

    for directory in directoryMappings:
        if not os.path.isdir(directory):
            raise Fail(
                "Unable to backup missing directory {0}".format(directory))

        archive = os.path.join(absolute_backup_dir,
                               directoryMappings[directory])
        Logger.info('Compressing {0} to {1}'.format(directory, archive))

        if os.path.exists(archive):
            os.remove(archive)

        # backup the directory, following symlinks instead of including them
        tar_archive.archive_directory_dereference(archive, directory)
Exemplo n.º 3
0
def backup_data():
  """
  Backs up the knox data as part of the upgrade process.
  :return: Returns the path to the absolute backup directory.
  """
  Logger.info('Backing up Knox data directory before upgrade...')
  directoryMappings = _get_directory_mappings_during_upgrade()

  Logger.info("Directory mappings to backup: {0}".format(str(directoryMappings)))

  absolute_backup_dir = os.path.join(tempfile.gettempdir(), BACKUP_TEMP_DIR)
  if not os.path.isdir(absolute_backup_dir):
    os.makedirs(absolute_backup_dir)

  for directory in directoryMappings:
    if not os.path.isdir(directory):
      raise Fail("Unable to backup missing directory {0}".format(directory))

    archive = os.path.join(absolute_backup_dir, directoryMappings[directory])
    Logger.info('Compressing {0} to {1}'.format(directory, archive))

    if os.path.exists(archive):
      os.remove(archive)

    # backup the directory, following symlinks instead of including them
    tar_archive.archive_directory_dereference(archive, directory)

  return absolute_backup_dir
Exemplo n.º 4
0
def post_stop_backup():
  """
  Backs up the flume config, config dir, file/spillable channels as part of the
  upgrade process.
  :return:
  """
  Logger.info('Backing up Flume data and configuration before upgrade...')
  directoryMappings = _get_directory_mappings()

  absolute_backup_dir = os.path.join(tempfile.gettempdir(), BACKUP_TEMP_DIR)
  if not os.path.isdir(absolute_backup_dir):
    os.makedirs(absolute_backup_dir)

  for directory in directoryMappings:
    if not os.path.isdir(directory):
      raise Fail("Unable to backup missing directory {0}".format(directory))

    archive = os.path.join(absolute_backup_dir, directoryMappings[directory])
    Logger.info('Compressing {0} to {1}'.format(directory, archive))

    if os.path.exists(archive):
      os.remove(archive)

    # backup the directory, following symlinks instead of including them
    tar_archive.archive_directory_dereference(archive, directory)
Exemplo n.º 5
0
def post_stop_backup():
    """
    Backs up beacon directories as part of the upgrade process.
    :return:
    """
    Logger.info('Backing up Beacon directories before upgrade...')
    directoryMappings = _get_directory_mappings()

    absolute_backup_dir = os.path.join(tempfile.gettempdir(), BACKUP_TEMP_DIR)
    if not os.path.isdir(absolute_backup_dir):
        os.makedirs(absolute_backup_dir)

    for directory in directoryMappings:
        if not os.path.isdir(directory):
            raise Fail(
                "Unable to backup missing directory {0}".format(directory))

        archive = os.path.join(absolute_backup_dir,
                               directoryMappings[directory])
        Logger.info('Compressing {0} to {1}'.format(directory, archive))

        if os.path.exists(archive):
            os.remove(archive)

        tar_archive.archive_directory_dereference(archive, directory)
Exemplo n.º 6
0
    def test_archive_directory_dereference(self, execute_mock):
        archive = '/home/etc.tar.gz'
        directory = '/etc'

        with Environment():
            tar_archive.archive_directory_dereference(archive, directory)

        self.assertEqual(execute_mock.call_count, 1)
        self.assertEqual(execute_mock.call_args[0][0].command,
                         ('tar', '-zchf', archive, '-C', directory, '.'))