Skip to main content
restore_backup(backup_name=”, restore_objects_map=None, datasource_name=None, options=)[source]

Restores database objects from a backup accessible via the data source specified by input parameter datasource_name.

Parameters

backup_name (str) –

Name of the backup to restore from, which must refer to an existing backup. The default value is ‘’.

restore_objects_map (dict of str to str) –

Map of database objects to be restored from the backup. Allowed keys are:

datasource_name (str) –

Data source through which the backup will be restored.

options (dict of str to str) –

Optional parameters. Allowed keys are:

  • backup_id – ID of the snapshot to restore. Leave empty to restore the most recent snapshot in the backup. The default value is ‘’.

  • checksum – Whether or not to verify checksums for backup files when restoring. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • cascade_foreign_keys – Whether to drop live foreign-key-referencing tables that are not themselves part of the backup, when the table they reference is being replaced. Only applies when restore_policy is replace. Allowed values are:

    • true – Drop any live table whose foreign key references a table being replaced, even when that table is not in the backup and therefore will not be restored.

    • false – Fail the restore of a table that is referenced by a live foreign-key table which is not part of the backup, rather than destroying data the backup cannot restore.

    The default value is ‘false’.

  • create_schema_if_not_exist – Behavior to apply when the schema containing any database object to restore does not already exist. Allowed values are:

    • true – If the schema containing any restored object does not exist, create it automatically.

    • false – If the schema containing any restored object does not exist, return an error.

    The default value is ‘true’.

  • ddl_only – Behavior to apply when restoring tables. Allowed values are:

    • true – Restore table DDL, but do not restore data.

    • false – Restore tables and their data.

    The default value is ‘false’.

  • dry_run – Whether or not to perform a dry run of the restoration operation. With a restore_policy of clean or clean_all, a dry run lists the objects the clean would drop in the clean_dropped_objects entry of the response output parameter info map and drops nothing, and fails as the restore would if the clean is refused. Allowed values are:

    • true

    • false

    The default value is ‘false’.

  • restore_subscriptions – Behavior to apply when restoring datasource subscriptions on tables. Allowed values are:

    • resume – Resume subscriptions that were active when the backup was made.

    • pause – Pause subscriptions that were active when the backup was made.

    • cancel – Cancel active subscriptions.

    The default value is ‘resume’.

  • reingest – Behavior to apply when restoring table data. Allowed values are:

    • true – Restore table data by re-ingesting it. This is the default behavior if the cluster topology differs from that of the contained backup.

    • false – Restore the persisted data files directly.

    The default value is ‘false’.

  • renamed_objects_schema – If the restore_policy is rename, use this schema for relocated existing objects instead of the default generated one. The default value is ‘’.

  • restore_all_permissions – Whether or not all permissions of restored principals should be restored or scoped to the restored objects. When restore_policy is clean or clean_all, the default is true: the clean drops each principal in scope along with all of its permissions, including those on objects it does not drop. Allowed values are:

    • true – Restore all permissions.

    • false – Restore only permissions on restored objects.

    The default value is ‘false’.

  • restore_policy – Behavior to apply when any database object to restore already exists. Allowed values are:

    • none – If an object to be restored already exists with the same name, abort and return error.

    • replace – If an object to be restored already exists with the same name, replace it with the backup version. Only objects in the backup are dropped; existing objects that are not in the backup are kept, so the result is a merge of the backup into the database. To drop those as well, use clean.

    • rename – If an object to be restored already exists with the same name, move that existing one to the schema specified by renamed_objects_schema. This policy does not apply to non-schema objects.

    • clean – Before restoring, drop every existing object of each object type being restored, whether or not that object is in the backup, including objects that are not persisted; object types not being restored are left untouched, and schemas are not dropped. Unlike replace, the clean is scoped by object type, not by name: restoring a single table drops every table in the database first, and the response warns when the objects to restore name specific objects of a type rather than all of them. Use dry_run to list the objects that would be dropped. The restore is refused, before anything is dropped, if an object that would be dropped is still used by an object of a type that is not being restored, or cannot be dropped, such as a table locked by a backup in progress. As graphs, contexts, table monitors and stored procedures all depend on tables, restoring tables requires restoring each of those types of which any objects exist. A data sink generated for a monitor is dropped along with the monitor, and a home directory only along with its user. Objects created by other sessions while the restore runs are not dropped. If the restore fails after the clean, the dropped objects are not put back. System objects, the data source being restored from and its credential, the calling user and admin, with their default schemas, home directories and resource groups, and the calling user’s roles are never dropped, nor are the schemas holding any of these. Requires system administrator permission.

    • clean_all – Before restoring, drop every existing object in the database, regardless of which objects are being restored, including users, roles, non-system schemas and objects that are not persisted. The restore is refused, before anything is dropped, if an object cannot be dropped, such as a table locked by a backup in progress, or is still used by an object the clean keeps, such as a resource group a system user is in; it also requires create_schema_if_not_exist to be true. If the restore fails after the clean, the dropped objects are not put back. System objects, the data source being restored from and its credential, the calling user and admin, with their default schemas, home directories and resource groups, and the calling user’s roles are never dropped, nor are the schemas holding any of these. Requires system administrator permission.

    The default value is ‘none’.

  • target_schema_map – Restore schema-based objects to alternate schema. Value is a comma delimitted list of key:value pairs mapping the original (source) schema name as it exists in the backup to a target (destination) schema namespace: “src: dst [, src: dst [, …]]”. Note that schema names are case sensitive and must adhere to the database schema naming criteria. The default value is ‘’.

The default value is an empty dict ( ).

Returns

A dict with the following entries–

backup_name (str) –

Value of input parameter backup_name.

backup_id (long) –

ID of the snapshot that was restored.

restored_bytes (long) –

Total size of data restored from backup.

restored_files (long) –

Total number of files restored from backup.

restored_records (long) –

Total number of records restored from backup.

restored_objects (dict of str to str) –

Database objects that were successfully restored and their associated types.

renamed_objects (dict of str to str) –

Original and new names of database objects that were successfully restored and their associated types.

failed_objects (dict of str to str) –

Database objects that failed to be restored and their associated types.

info (dict of str to str) –

Additional information. Allowed keys are:

  • clean_dropped_objects – If restore_policy is clean or clean_all, the objects the clean dropped before restoring, grouped by type, e.g. ‘table: s.a, s.b; user: u1; schema: s’. When dry_run is true, the objects it would drop. A long list ends with the number of objects left out.

  • clean_kept_objects – If restore_policy is clean or clean_all, comma-separated list of objects in the backup that the clean kept on the target, such as the calling user, and that the restore therefore left as they were instead of restoring them, e.g. user ‘u1’, directory ‘~u1’.

The default value is an empty dict ( ).