-
Notifications
You must be signed in to change notification settings - Fork 101
feat: add samples for PITR #222
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
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f64659b
Add PITR samples
zoercai 12c8573
Merge branch 'master' of github.com:googleapis/python-spanner into pi…
zoercai fd56d7c
Set backup version time to earliest version time
zoercai 8f942b1
Move version_retention_period to backup_sample
zoercai 977c883
Merge branch 'master' of github.com:googleapis/python-spanner into pi…
zoercai 9af4765
Review changes & fixes
zoercai 1d424c4
New line for consistency
zoercai c785b51
Lint
zoercai 60038b4
Move retention test to the bottom to make it pass?
zoercai 8932c21
Review changes
zoercai 533b855
Review changes
zoercai 32bc39d
Review changes
zoercai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Copyright 2020 Google Inc. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """This application demonstrates how to create and restore from backups | ||
| using Cloud Spanner. | ||
|
|
||
| For more information, see the README.rst under /spanner. | ||
| """ | ||
|
|
||
| import argparse | ||
| from datetime import datetime, timedelta | ||
| import time | ||
|
|
||
| from google.cloud import spanner | ||
|
|
||
| # [START spanner_create_database_with_version_retention_period] | ||
| def create_database_with_version_retention_period(instance_id, database_id, retention_period): | ||
| """Creates a database with a version retention period.""" | ||
| spanner_client = spanner.Client() | ||
| instance = spanner_client.instance(instance_id) | ||
| ddl_statements = [ | ||
| "CREATE TABLE Singers (" | ||
| + " SingerId INT64 NOT NULL," | ||
| + " FirstName STRING(1024)," | ||
| + " LastName STRING(1024)," | ||
| + " SingerInfo BYTES(MAX)" | ||
| + ") PRIMARY KEY (SingerId)", | ||
| "CREATE TABLE Albums (" | ||
| + " SingerId INT64 NOT NULL," | ||
| + " AlbumId INT64 NOT NULL," | ||
| + " AlbumTitle STRING(MAX)" | ||
| + ") PRIMARY KEY (SingerId, AlbumId)," | ||
| + " INTERLEAVE IN PARENT Singers ON DELETE CASCADE", | ||
| "ALTER DATABASE {}" | ||
| " SET OPTIONS (version_retention_period = '{}')".format( | ||
| database_id, retention_period | ||
| ) | ||
| ] | ||
| db = instance.database(database_id, ddl_statements) | ||
| operation = db.create() | ||
|
|
||
| operation.result(30) | ||
|
|
||
| db.reload() | ||
|
|
||
| print("Database {} created with version retention period {} and earliest version time {}".format( | ||
| db.database_id, db.version_retention_period(), db.earliest_version_time() | ||
| )) | ||
|
|
||
| db.drop() | ||
|
|
||
| # [END spanner_create_database_with_version_retention_period] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Copyright 2020 Google Inc. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import uuid | ||
|
|
||
| from google.api_core.exceptions import DeadlineExceeded | ||
| from google.cloud import spanner | ||
| import pytest | ||
| from test_utils.retry import RetryErrors | ||
|
|
||
| import version_retention_period | ||
|
|
||
| def unique_instance_id(): | ||
| """ Creates a unique id for the database. """ | ||
| return f"test_instance_{uuid.uuid4().hex[:10]}" | ||
|
|
||
|
|
||
| def unique_database_id(): | ||
| """ Creates a unique id for the database. """ | ||
| return f"test_db_{uuid.uuid4().hex[:10]}" | ||
|
|
||
|
|
||
| INSTANCE_ID = unique_instance_id() | ||
| DATABASE_ID = unique_database_id() | ||
|
|
||
| @pytest.fixture(scope="module") | ||
| def spanner_instance(): | ||
| spanner_client = spanner.Client() | ||
| instance_config = "{}/instanceConfigs/{}".format( | ||
| spanner_client.project_name, "regional-us-central1" | ||
| ) | ||
| instance = spanner_client.instance(INSTANCE_ID, instance_config) | ||
| op = instance.create() | ||
| op.result(120) # block until completion | ||
| yield instance | ||
| instance.delete() | ||
|
|
||
| @RetryErrors(exception=DeadlineExceeded, max_tries=2) | ||
| def test_restore_database(capsys): | ||
| retention_period = "7d" | ||
| version_retention_period.create_database_with_version_retention_period(INSTANCE_ID, DATABASE_ID, retention_period) | ||
| out, _ = capsys.readouterr() | ||
| assert (DATABASE_ID + " created with ") in out | ||
| assert ("retention period " + version_retention_period) in out |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.