-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Spanner): Add samples for Cloud Spanner Scheduled Backups
- Loading branch information
1 parent
b9a5ba1
commit b5d117e
Showing
12 changed files
with
508 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
spanner/api/Spanner.Samples.Tests/CreateFullBackupScheduleTest.cs
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,35 @@ | ||
// Copyright 2024 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. | ||
|
||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class CreateFullBackupScheduleTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
public CreateFullBackupScheduleTest(SpannerFixture spannerFixture) => _spannerFixture = spannerFixture; | ||
|
||
[Fact] | ||
public void TestCreateFullBackupSchedule() | ||
{ | ||
var scheduleId = SpannerFixture.GenerateId("schedule-"); | ||
var sample = new CreateFullBackupScheduleSample(); | ||
var schedule = sample.CreateFullBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId); | ||
Assert.NotNull(schedule); | ||
|
||
new DeleteBackupScheduleSample() | ||
.DeleteBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
spanner/api/Spanner.Samples.Tests/CreateIncrementalBackupScheduleTest.cs
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,35 @@ | ||
// Copyright 2024 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. | ||
|
||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class CreateIncrementalBackupScheduleTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
public CreateIncrementalBackupScheduleTest(SpannerFixture spannerFixture) => _spannerFixture = spannerFixture; | ||
|
||
[Fact] | ||
public void TestCreateIncrementalBackupSchedule() | ||
{ | ||
var scheduleId = SpannerFixture.GenerateId("schedule-"); | ||
var sample = new CreateIncrementalBackupScheduleSample(); | ||
var schedule = sample.CreateIncrementalBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId); | ||
Assert.NotNull(schedule); | ||
|
||
new DeleteBackupScheduleSample() | ||
.DeleteBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
spanner/api/Spanner.Samples.Tests/DeleteBackupScheduleTest.cs
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,36 @@ | ||
// Copyright 2024 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. | ||
|
||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class DeleteBackupScheduleTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
public DeleteBackupScheduleTest(SpannerFixture spannerFixture) => _spannerFixture = spannerFixture; | ||
|
||
[Fact] | ||
public void TestDeleteBackupSchedule() | ||
{ | ||
var scheduleId = SpannerFixture.GenerateId("schedule-"); | ||
Assert.NotNull( | ||
new CreateFullBackupScheduleSample() | ||
.CreateFullBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId) | ||
); | ||
|
||
var sample = new DeleteBackupScheduleSample(); | ||
sample.DeleteBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
spanner/api/Spanner.Samples.Tests/GetBackupScheduleTest.cs
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,40 @@ | ||
// Copyright 2024 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. | ||
|
||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class GetBackupScheduleTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
public GetBackupScheduleTest(SpannerFixture spannerFixture) => _spannerFixture = spannerFixture; | ||
|
||
[Fact] | ||
public void TestGetBackupSchedule() | ||
{ | ||
var scheduleId = SpannerFixture.GenerateId("schedule-"); | ||
Assert.NotNull( | ||
new CreateFullBackupScheduleSample() | ||
.CreateFullBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId) | ||
); | ||
|
||
var sample = new GetBackupScheduleSample(); | ||
var schedule = sample.GetBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId); | ||
Assert.NotNull(schedule); | ||
|
||
new DeleteBackupScheduleSample() | ||
.DeleteBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
spanner/api/Spanner.Samples.Tests/ListBackupSchedulesTest.cs
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,41 @@ | ||
// Copyright 2024 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. | ||
|
||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class ListBackupSchedulesTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
public ListBackupSchedulesTest(SpannerFixture spannerFixture) => _spannerFixture = spannerFixture; | ||
|
||
[Fact] | ||
public void TestListBackupSchedules() | ||
{ | ||
var scheduleId = SpannerFixture.GenerateId("schedule-"); | ||
Assert.NotNull( | ||
new CreateFullBackupScheduleSample() | ||
.CreateFullBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId) | ||
); | ||
|
||
var sample = new ListBackupSchedulesSample(); | ||
var schedules = sample.ListBackupSchedules(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId); | ||
Assert.NotNull(schedules); | ||
Assert.NotEmpty(schedules); | ||
|
||
new DeleteBackupScheduleSample() | ||
.DeleteBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
spanner/api/Spanner.Samples.Tests/UpdateBackupScheduleTest.cs
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,40 @@ | ||
// Copyright 2024 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. | ||
|
||
using Xunit; | ||
|
||
[Collection(nameof(SpannerFixture))] | ||
public class UpdateBackupScheduleTest | ||
{ | ||
private readonly SpannerFixture _spannerFixture; | ||
|
||
public UpdateBackupScheduleTest(SpannerFixture spannerFixture) => _spannerFixture = spannerFixture; | ||
|
||
[Fact] | ||
public void TestUpdateBackupSchedule() | ||
{ | ||
var scheduleId = SpannerFixture.GenerateId("schedule-"); | ||
Assert.NotNull( | ||
new CreateFullBackupScheduleSample() | ||
.CreateFullBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId) | ||
); | ||
|
||
var sample = new UpdateBackupScheduleSample(); | ||
var schedule = sample.UpdateBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId); | ||
Assert.NotNull(schedule); | ||
|
||
new DeleteBackupScheduleSample() | ||
.DeleteBackupSchedule(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.DatabaseId, scheduleId); | ||
} | ||
} |
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,57 @@ | ||
// Copyright 2024 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. | ||
|
||
// [START spanner_create_full_backup_schedule] | ||
using Google.Cloud.Spanner.Admin.Database.V1; | ||
using Google.Cloud.Spanner.Common.V1; | ||
using Google.Protobuf.WellKnownTypes; | ||
using System; | ||
|
||
public class CreateFullBackupScheduleSample | ||
{ | ||
public BackupSchedule CreateFullBackupSchedule(string projectId, string instanceId, string databaseId, string scheduleId) | ||
{ | ||
DatabaseAdminClient client = DatabaseAdminClient.Create(); | ||
|
||
BackupSchedule response = client.CreateBackupSchedule( | ||
new CreateBackupScheduleRequest | ||
{ | ||
ParentAsDatabaseName = DatabaseName.FromProjectInstanceDatabase(projectId, instanceId, databaseId), | ||
BackupScheduleId = scheduleId, | ||
BackupSchedule = new BackupSchedule | ||
{ | ||
Spec = new BackupScheduleSpec | ||
{ | ||
CronSpec = new CrontabSpec | ||
{ | ||
Text = "30 12 * * *", | ||
} | ||
}, | ||
RetentionDuration = new Duration | ||
{ | ||
Seconds = 86400, | ||
}, | ||
EncryptionConfig = new CreateBackupEncryptionConfig | ||
{ | ||
EncryptionType = CreateBackupEncryptionConfig.Types.EncryptionType.UseDatabaseEncryption, | ||
}, | ||
FullBackupSpec = new FullBackupSpec { }, | ||
} | ||
}); | ||
|
||
Console.WriteLine($"Created full backup schedule: {response}"); | ||
return response; | ||
} | ||
} | ||
// [END spanner_create_full_backup_schedule] |
57 changes: 57 additions & 0 deletions
57
spanner/api/Spanner.Samples/CreateIncrementalBackupSchedule.cs
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,57 @@ | ||
// Copyright 2024 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. | ||
|
||
// [START spanner_create_incremental_backup_schedule] | ||
using Google.Cloud.Spanner.Admin.Database.V1; | ||
using Google.Cloud.Spanner.Common.V1; | ||
using Google.Protobuf.WellKnownTypes; | ||
using System; | ||
|
||
public class CreateIncrementalBackupScheduleSample | ||
{ | ||
public BackupSchedule CreateIncrementalBackupSchedule(string projectId, string instanceId, string databaseId, string scheduleId) | ||
{ | ||
DatabaseAdminClient client = DatabaseAdminClient.Create(); | ||
|
||
BackupSchedule response = client.CreateBackupSchedule( | ||
new CreateBackupScheduleRequest | ||
{ | ||
ParentAsDatabaseName = DatabaseName.FromProjectInstanceDatabase(projectId, instanceId, databaseId), | ||
BackupScheduleId = scheduleId, | ||
BackupSchedule = new BackupSchedule | ||
{ | ||
Spec = new BackupScheduleSpec | ||
{ | ||
CronSpec = new CrontabSpec | ||
{ | ||
Text = "30 12 * * *", | ||
} | ||
}, | ||
RetentionDuration = new Duration | ||
{ | ||
Seconds = 86400, | ||
}, | ||
EncryptionConfig = new CreateBackupEncryptionConfig | ||
{ | ||
EncryptionType = CreateBackupEncryptionConfig.Types.EncryptionType.GoogleDefaultEncryption, | ||
}, | ||
IncrementalBackupSpec = new IncrementalBackupSpec { }, | ||
} | ||
}); | ||
|
||
Console.WriteLine($"Created incremental backup schedule: {response}"); | ||
return response; | ||
} | ||
} | ||
// [END spanner_create_incremental_backup_schedule] |
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,34 @@ | ||
// Copyright 2024 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. | ||
|
||
// [START spanner_delete_backup_schedule] | ||
using Google.Cloud.Spanner.Admin.Database.V1; | ||
using System; | ||
|
||
public class DeleteBackupScheduleSample | ||
{ | ||
public void DeleteBackupSchedule(string projectId, string instanceId, string databaseId, string scheduleId) | ||
{ | ||
DatabaseAdminClient client = DatabaseAdminClient.Create(); | ||
|
||
client.DeleteBackupSchedule( | ||
new DeleteBackupScheduleRequest | ||
{ | ||
BackupScheduleName = BackupScheduleName.FromProjectInstanceDatabaseSchedule(projectId, instanceId, databaseId, scheduleId), | ||
}); | ||
|
||
Console.WriteLine("Deleted backup schedule"); | ||
} | ||
} | ||
// [END spanner_delete_backup_schedule] |
Oops, something went wrong.