-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(spanner): Added sample for copyBackup #1568
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
bshaffer
merged 13 commits into
GoogleCloudPlatform:master
from
saranshdhingra:add-copy-backup-sample
Apr 5, 2022
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
59aefad
Spanner: Added sample for copyBackup()
saranshdhingra 98b8cfa
Spanner: Lint fixes in copy_backup.php
saranshdhingra d2066dd
Spanner: Updated copy_backup sample with the latest interface
saranshdhingra b3b9764
Spanner: Minor fix in the create_backup sample
saranshdhingra 0f0bcba
Spanner: Added maxExpireTime changes in update_backup sample
saranshdhingra 0b9ce60
spanner: Added version time in copy_backup, nit changes in update_backup
saranshdhingra 7033328
Merge branch 'GoogleCloudPlatform:master' into add-copy-backup-sample
saranshdhingra 68141d1
Spanner: list_backup_operations now lists copy backup operations as well
saranshdhingra c75fc63
Spanner: Fix the testCopyBackup test
saranshdhingra 02c23f6
Spanner: Fix the testCopyBackup test
saranshdhingra 42f913d
Spanner: Change the arguments for the copy_backup sample test
saranshdhingra 10bbb34
Spanner: Changed the copy backup id to tackle multiple iterations of …
saranshdhingra 6ed8d79
Spanner: Updated composer.json to reflect version for copy backup sample
saranshdhingra 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "require": { | ||
| "google/cloud-spanner": "^1.28.0" | ||
| "google/cloud-spanner": "^1.48.0" | ||
| } | ||
| } |
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,76 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2021 Google Inc. | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| /** | ||
| * For instructions on how to run the full sample: | ||
| * | ||
| * @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/spanner/README.md | ||
| */ | ||
|
|
||
| namespace Google\Cloud\Samples\Spanner; | ||
|
|
||
| // [START spanner_copy_backup] | ||
| use Google\Cloud\Spanner\Backup; | ||
| use Google\Cloud\Spanner\SpannerClient; | ||
|
|
||
| /** | ||
| * Create a copy backup from another source backup. | ||
| * Example: | ||
| * ``` | ||
| * copy_backup($destInstanceId, $destBackupId, $sourceInstanceId, $sourceBackupId); | ||
| * ``` | ||
| * | ||
| * @param string $destInstanceId The Spanner instance ID where the copy backup will reside. | ||
| * @param string $destBackupId The Spanner backup ID of the new backup to be created. | ||
| * @param string $sourceInstanceId The Spanner instance ID of the source backup. | ||
| * @param string $sourceBackupId The Spanner backup ID of the source. | ||
| */ | ||
| function copy_backup($destInstanceId, $destBackupId, $sourceInstanceId, $sourceBackupId) | ||
| { | ||
| $spanner = new SpannerClient(); | ||
|
|
||
| $destInstance = $spanner->instance($destInstanceId); | ||
| $sourceInstance = $spanner->instance($sourceInstanceId); | ||
| $sourceBackup = $sourceInstance->backup($sourceBackupId); | ||
| $destBackup = $destInstance->backup($destBackupId); | ||
|
|
||
| $expireTime = new \DateTime('+8 hours'); | ||
| $operation = $sourceBackup->createCopy($destBackup, $expireTime); | ||
|
|
||
| print('Waiting for operation to complete...' . PHP_EOL); | ||
|
|
||
| $operation->pollUntilComplete(); | ||
| $destBackup->reload(); | ||
|
|
||
| $ready = ($destBackup->state() == Backup::STATE_READY); | ||
|
|
||
| if ($ready) { | ||
| print('Backup is ready!' . PHP_EOL); | ||
| $info = $destBackup->info(); | ||
| printf( | ||
| 'Backup %s of size %d bytes was copied at %s from the source backup %s' . PHP_EOL, | ||
| basename($info['name']), $info['sizeBytes'], $info['createTime'], $sourceBackupId); | ||
| printf('Version time of the copied backup: %s' . PHP_EOL, $info['versionTime']); | ||
| } else { | ||
| printf('Unexpected state: %s' . PHP_EOL, $destBackup->state()); | ||
| } | ||
| } | ||
| // [END spanner_copy_backup] | ||
|
|
||
| // The following 2 lines are only needed to run the samples | ||
| require_once __DIR__ . '/../../testing/sample_helpers.php'; | ||
| \Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv); | ||
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
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
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.