Skip to main content

Backup

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);
}
})();

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.Status

    The error result of the operation in case of failure or cancellation.

  • response : google.protobuf.Any
    The 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.