Backup
- TypeScript
- Python
import {
cloudApi,
decodeMessage,
serviceClients,
Session,
waitForOperation,
} from "@yandex-cloud/nodejs-sdk";
import { google } from "googleapis";
const BackupDatabaseRequest =
cloudApi.ydb.database_service.BackupDatabaseRequest;
const BackupSettings_StorageClass =
cloudApi.ydb.backup.BackupSettings_StorageClass;
const BackupSettings_Type = cloudApi.ydb.backup.BackupSettings_Type;
const Database = cloudApi.mdb.clickhouse_database.Database;
const DayOfWeek = google.type.dayofweek.DayOfWeek;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.DatabaseServiceClient);
const operation = await client.backup(
BackupDatabaseRequest.fromPartial({
// databaseId: "databaseId",
// backupSettings: {
// name: "name",
// description: "description",
// backupSchedule: {
// dailyBackupSchedule: {
// executeTime: {
// hours: 0,
// minutes: 0,
// seconds: 0,
// nanos: 0
// }
// },
// weeklyBackupSchedule: {
// daysOfWeek: [{
// days: [DayOfWeek.MONDAY],
// executeTime: {
// hours: 0,
// minutes: 0,
// seconds: 0,
// nanos: 0
// }
// }]
// },
// recurringBackupSchedule: {
// startTime: {
// seconds: 0,
// nanos: 0
// },
// recurrence: "recurrence"
// },
// nextExecuteTime: {
// seconds: 0,
// nanos: 0
// }
// },
// backupTimeToLive: {
// seconds: 0,
// nanos: 0
// },
// sourcePaths: ["sourcePaths"],
// sourcePathsToExclude: ["sourcePathsToExclude"],
// type: BackupSettings_Type.SYSTEM,
// storageClass: BackupSettings_StorageClass.STANDARD
// }
})
);
const finishedOp = await waitForOperation(operation, session);
if (finishedOp.response) {
const result = decodeMessage<typeof Database>(finishedOp.response);
console.log(result);
}
})();
import os
import grpc
import yandexcloud
import {google} from "googleapis";
from yandex.cloud.ydb.v1.database_service_pb2 import BackupDatabaseMetadata
from yandex.cloud.ydb.v1.database_service_pb2 import BackupDatabaseRequest
from yandex.cloud.ydb.v1.backup_pb2 import BackupSchedule
from yandex.cloud.ydb.v1.backup_pb2 import BackupSettings
from yandex.cloud.ydb.v1.backup_pb2 import DailyBackupSchedule
from yandex.cloud.mdb.clickhouse.v1.database_pb2 import Database
from yandex.cloud.mdb.clickhouse.v1.database_service_pb2_grpc import DatabaseServiceStub
const DayOfWeek = google.type.dayofweek;
from yandex.cloud.ydb.v1.backup_pb2 import DaysOfWeekBackupSchedule
from yandex.cloud.ydb.v1.backup_pb2 import RecurringBackupSchedule
const TimeOfDay = google.type.timeofday;
from yandex.cloud.ydb.v1.backup_pb2 import WeeklyBackupSchedule
token = os.getenv('YC_OAUTH_TOKEN')
sdk = yandexcloud.SDK(token=token)
service = sdk.client(DatabaseServiceStub)
operation = service.Backup(
BackupDatabaseRequest(
# database_id = "databaseId",
# backup_settings = BackupSettings(
# name = "name",
# description = "description",
# backup_schedule = BackupSchedule(
# daily_backup_schedule = DailyBackupSchedule(
# execute_time = TimeOfDay(
# hours = 0,
# minutes = 0,
# seconds = 0,
# nanos = 0
# )
# ),
# weekly_backup_schedule = WeeklyBackupSchedule(
# days_of_week = [DaysOfWeekBackupSchedule(
# days = [DayOfWeek.MONDAY],
# execute_time = TimeOfDay(
# hours = 0,
# minutes = 0,
# seconds = 0,
# nanos = 0
# )
# )]
# ),
# recurring_backup_schedule = RecurringBackupSchedule(
# start_time = Timestamp(
# seconds = 0,
# nanos = 0
# ),
# recurrence = "recurrence"
# ),
# next_execute_time = Timestamp(
# seconds = 0,
# nanos = 0
# )
# ),
# backup_time_to_live = Duration(
# seconds = 0,
# nanos = 0
# ),
# source_paths = ["sourcePaths"],
# source_paths_to_exclude = ["sourcePathsToExclude"],
# type = BackupSettings.Type.SYSTEM,
# storage_class = BackupSettings.StorageClass.STANDARD
# )
)
)
operation_result = sdk.wait_operation_and_get_result(
operation,
response_type=Database,
meta_type=BackupDatabaseMetadata,
)
print(operation_result)
BackupDatabaseRequest
databaseId
: string
backupSettings
: BackupSettings
custom backup options, if required.
BackupSettings
Type
TYPE_UNSPECIFIED
SYSTEM
USER
StorageClass
STORAGE_CLASS_UNSPECIFIED
STANDARD
REDUCED_REDUNDANCY
STANDARD_IA
ONEZONE_IA
INTELLIGENT_TIERING
GLACIER
DEEP_ARCHIVE
OUTPOSTS
name
: string
name of backup settings
description
: string
human readable description.
backupSchedule
: BackupSchedule
provide schedule. if empty, backup will be disabled.
backupTimeToLive
: google.protobuf.Duration
provide time to live of backup.
sourcePaths
: string
provide a list of source paths. Each path can be directory, table or even database itself. Each directory (or database) will be traversed recursively and all childs of directory will be included to backup. By default, backup will be created for full database.
sourcePathsToExclude
: string
provide a list of paths to exclude from backup. Each path is a directory, table, or database. Each directory (or database) will be traversed recursively and all childs of directory will be excluded.
type
: Type
storageClass
: StorageClass
BackupSchedule
One of policy
dailyBackupSchedule
: DailyBackupSchedule
weeklyBackupSchedule
: WeeklyBackupSchedule
recurringBackupSchedule
: RecurringBackupSchedule
nextExecuteTime
: google.protobuf.Timestamp
output only field: when next backup will be executed using provided schedule.
DailyBackupSchedule
executeTime
: google.type.TimeOfDay
WeeklyBackupSchedule
daysOfWeek
: DaysOfWeekBackupSchedule
RecurringBackupSchedule
startTime
: google.protobuf.Timestamp
Timestamp of the first recurrence.
recurrence
: string
An RRULE (https://tools.ietf.org/html/rfc5545#section-3.8.5.3) for how this backup reccurs. The FREQ values of MINUTELY, and SECONDLY are not supported.
DaysOfWeekBackupSchedule
days
: google.type.DayOfWeek
executeTime
: google.type.TimeOfDay
Operation
An Operation resource. For more information, see Operation.
id
: string
ID of the operation.
description
: string
Description of the operation. 0-256 characters long.
createdAt
: google.protobuf.Timestamp
Creation timestamp.
createdBy
: string
ID of the user or service account who initiated the operation.
modifiedAt
: google.protobuf.Timestamp
The time when the Operation resource was last modified.
done
: bool
If the value is false
, it means the operation is still in progress.
If true
, the operation is completed, and either error
or response
is available.
metadata
: google.protobuf.Any
Service-specific metadata associated with the operation. It typically contains the ID of the target resource that the operation is performed on. Any method that returns a long-running operation should document the metadata type, if any.
One of result
The operation result.
If done == false
and there was no failure detected, neither error
nor response
is set.
If done == false
and there was a failure detected, error
is set.
If done == true
, exactly one of error
or response
is set.
error
: google.rpc.StatusThe error result of the operation in case of failure or cancellation.
response
: google.protobuf.AnyThe normal response of the operation in case of success.
If the original method returns no data on success, such as Delete, the response is google.protobuf.Empty. If the original method is the standard Create/Update, the response should be the target resource of the operation. Any method that returns a long-running operation should document the response type, if any.