Skip to content

feat(spanner): Add CreateBackupSchedule incremental backup sample - #14983

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

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

Conversation

@iennae

@iennae iennae commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Description

Adds spanner_create_incremental_backup_schedule creating an automated IncrementalBackupSpec 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

Enterprise Spanner databases reduce backup storage and cost with IncrementalBackupSpec schedules via create_backup_schedule. Add a standalone spanner_create_incremental_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 script to create incremental backup schedules on Enterprise Spanner databases, along with unit and live integration tests. The feedback suggests refining the live integration test to avoid deleting all existing backup schedules on the shared database, which could disrupt concurrent tests. Instead, the cleanup should target only the specific test-created schedules using a safer teardown pattern.

Comment on lines +133 to +135
# Remove any default incremental schedule temporarily if present
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.

medium

Deleting all existing backup schedules on the shared live database can disrupt other concurrent tests or delete persistent schedules. It is safer to only clean up leftover schedules created by this test suite (e.g., those matching the 'example-isc-' prefix). Additionally, ensure consistency in test structures by using a try...finally block or teardown function for resource cleanup, matching neighboring tests in the same directory.

try:
    # Run test logic
    pass
finally:
    # Remove any leftover test incremental schedules if present
    for existing in admin.list_backup_schedules(parent=db_path):
        if "example-isc-" in existing.name:
            admin.delete_backup_schedule(name=existing.name)
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 these tests (4b37cc7).

…chedule

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_incremental_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