feat: add support for spanner copy backup feature by asthamohta · Pull Request #600 · googleapis/python-spanner · GitHub
Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 61 additions & 6 deletions google/cloud/spanner_v1/backup.py
33 changes: 33 additions & 0 deletions google/cloud/spanner_v1/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
_OPERATION_METADATA_MESSAGES = (
backup.Backup,
backup.CreateBackupMetadata,
backup.CopyBackupMetadata,
spanner_database_admin.CreateDatabaseMetadata,
spanner_database_admin.Database,
spanner_database_admin.OptimizeRestoredDatabaseMetadata,
Expand All @@ -58,6 +59,7 @@

_OPERATION_RESPONSE_TYPES = {
backup.CreateBackupMetadata: backup.Backup,
backup.CopyBackupMetadata: backup.Backup,
spanner_database_admin.CreateDatabaseMetadata: spanner_database_admin.Database,
spanner_database_admin.OptimizeRestoredDatabaseMetadata: spanner_database_admin.Database,
spanner_database_admin.RestoreDatabaseMetadata: spanner_database_admin.Database,
Expand Down Expand Up @@ -551,6 +553,37 @@ def backup(
encryption_config=encryption_config,
)

def copy_backup(
self, backup_id, source_backup, expire_time=None, encryption_config=None,
):
"""Factory to create a copy backup within this instance.

:type backup_id: str
:param backup_id: The ID of the backup copy.
:type source_backup: str
:param source_backup_id: The full path of the source backup to be copied.
:type expire_time: :class:`datetime.datetime`
:param expire_time:
Optional. The expire time that will be used when creating the copy backup.
Required if the create method needs to be called.
:type encryption_config:
:class:`~google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig`
or :class:`dict`
:param encryption_config:
(Optional) Encryption configuration for the backup.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig`
:rtype: :class:`~google.cloud.spanner_v1.backup.Backup`
:returns: a copy backup owned by this instance.
"""
return Backup(
backup_id,
self,
source_backup=source_backup,
expire_time=expire_time,
encryption_config=encryption_config,
)

def list_backups(self, filter_="", page_size=None):
"""List backups for the instance.

Expand Down
7 changes: 2 additions & 5 deletions samples/samples/autocommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ def enable_autocommit_mode(instance_id, database_id):

if __name__ == "__main__":
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument("instance_id", help="Your Cloud Spanner instance ID.")
parser.add_argument(
"--database-id",
help="Your Cloud Spanner database ID.",
default="example_db",
"--database-id", help="Your Cloud Spanner database ID.", default="example_db",
)
subparsers = parser.add_subparsers(dest="command")
subparsers.add_parser("enable_autocommit_mode", help=enable_autocommit_mode.__doc__)
Expand Down
2 changes: 1 addition & 1 deletion samples/samples/autocommit_test.py
Loading