Managing backups in Managed Service for ClickHouse®
You can create backups and restore clusters from existing backups.
Managed Service for ClickHouse® also creates automatic daily backups. You can set the backup start time and retention period.
Creating a backup
Warning
Backups are created based on a random replica host. If there is no cluster host data consistency, restoring clusters from backups does not guarantee complete data recovery. For more information, see Backups.
- Go to the folder page
and select Managed Service for ClickHouse. - Click the cluster name and open the Backups tab.
- Click Create backup.
The service will start creating a backup without an additional confirmation.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To create a cluster backup:
-
View a description of the CLI create ClickHouse® backup command:
yc managed-clickhouse cluster backup --help
-
Request the creation of a backup specifying the cluster name or ID:
yc managed-clickhouse cluster backup <cluster_name_or_ID>
You can get the cluster name and ID with a list of clusters in the folder.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Cluster.backup method and make a request, e.g., via cURL
:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>:backup'
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the ClusterService/Backup call and make a request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.Backup
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
Warning
While you are creating your backup, the cluster performance might degrade.
Restoring clusters from backups
When you restore a cluster from a backup, you create a new cluster with the backup data. If the cloud does not have sufficient resources to create such a cluster, you will not be able to restore your data from a backup. The average backup recovery speed is 10 MBps per database core.
You can restore an individual shard or the whole cluster. You can restore the whole cluster only by using the CLI or API.
Before you begin, make sure your account in Yandex Cloud has the iam.serviceAccounts.user role or higher. You will need this role if the cluster you want to restore is linked to a service account.
Important
When restoring a backup to a cluster without any ZooKeeper hosts, all the tables in the ReplicatedMergeTree family engine are converted to simple MergeTree tables. Data in the converted tables is saved. For more information, see the ClickHouse® documentation
To restore an existing cluster from a backup:
- Go to the folder page
and select Managed Service for ClickHouse. - Click the cluster name and open the Backups tab.
- Click
for the backup you need and click Restore cluster. - Change the settings of the new cluster if required. You can select a folder for the new cluster from the Folder list.
- Click Restore cluster.
To restore a previously deleted cluster from a backup:
- Go to the folder page
and select Managed Service for ClickHouse. - In the left-hand panel, select
Backups. - Find the backup you need using the backup creation time and cluster ID. The ID column contains IDs formatted as
<cluster_ID>:<backup_IP>
. - Click
for the backup you need and click Restore cluster. - Change the settings of the new cluster if required. You can select a folder for the new cluster from the Folder list.
- Click Restore cluster.
Managed Service for ClickHouse® will launch the operation to create a cluster from the backup.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To restore a cluster from a backup:
-
View a description of the CLI restore ClickHouse® cluster command:
yc managed-clickhouse cluster restore --help
-
Getting a list of available ClickHouse® cluster backups:
yc managed-clickhouse backup list
+--------------------------+---------------------+----------------------+---------------------+-------------+-------+-----------+ | ID | CREATED AT | SOURCE CLUSTER ID | STARTED AT | SHARD NAMES | SIZE | TYPE | +--------------------------+---------------------+----------------------+---------------------+-------------+-------+-----------+ | c9qud5etkq19********:... | 2023-12-08 00:09:17 | c9qud5etkq19******** | 2023-12-08 00:08:06 | shard1 | 30 KB | AUTOMATED | | ... | | | | | | | +--------------------------+---------------------+----------------------+---------------------+-------------+-------+-----------+
-
To restore an individual shard, pass the ID of a single backup:
yc managed-clickhouse cluster restore \ --backup-id=<backup_ID> \ --name=<cluster_name> \ --environment=<environment> \ --network-name=<network_name> \ --host type=<host_type>,` `zone-id=<availability_zone>,` `subnet-id=<subnet_ID> \ --clickhouse-disk-size=<storage_size_in_GB> \ --clickhouse-disk-type=<disk_type> \ --clickhouse-resource-preset=<host_class>
Where:
-
--backup-id
: Backup ID. -
--name
: Cluster name. -
--environment
: Environment:PRODUCTION
: For stable versions of your apps.PRESTABLE
: For testing purposes. The prestable environment is similar to the production environment and likewise covered by the SLA, but it is the first to get new functionalities, improvements, and bug fixes. In the prestable environment, you can test compatibility of new versions with your application.
-
--network-name
: Network name. -
--host
: Host parameters:type
: Host type:clickhouse
orzookeeper
.zone-id
: Availability zone.subnet-id
: Subnet ID. Specify if two or more subnets are created in the selected availability zone.
-
--resource-preset
: Host class. -
--disk-size
: Storage size in GB. -
--disk-type
: Disk type:-
network-hdd
-
network-ssd
-
local-ssd
-
network-ssd-nonreplicated
-
-
-
To restore the entire cluster, provide backup IDs for all cluster shards:
yc managed-clickhouse cluster restore \ --backup-id=<list_of_backup_IDs_for_all_shards> \ ...
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Cluster.restore method and make a request, e.g., via cURL
:-
Create a file named
body.json
and add the following contents to it:{ "backupId": "<backup_ID>", "additionalBackupIds": [ <list_of_additional_IDs_of_backups> ], "name": "<cluster_name>", "environment": "<environment>", "configSpec": { <cluster_configuration> }, "hostSpecs": [ { "type": "<host_type>", "zoneId": "<availability_zone>", "subnetId": "<subnet_ID>", "shardName": "<shard_name>", "assignPublicIp": <public_access_to_host> }, { <similar_configuration_for_host_2> }, { ... }, { <similar_configuration_for_host_N> } ], "folderId": "<folder_ID>", "networkId": "<network_ID>", "serviceAccountId": "<service_account_ID>", "securityGroupIds": [ <list_of_security_group_IDs> ], "deletionProtection": <deletion_protection> }
Where:
-
backupId
: Backup ID.The shard for which that backup was created will be restored.
-
additionalBackupIds
: Array containing a list of additional IDs of your backups.The shards for which those backups were created will be restored. To restore the entire cluster, provide backup IDs for all cluster shards.
-
name
: Cluster name. -
environment
: Environment:PRODUCTION
: For stable versions of your apps.PRESTABLE
: For testing purposes. The prestable environment is similar to the production environment and likewise covered by the SLA, but it is the first to get new functionalities, improvements, and bug fixes. In the prestable environment, you can test compatibility of new versions with your application.
-
configSpec
: ClickHouse® cluster configuration. For detailed description of the parameters, see the Cluster.restore method description. -
hostSpecs
: Array with settings for the new hosts. One array element contains settings for a single host and has the following structure:type
: Host type.zoneId
: Availability zone.subnetId
: Subnet ID.shardName
: Shard name.assignPublicIp
: Internet access to the host via a public IP address,true
orfalse
.
-
folderId
: ID of the folder to create your cluster in. -
networkId
: ID of the network to create your cluster in. -
serviceAccountId
: Service account ID. -
securityGroupIds
: Array of security group IDs. -
deletionProtection
: Option to manage protection of the cluster, its databases, and its users against accidental deletion.Enabled deletion protection will not prevent a manual connection and database content deletion.
You can get the backup ID together with a list of backups in the relevant folder.
-
-
Run this request:
curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters:restore' \ --data "@body.json"
-
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the ClusterService/Restore call and make a request, e.g., via gRPCurl
:-
Create a file named
body.json
and add the following contents to it:{ "backup_id": "<backup_ID>", "additional_backup_ids": [ <list_of_additional_IDs_of_backups> ], "name": "<cluster_name>", "environment": "<environment>", "config_spec": { <cluster_configuration> }, "host_specs": [ { "type": "<host_type>", "zone_id": "<availability_zone>", "subnet_id": "<subnet_ID>", "shard_name": "<shard_name>", "assign_public_ip": <public_access_to_host> }, { <similar_configuration_for_host_2> }, { ... }, { <similar_configuration_for_host_N> } ], "folder_id": "<folder_ID>", "network_id": "<network_ID>", "service_account_id": "<service_account_ID>", "security_group_ids": [ <list_of_security_group_IDs> ], "deletion_protection": <deletion_protection> }
Where:
-
backup_id
: Backup ID.The shard for which that backup was created will be restored.
-
additional_backup_ids
: Array containing a list of additional IDs of your backups.The shards for which those backups were created will be restored. To restore the entire cluster, provide backup IDs for all cluster shards.
-
name
: Cluster name. -
environment
: Environment:PRODUCTION
: For stable versions of your apps.PRESTABLE
: For testing purposes. The prestable environment is similar to the production environment and likewise covered by the SLA, but it is the first to get new functionalities, improvements, and bug fixes. In the prestable environment, you can test compatibility of new versions with your application.
-
config_spec
: ClickHouse® cluster configuration. For detailed description of the parameters, see the ClusterService/Restore call description. -
host_specs
: Array with settings for the new hosts. One array element contains settings for a single host and has the following structure:type
: Host type.zone_id
: Availability zone.subnet_id
: Subnet ID.shard_name
: Shard name.assign_public_ip
: Internet access to the host via a public IP address,true
orfalse
.
-
folder_id
: ID of the folder to create your cluster in. -
network_id
: ID of the network to create your cluster in. -
service_account_id
: Service account ID. -
security_group_ids
: Array of security group IDs. -
deletion_protection
: Option to manage protection of the cluster, its databases, and its users against accidental deletion.Enabled deletion protection will not prevent a manual connection and database content deletion.
You can get the backup ID together with a list of backups in the relevant folder.
-
-
Run this request:
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d @ \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.Restore \ < body.json
-
-
View the server response to make sure the request was successful.
Getting a list of backups
To get a list of cluster backups:
- Go to the folder page
and select Managed Service for ClickHouse. - Click the cluster name and open the Backups tab.
To get a list of all backups in a folder:
- Go to the folder page
and select Managed Service for ClickHouse. - In the left-hand panel, select
Backups.
These lists contain the following information:
- Backup name.
- Source shard.
- Backup size.
- Backup type: Automatic (
Automated
) or manual (Manual
). - Start time of backup creation in UTC (Coordinated Universal Time).
- End time of backup creation in UTC.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To get a list of ClickHouse® cluster backups available in the default folder, run the command:
yc managed-clickhouse backup list
+--------------------------+---------------------+----------------------+---------------------+-------------+-------+-----------+
| ID | CREATED AT | SOURCE CLUSTER ID | STARTED AT | SHARD NAMES | SIZE | TYPE |
+--------------------------+---------------------+----------------------+---------------------+-------------+-------+-----------+
| c9qud5etkq19********:... | 2023-12-08 00:09:17 | c9qud5etkq19******** | 2023-12-08 00:08:06 | shard1 | 30 KB | AUTOMATED |
| c9qud5etkq19********:... | 2023-12-07 08:17:04 | c9qud5etkq19******** | 2023-12-07 08:15:54 | shard1 | 30 KB | MANUAL |
+--------------------------+---------------------+----------------------+---------------------+-------------+-------+-----------+
The resulting table contains the following information:
- ID of the backup.
- End time of backup creation in UTC (Coordinated Universal Time).
- ID of the cluster that the backup was created for.
- Start time of backup creation in UTC.
- Source shard name.
- Backup size.
- Backup type: Automatic (
AUTOMATED
) or manual (MANUAL
).
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
To get a list of ClickHouse® cluster backups:
-
Use the Cluster.listBackups method and make a request, e.g., via cURL
:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/backups'
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
-
To get a list of backups for all the ClickHouse® clusters in a folder:
-
Use the Backup.list method and make a request, e.g., via cURL
:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/backups' \ --url-query folderId=<folder_ID>
You can request the folder ID with a list of folders in the cloud.
-
View the server response to make sure the request was successful.
-
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
To get a list of ClickHouse® cluster backups:
-
Use the ClusterService/ListBackups call and make a request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.ListBackups
You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
-
To get a list of backups for all the ClickHouse® clusters in a folder:
-
Use the BackupService/List call and make a request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/backup_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "folder_id": "<folder_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.BackupService.List
You can request the folder ID with a list of folders in the cloud.
-
View the server response to make sure the request was successful.
-
Getting information about backups
To get information about the backup of an existing cluster:
- Go to the folder page
and select Managed Service for ClickHouse. - Click the cluster name and open the Backups tab.
To get information about the backup of a previously deleted cluster:
- Go to the folder page
and select Managed Service for ClickHouse. - In the left-hand panel, select
Backups.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To get information about a ClickHouse® cluster backup, run the command:
yc managed-clickhouse backup get <backup_ID>
You can retrieve the backup ID with a list of backups.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Backup.get method and make a request, e.g., via cURL
:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/backups/<backup_ID>'
You can get the backup ID together with a list of backups in the relevant folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the BackupService/Get call and make a request, e.g., via gRPCurl
:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/backup_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "backup_id": "<backup_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.BackupService.Get
You can get the backup ID together with a list of backups in the relevant folder.
-
View the server response to make sure the request was successful.
Setting the backup start time
In the management console
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To set the backup start time, provide the required value in HH:MM:SS
format in the --backup-window-start
argument of the cluster update
command:
yc managed-clickhouse cluster update <cluster_name_or_ID> \
--backup-window-start=<backup_start_time>
You can request the cluster ID and name with a list of clusters in the folder.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Cluster.update method and make a request, e.g., via cURL
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
updateMask
parameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>' \ --data '{ "updateMask": "configSpec.backupWindowStart", "configSpec": { "backupWindowStart": { "hours": "<hours>", "minutes": "<minutes>", "seconds": "<seconds>", "nanos": "<nanoseconds>" } } }'
Where:
-
updateMask
: List of parameters to update as a single string, separated by commas.Here only one parameter is specified:
configSpec.backupWindowStart
. -
configSpec.backupWindowStart
: Backup start time (UTC):hours
: Hours in 24-hour formatminutes
: Minutesseconds
: Secondsnanos
: Nanoseconds
You can get the cluster ID with a list of clusters in the folder.
-
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the ClusterService/Update call and make a request, e.g., via gRPCurl
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
update_mask
parameter as an array ofpaths[]
strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "update_mask": { "paths": [ "config_spec.backup_window_start" ] }, "config_spec": { "backup_window_start": { "hours": "<hours>", "minutes": "<minutes>", "seconds": "<seconds>", "nanos": "<nanoseconds>" } } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.Update
Where:
-
update_mask
: List of parameters to update as an array ofpaths[]
strings.Here only one parameter is specified:
config_spec.backup_window_start
. -
config_spec.backup_window_start
: Backup start time (UTC):hours
: Hours in 24-hour formatminutes
: Minutesseconds
: Secondsnanos
: Nanoseconds
You can get the cluster ID with a list of clusters in the folder.
-
-
View the server response to make sure the request was successful.
Setting a retention period for automatic backups
In the management console
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To set the retention period for automatic backups, provide the required value in HH:MM:SS
format in the --backup-retain-period-days
argument of the cluster update command:
yc managed-clickhouse cluster update <cluster_name_or_ID> \
--backup-retain-period-days=<automatic_backup_retention_period_in_days>
You can request the cluster ID and name with a list of clusters in the folder.
To set the retention period for automatic backups, use the update REST API method for the Cluster resource or the Cluster/Update gRPC API call and provide the following in the request:
- Cluster ID in the
clusterId
parameter. You can get it with a list of clusters in the folder. - New automatic backup retention period in days in the
configSpec.backupRetainPeriodDays
parameter. - List of updatable cluster configuration fields in the
updateMask
parameter (in this case,configSpec.backupRetainPeriodDays
).
- View the server response to make sure the request was successful.
ClickHouse® is a registered trademark of ClickHouse, Inc