-
Notifications
You must be signed in to change notification settings - Fork 102
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
feat: Spanner copy backup #1530
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f200a1c
feat: adding support for Cross Region Backups
asthamohta 069c74c
feat:changes to update backup sample
asthamohta 68b8a27
fix: changes as per comments
asthamohta a747b7f
Merge branch 'main' into spanner_copy_backup
asthamohta 5332b83
feat: changes as per comments
asthamohta 84544aa
Merge branch 'googleapis:main' into spanner_copy_backup
asthamohta 2e489e3
feat: updating samples
asthamohta 1aa86a6
fix: linting changes
asthamohta c0c3a96
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 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 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 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 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,97 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// 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. | ||
|
||
// sample-metadata: | ||
// title: Copies a source backup | ||
// usage: node spannerCopyBackup <INSTANCE_ID> <COPY_BACKUP_ID> <SOURCE_BACKUP_ID> <PROJECT_ID> | ||
|
||
'use strict'; | ||
|
||
function main( | ||
instanceId = 'my-instance', | ||
backupId = 'my-backup', | ||
sourceBackupPath = 'projects/my-project-id/instances/my-source-instance/backups/my-source-backup', | ||
projectId = 'my-project-id' | ||
) { | ||
// [START spanner_copy_backup] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const instanceId = 'my-instance'; | ||
// const backupId = 'my-backup', | ||
// const sourceBackupPath = 'projects/my-project-id/instances/my-source-instance/backups/my-source-backup', | ||
// const projectId = 'my-project-id'; | ||
|
||
// Imports the Google Cloud Spanner client library | ||
const {Spanner} = require('@google-cloud/spanner'); | ||
const {PreciseDate} = require('@google-cloud/precise-date'); | ||
|
||
// Instantiates a client | ||
const spanner = new Spanner({ | ||
projectId: projectId, | ||
}); | ||
|
||
async function spannerCopyBackup() { | ||
// Gets a reference to a Cloud Spanner instance and backup | ||
const instance = spanner.instance(instanceId); | ||
|
||
// Expire copy backup 14 days in the future | ||
const expireTime = Spanner.timestamp( | ||
Date.now() + 1000 * 60 * 60 * 24 * 14 | ||
).toStruct(); | ||
|
||
// Copy the source backup | ||
try { | ||
console.log(`Creating copy of the source backup ${sourceBackupPath}.`); | ||
const [, operation] = await instance.copyBackup( | ||
sourceBackupPath, | ||
backupId, | ||
{ | ||
expireTime: expireTime, | ||
} | ||
); | ||
|
||
console.log( | ||
`Waiting for backup copy ${ | ||
instance.backup(backupId).formattedName_ | ||
} to complete...` | ||
); | ||
await operation.promise(); | ||
|
||
// Verify the copy backup is ready | ||
const copyBackup = instance.backup(backupId); | ||
const [copyBackupInfo] = await copyBackup.getMetadata(); | ||
if (copyBackupInfo.state === 'READY') { | ||
console.log( | ||
`Backup copy ${copyBackupInfo.name} of size ` + | ||
`${copyBackupInfo.sizeBytes} bytes was created at ` + | ||
`${new PreciseDate(copyBackupInfo.createTime).toISOString()} ` + | ||
'with version time ' + | ||
`${new PreciseDate(copyBackupInfo.versionTime).toISOString()}` | ||
); | ||
} else { | ||
console.error('ERROR: Copy of backup is not ready.'); | ||
} | ||
} catch (err) { | ||
console.error('ERROR:', err); | ||
} | ||
} | ||
spannerCopyBackup(); | ||
// [END spanner_copy_backup] | ||
} | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains 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 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 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rest of the links are "-" separated. Maybe change to [Copy-source-backup]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is because this is in the new format of test. As you can see on line 34-36, this is acceptable