|
23 | 23 | from google.api_core import protobuf_helpers |
24 | 24 | from google.cloud import spanner |
25 | 25 | from google.cloud.exceptions import NotFound |
26 | | -from google.cloud.spanner_admin_database_v1.types import backup as backup_pb |
27 | | -from google.cloud.spanner_admin_database_v1.types import spanner_database_admin |
28 | 26 |
|
29 | 27 |
|
30 | 28 | # [START spanner_create_backup] |
31 | 29 | def create_backup(instance_id, database_id, backup_id, version_time): |
32 | 30 | """Creates a backup for a database.""" |
| 31 | + |
| 32 | + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb |
| 33 | + |
33 | 34 | spanner_client = spanner.Client() |
34 | 35 | instance = spanner_client.instance(instance_id) |
35 | 36 | database = instance.database(database_id) |
@@ -70,8 +71,10 @@ def create_backup_with_encryption_key( |
70 | 71 | instance_id, database_id, backup_id, kms_key_name |
71 | 72 | ): |
72 | 73 | """Creates a backup for a database using a Customer Managed Encryption Key (CMEK).""" |
73 | | - from google.cloud.spanner_admin_database_v1 import \ |
74 | | - CreateBackupEncryptionConfig |
| 74 | + |
| 75 | + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb |
| 76 | + |
| 77 | + from google.cloud.spanner_admin_database_v1 import CreateBackupEncryptionConfig |
75 | 78 |
|
76 | 79 | spanner_client = spanner.Client() |
77 | 80 | instance = spanner_client.instance(instance_id) |
@@ -151,7 +154,9 @@ def restore_database_with_encryption_key( |
151 | 154 | ): |
152 | 155 | """Restores a database from a backup using a Customer Managed Encryption Key (CMEK).""" |
153 | 156 | from google.cloud.spanner_admin_database_v1 import ( |
154 | | - RestoreDatabaseEncryptionConfig, RestoreDatabaseRequest) |
| 157 | + RestoreDatabaseEncryptionConfig, |
| 158 | + RestoreDatabaseRequest, |
| 159 | + ) |
155 | 160 |
|
156 | 161 | spanner_client = spanner.Client() |
157 | 162 | instance = spanner_client.instance(instance_id) |
@@ -190,6 +195,8 @@ def restore_database_with_encryption_key( |
190 | 195 |
|
191 | 196 | # [START spanner_cancel_backup_create] |
192 | 197 | def cancel_backup(instance_id, database_id, backup_id): |
| 198 | + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb |
| 199 | + |
193 | 200 | spanner_client = spanner.Client() |
194 | 201 | instance = spanner_client.instance(instance_id) |
195 | 202 | database = instance.database(database_id) |
@@ -238,6 +245,8 @@ def cancel_backup(instance_id, database_id, backup_id): |
238 | 245 |
|
239 | 246 | # [START spanner_list_backup_operations] |
240 | 247 | def list_backup_operations(instance_id, database_id, backup_id): |
| 248 | + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb |
| 249 | + |
241 | 250 | spanner_client = spanner.Client() |
242 | 251 | instance = spanner_client.instance(instance_id) |
243 | 252 |
|
@@ -288,6 +297,8 @@ def list_backup_operations(instance_id, database_id, backup_id): |
288 | 297 |
|
289 | 298 | # [START spanner_list_database_operations] |
290 | 299 | def list_database_operations(instance_id): |
| 300 | + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin |
| 301 | + |
291 | 302 | spanner_client = spanner.Client() |
292 | 303 | instance = spanner_client.instance(instance_id) |
293 | 304 |
|
@@ -316,6 +327,8 @@ def list_database_operations(instance_id): |
316 | 327 |
|
317 | 328 | # [START spanner_list_backups] |
318 | 329 | def list_backups(instance_id, database_id, backup_id): |
| 330 | + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb |
| 331 | + |
319 | 332 | spanner_client = spanner.Client() |
320 | 333 | instance = spanner_client.instance(instance_id) |
321 | 334 |
|
@@ -402,6 +415,8 @@ def list_backups(instance_id, database_id, backup_id): |
402 | 415 |
|
403 | 416 | # [START spanner_delete_backup] |
404 | 417 | def delete_backup(instance_id, backup_id): |
| 418 | + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb |
| 419 | + |
405 | 420 | spanner_client = spanner.Client() |
406 | 421 | instance = spanner_client.instance(instance_id) |
407 | 422 | backup = spanner_client.database_admin_api.get_backup( |
@@ -432,14 +447,15 @@ def delete_backup(instance_id, backup_id): |
432 | 447 | except NotFound: |
433 | 448 | print("Backup {} has been deleted.".format(backup.name)) |
434 | 449 | return |
435 | | - assert True is False |
436 | 450 |
|
437 | 451 |
|
438 | 452 | # [END spanner_delete_backup] |
439 | 453 |
|
440 | 454 |
|
441 | 455 | # [START spanner_update_backup] |
442 | 456 | def update_backup(instance_id, backup_id): |
| 457 | + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb |
| 458 | + |
443 | 459 | spanner_client = spanner.Client() |
444 | 460 | instance = spanner_client.instance(instance_id) |
445 | 461 |
|
@@ -474,6 +490,9 @@ def create_database_with_version_retention_period( |
474 | 490 | instance_id, database_id, retention_period |
475 | 491 | ): |
476 | 492 | """Creates a database with a version retention period.""" |
| 493 | + |
| 494 | + from google.cloud.spanner_admin_database_v1.types import spanner_database_admin |
| 495 | + |
477 | 496 | spanner_client = spanner.Client() |
478 | 497 | instance = spanner_client.instance(instance_id) |
479 | 498 | ddl_statements = [ |
@@ -520,6 +539,9 @@ def create_database_with_version_retention_period( |
520 | 539 | # [START spanner_copy_backup] |
521 | 540 | def copy_backup(instance_id, backup_id, source_backup_path): |
522 | 541 | """Copies a backup.""" |
| 542 | + |
| 543 | + from google.cloud.spanner_admin_database_v1.types import backup as backup_pb |
| 544 | + |
523 | 545 | spanner_client = spanner.Client() |
524 | 546 | instance = spanner_client.instance(instance_id) |
525 | 547 |
|
|
0 commit comments