Ejemplo n.º 1
0
def restore_data(storage, path=''):
  """ Restores the Cassandra backup.

  Args:
    storage: A str, one of the StorageTypes class members.
    path: A str, the name of the backup file to restore from.
  Returns:
    True on success, False otherwise.
  """
  if storage not in StorageTypes().get_storage_types():
    logging.error("Storage '{0}' not supported.")
    return False

  logging.info("Starting new db restore.")

  if storage == StorageTypes.GCS:
    # Download backup file and store locally with a fixed name.
    if not gcs_helper.download_from_bucket(path,
        CASSANDRA_BACKUP_FILE_LOCATION):
      logging.error("Download from GCS failed. Aborting recovery...")
      return False

  # TODO Make sure there's a snapshot to rollback to if restore fails.
  # Not pressing for fresh deployments.
  # create_snapshot('rollback-snapshot')

  if not shut_down_cassandra.run():
    logging.error("Unable to shut down Cassandra. Aborting restore...")
    if storage == StorageTypes.GCS:
      backup_recovery_helper.\
        delete_local_backup_file(CASSANDRA_BACKUP_FILE_LOCATION)
    return False

  remove_old_data()
  try:
    backup_recovery_helper.untar_backup_files(CASSANDRA_BACKUP_FILE_LOCATION)
  except backup_exceptions.BRException as br_exception:
    logging.exception("Error while unpacking backup files. Exception: {0}".
      format(str(br_exception)))
    start_cassandra.run()
    if storage == StorageTypes.GCS:
      backup_recovery_helper.\
        delete_local_backup_file(CASSANDRA_BACKUP_FILE_LOCATION)
    return False
  restore_snapshots()

  # Start Cassandra and repair.
  logging.info("Starting Cassandra.")
  start_cassandra.run()
  refresh_data()

  # Local cleanup.
  clear_old_snapshots()
  if storage == StorageTypes.GCS:
    backup_recovery_helper.\
      delete_local_backup_file(CASSANDRA_BACKUP_FILE_LOCATION)

  logging.info("Done with db restore.")
  return True
Ejemplo n.º 2
0
def restore_data(storage, path=''):
    """ Restores the Zookeeper snapshot.

  Args:
    storage: A str, one of the StorageTypes class members.
    path: A str, the name of the backup file to restore from.
  """
    if storage not in StorageTypes().get_storage_types():
        logging.error("Storage '{0}' not supported.")
        return False

    logging.info("Starting new zk restore.")

    if storage == StorageTypes.GCS:
        # Download backup file and store locally with a fixed name.
        if not gcs_helper.download_from_bucket(path,
                                               ZOOKEEPER_BACKUP_FILE_LOCATION):
            logging.error("Download from GCS failed. Aborting recovery...")
            return False

    # TODO Make sure there's a snapshot to rollback to if restore fails.
    # Not pressing for fresh deployments.

    flush_zk()
    try:
        backup_recovery_helper.untar_backup_files(
            ZOOKEEPER_BACKUP_FILE_LOCATION)
    except backup_exceptions.BRException as br_exception:
        logging.exception(
            "Error while unpacking backup files. Exception: {0}".format(
                str(br_exception)))
        if storage == StorageTypes.GCS:
            backup_recovery_helper.\
              delete_local_backup_file(ZOOKEEPER_BACKUP_FILE_LOCATION)
        return False
    restore_zk(TMP_ZOOKEEPER_BACKUP)

    # Local cleanup.
    backup_recovery_helper.remove(TMP_ZOOKEEPER_BACKUP)
    if storage == StorageTypes.GCS:
        backup_recovery_helper.\
          delete_local_backup_file(ZOOKEEPER_BACKUP_FILE_LOCATION)

    logging.info("Done with zk restore.")
    return True
Ejemplo n.º 3
0
def restore_data(storage, path=''):
  """ Restores the Zookeeper snapshot.

  Args:
    storage: A str, one of the StorageTypes class members.
    path: A str, the name of the backup file to restore from.
  """
  if storage not in StorageTypes().get_storage_types():
    logging.error("Storage '{0}' not supported.")
    return False

  logging.info("Starting new zk restore.")

  if storage == StorageTypes.GCS:
    # Download backup file and store locally with a fixed name.
    if not gcs_helper.download_from_bucket(path,
        ZOOKEEPER_BACKUP_FILE_LOCATION):
      logging.error("Download from GCS failed. Aborting recovery...")
      return False

  # TODO Make sure there's a snapshot to rollback to if restore fails.
  # Not pressing for fresh deployments.

  flush_zk()
  try:
    backup_recovery_helper.untar_backup_files(ZOOKEEPER_BACKUP_FILE_LOCATION)
  except backup_exceptions.BRException as br_exception:
    logging.exception("Error while unpacking backup files. Exception: {0}".
      format(str(br_exception)))
    if storage == StorageTypes.GCS:
      backup_recovery_helper.\
        delete_local_backup_file(ZOOKEEPER_BACKUP_FILE_LOCATION)
    return False
  restore_zk(TMP_ZOOKEEPER_BACKUP)

  # Local cleanup.
  backup_recovery_helper.remove(TMP_ZOOKEEPER_BACKUP)
  if storage == StorageTypes.GCS:
    backup_recovery_helper.\
      delete_local_backup_file(ZOOKEEPER_BACKUP_FILE_LOCATION)

  logging.info("Done with zk restore.")
  return True