Skip to content

feat(spanner): Add CreateBackupSchedule full backup sample - #14982

Open
iennae wants to merge 2 commits into
feat/spanner-copy-backupfrom
feat/spanner-create-full-backup-schedule
Open

iennae wants to merge 2 commits into
feat/spanner-copy-backupfrom
feat/spanner-create-full-backup-schedule

Conversation

@iennae

@iennae iennae commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Description

Adds spanner_create_full_backup_schedule creating an automated FullBackupSpec backup schedule.

Note: Stacked on #14854 (feat/spanner-copy-backup) so this PR shows only this sample's diff. It will merge into main after #14854.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended. Unit and live integration tests pass on Python 3.13.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

Automated full backup schedules configure cron timing and retention on a database via FullBackupSpec and create_backup_schedule. Add a standalone spanner_create_full_backup_schedule sample.
@iennae
iennae requested review from a team as code owners November 18, 2026 22:20
@snippet-bot

snippet-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples. labels Nov 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new script to create daily full backup schedules on Google Cloud Spanner databases, along with unit and live integration tests. A critical issue was identified in the live integration test, where all existing backup schedules on the database are deleted before running the test. This destructive pre-cleanup step is unnecessary and risky, as the test already generates a unique schedule ID and cleans it up in a try-finally block.

Comment on lines +129 to +130
for existing in admin.list_backup_schedules(parent=db_path):
admin.delete_backup_schedule(name=existing.name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Deleting all existing backup schedules on the live database is highly destructive and can cause flaky tests or disrupt other concurrent test runs or resources sharing the same database. Since the test already generates a unique schedule ID using a UUID and cleans it up in the finally block, this pre-cleanup step is unnecessary and should be removed.

References
  1. Maintain consistency in test structures by matching the patterns employed by existing or neighboring tests in the same directory, such as using a try...finally block with a teardown function for resource cleanup.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done: the pre-cleanup now only removes schedules left behind by earlier runs of this test (8b1636e).

Problem: review of this sample identified correctness and robustness
improvements in the sample and its tests.

Solution: apply the accepted review suggestions and extend the tests to
cover the updated behavior. Details are in the review thread replies.

Files updated:
  - spanner/backups/tests/create_full_backup_schedule_test.py
@amcolin amcolin self-assigned this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants