Skip to content

samples: parameterises create backup version time #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
8 changes: 1 addition & 7 deletions samples/samples/backup_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@


# [START spanner_create_backup]
def create_backup(instance_id, database_id, backup_id):
def create_backup(instance_id, database_id, backup_id, version_time):
"""Creates a backup for a database."""
spanner_client = spanner.Client()
instance = spanner_client.instance(instance_id)
database = instance.database(database_id)

# Sets the version time as the current server time
version_time = None
with database.snapshot() as snapshot:
results = snapshot.execute_sql("SELECT CURRENT_TIMESTAMP()")
version_time = list(results)[0][0]

# Create a backup
expire_time = datetime.utcnow() + timedelta(days=14)
backup = instance.backup(backup_id, database=database, expire_time=expire_time, version_time=version_time)
Expand Down
7 changes: 6 additions & 1 deletion samples/samples/backup_sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ def database(spanner_instance):


def test_create_backup(capsys, database):
backup_sample.create_backup(INSTANCE_ID, DATABASE_ID, BACKUP_ID)
version_time = None
with database.snapshot() as snapshot:
results = snapshot.execute_sql("SELECT CURRENT_TIMESTAMP()")
version_time = list(results)[0][0]

backup_sample.create_backup(INSTANCE_ID, DATABASE_ID, BACKUP_ID, version_time)
out, _ = capsys.readouterr()
assert BACKUP_ID in out

Expand Down