crate.operator.restore_backup module¶
- class crate.operator.restore_backup.AfterRestoreBackupSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)¶
Bases:
StateBasedSubHandler
- class crate.operator.restore_backup.BeforeRestoreBackupSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)¶
Bases:
StateBasedSubHandler
- class crate.operator.restore_backup.ResetSnapshotSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)¶
Bases:
StateBasedSubHandler- async handle(namespace, name, logger, **kwargs)¶
Reset the snapshot name in the CrateDB spec to ensure the same snapshot can be restored again if it failed for any reason. This has to be done last because kopf recognizes it as a new change in the restoreSnapshot field.
- class crate.operator.restore_backup.RestoreAll(*, tables=None, sections=None, partitions=None, **_kwargs)¶
Bases:
RestoreType- Parameters:
- get_restore_keyword(*, cursor)¶
Each subclass needs to return the keyword to be used in the
RESTORE SNAPSHOTcommand based on the type of restore operation.- Parameters:
cursor (
Cursor)
- async validate_restore_complete(*, conn_factory, snapshot, logger, **_kwargs)¶
Each subclass needs to define a method which indicates that the restore operation has been completed successfully. Or raise a
kopf.TemporaryErrorin case the operation is still in progress.
- class crate.operator.restore_backup.RestoreBackupSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)¶
Bases:
StateBasedSubHandler- async handle(namespace, name, repository, snapshot, restore_type, backup_provider, tables, partitions, sections, logger, **kwargs)¶
- class crate.operator.restore_backup.RestoreDataSections(*, tables=None, sections=None, partitions=None, **_kwargs)¶
Bases:
RestoreType- Parameters:
- get_restore_keyword(*, cursor)¶
Each subclass needs to return the keyword to be used in the
RESTORE SNAPSHOTcommand based on the type of restore operation.- Parameters:
cursor (
Cursor)
- async validate_restore_complete(*, conn_factory, snapshot, logger, **_kwargs)¶
Each subclass needs to define a method which indicates that the restore operation has been completed successfully. Or raise a
kopf.TemporaryErrorin case the operation is still in progress.
- class crate.operator.restore_backup.RestoreInternalTables(conn_factory, repository, snapshot, logger)¶
Bases:
object- async cleanup_tables()¶
After a successful restore, the temporary renamed gc tables can be dropped.
- async rename_duplicated_tables()¶
If the snapshot contains grand central tables, rename them if they exist in the cluster in order to recreate the new ones from the snapshot.
- async restore_tables()¶
If the restore operation failed, rename back the gc tables to their original names.
- class crate.operator.restore_backup.RestoreInternalTablesSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)¶
Bases:
StateBasedSubHandler- async handle(namespace, name, snapshot, repository, restore_type, tables, logger, **kwargs)¶
Handles restoring or cleaning up internal tables after a snapshot restore.
This subhandler runs after dependent handlers (e.g. RestoreSubHandler and ValidateRestoreCompleteSubHandler) have completed. It verifies their results and then either restores temporary internal tables (on failure) or drops them (on success).
- class crate.operator.restore_backup.RestoreInternalUsersPasswordSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)¶
Bases:
StateBasedSubHandler- async handle(namespace, name, logger, **kwargs)¶
Restore the system user and grand-central user passwords from the secret in the namespace. Use crash here because during a restore the system user password was probably set to a different value.
- class crate.operator.restore_backup.RestoreMetadata(*, tables=None, sections=None, partitions=None, **_kwargs)¶
Bases:
RestoreType- Parameters:
- get_restore_keyword(*, cursor)¶
Each subclass needs to return the keyword to be used in the
RESTORE SNAPSHOTcommand based on the type of restore operation.- Parameters:
cursor (
Cursor)
- async validate_restore_complete(*, conn_factory, snapshot, logger, **_kwargs)¶
Each subclass needs to define a method which indicates that the restore operation has been completed successfully. Or raise a
kopf.TemporaryErrorin case the operation is still in progress.
- class crate.operator.restore_backup.RestorePartitions(*, tables=None, sections=None, partitions=None, **_kwargs)¶
Bases:
RestoreType- Parameters:
- get_restore_keyword(*, cursor)¶
Each subclass needs to return the keyword to be used in the
RESTORE SNAPSHOTcommand based on the type of restore operation.- Parameters:
cursor (
Cursor)
- async validate_restore_complete(*, conn_factory, snapshot, logger, **_kwargs)¶
Each subclass needs to define a method which indicates that the restore operation has been completed successfully. Or raise a
kopf.TemporaryErrorin case the operation is still in progress.
- class crate.operator.restore_backup.RestoreTables(*, tables=None, sections=None, partitions=None, **_kwargs)¶
Bases:
RestoreType- Parameters:
- get_restore_keyword(*, cursor)¶
Each subclass needs to return the keyword to be used in the
RESTORE SNAPSHOTcommand based on the type of restore operation.- Parameters:
cursor (
Cursor)
- async validate_restore_complete(*, conn_factory, snapshot, logger, **_kwargs)¶
Each subclass needs to define a method which indicates that the restore operation has been completed successfully. Or raise a
kopf.TemporaryErrorin case the operation is still in progress.
- class crate.operator.restore_backup.RestoreType(*, tables=None, sections=None, partitions=None, **_kwargs)¶
Bases:
ABCBase class for the different types of restore operations. New subclasses are identified by their
restore_typeand can be added dynamically by using theregister_subclassdecorator.- Parameters:
- abstractmethod get_restore_keyword(*, cursor)¶
Each subclass needs to return the keyword to be used in the
RESTORE SNAPSHOTcommand based on the type of restore operation.- Parameters:
cursor (
Cursor)
-
subclasses:
Dict[str,Any] = {'all': <class 'crate.operator.restore_backup.RestoreAll'>, 'metadata': <class 'crate.operator.restore_backup.RestoreMetadata'>, 'partitions': <class 'crate.operator.restore_backup.RestorePartitions'>, 'sections': <class 'crate.operator.restore_backup.RestoreDataSections'>, 'tables': <class 'crate.operator.restore_backup.RestoreTables'>}¶
- abstractmethod async validate_restore_complete(*, conn_factory, snapshot, logger, **_kwargs)¶
Each subclass needs to define a method which indicates that the restore operation has been completed successfully. Or raise a
kopf.TemporaryErrorin case the operation is still in progress.
- class crate.operator.restore_backup.SendSuccessNotificationSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)¶
Bases:
StateBasedSubHandlerA handler which depends on all other subhandlers having finished successfully and schedules a success notification of the restore process.
- async handle(namespace, name, logger, **kwargs)¶
Schedule success notification and send it after the cluster has been restored successfully.
- class crate.operator.restore_backup.ValidateRestoreCompleteSubHandler(namespace, name, ref, context, depends_on=None, run_on_dep_failures=False, operation=None)¶
Bases:
StateBasedSubHandler
- async crate.operator.restore_backup.drop_repository(cursor, repository, logger)¶
Drops a backup repository if it exists.
- async crate.operator.restore_backup.ensure_no_restore_in_progress(namespace, name, snapshot, pod_name, scheme, logger)¶
This checks if there is a restore operation of the given snapshot currently in progress by querying the
sys.snapshot_restoretable. If there is a restore in progress, it queries thesys.shardstable to get the progress of the operation. It sends this information to the API and raises akopf.TemporaryError. Use crash here because during a restore the system user password might be restored to a different value already.- Parameters:
namespace (
str) – The Kubernetes namespace of the CrateDB cluster.name (
str) – The CrateDB custom resource name defining the CrateDB cluster.snapshot (
str) – The name of the snapshot.pod_name (
str) – The pod name where the crash command should be run.scheme (
str) – The host scheme for running the crash command.logger (
Logger) – the logger on which we’re logging
- async crate.operator.restore_backup.get_snapshot_tables(conn_factory, snapshot, logger)¶
Returns a list of tables included in a snapshot.
- async crate.operator.restore_backup.get_source_backup_repository_data(core, namespace, name, backup_provider, logger)¶
Read the secret values to access the backup repository of the source cluster defined by
secretKeyRefinrestoreSnapshot.- Parameters:
core (
CoreV1Api) – An instance of the Kubernetes Core V1 API.namespace (
str) – The namespace where to lookup the secret and its value.name (
str) – The CrateDB custom resource name defining the CrateDB cluster.logger (
Logger) – the logger on which we’re loggingbackup_provider (
BackupStorageProvider)
- Return type:
- crate.operator.restore_backup.is_valid_snapshot(new, **kwargs)¶
This checks if the new snapshot name is valid or not (empty). This check is necessary to avoid another restore operation is triggered after we reset the snapshot field at the end of a completed restore operation.
- crate.operator.restore_backup.quote_table(table, cursor)¶
Ensure table names are correctly quoted. If it contains a schema (e.g., ‘doc.nyc_taxi’), quote both the schema and the table using psycopg2.extensions.quote_ident.
- Return type:
- crate.operator.restore_backup.restore_internal_tables_context(apps, namespace, name, conn_factory, repository, snapshot, logger, restore_type, tables)¶
- async crate.operator.restore_backup.shards_recovery_in_progress(conn_factory, snapshot, tables, logger)¶
Checks if there is at least one shard which has not fully recovered after an operation of type
SNAPSHOT.- Parameters:
conn_factory – A function that establishes a database connection to the CrateDB cluster used for SQL queries.
snapshot (
str) – The name of the snapshot to restore.tables (
List[str]) – A list of tables which should be checked for shards that have not been restored completely.logger (
Logger) – the logger on which we’re logging
- crate.operator.restore_backup.table_without_schema(table, cursor)¶
Returns the table name without schema, ensuring it’s correctly quoted.
- Parameters:
table – The full table name, possibly including schema.
cursor – The database cursor used for quoting.
- Return type:
- Returns:
The quoted table name without schema.
- async crate.operator.restore_backup.update_cratedb_admin_username_in_cratedb(namespace, cluster_name, new_admin_username)¶