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
def shutdown_datastore(): """ Top level function for bringing down Cassandra. Returns: True on success, False otherwise. """ success = shut_down_cassandra.run() if not success: return False return True
def shutdown_datastore(): """ Top level function for bringing down Cassandra. Returns: True on success, False otherwise. """ logging.info("Shutting down Cassandra.") if not shut_down_cassandra.run(): return False return True