> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# Cluster Snapshot

> Create and restore shared-data cluster snapshots and configure cross-region replication with external automated snapshots.

**Beta feature**

[Advice on use of Beta features](/documents/4.2/maturity/features.md)

This topic describes how to use Cluster Snapshot for disaster recovery on shared-data clusters.

This feature is supported from v3.4.2 onwards and only available on shared-data clusters.

## Overview

In a shared-data cluster, data files are stored in object storage, while FE metadata is stored locally. A cluster snapshot saves an FE metadata image and preserves the data needed to restore the cluster to that point in time. Use a [manual snapshot](#manual-cluster-snapshot) to retain a specific restore point, or use [cross-region incremental replication](#cross-region-incremental-replication) to keep a recovery copy in another region.

### Workflow

![Workflow](https://mintcdn.com/mirrorship-docs/8gpPdHU-sBXASb5i/documents/images/035a64ddf19999803138a485.png?fit=max\&auto=format\&n=8gpPdHU-sBXASb5i\&q=85\&s=d415319e6a29f7a95eccd951c84258c1)

### Terms

* **Cluster snapshot**

  A cluster snapshot refers to a snapshot of the cluster state at a certain moment. It contains all the objects in the cluster, such as catalogs, databases, tables, users & privileges, loading tasks, and more. It does not include all external dependent objects, such as configuration files of external catalogs, and local UDF JAR packages.

* **Generating cluster snapshot**

  The system replaces older automated snapshots as new ones complete. You can keep multiple named manual snapshots until you drop them.

* **Cluster Restore**

  Restore the cluster from a snapshot.

## Automated cluster snapshot

Automated Cluster Snapshot is disabled by default.

Use the following statement to enable this feature:

Syntax:

```SQL theme={null}
ADMIN SET AUTOMATED CLUSTER SNAPSHOT ON
[INTERVAL <value> <unit>]
[STORAGE VOLUME <storage_volume_name>]
[PROPERTIES ("key"="value", ...)]
```

Parameters:

`INTERVAL <value> <unit>`: The interval at which automated snapshots are created. `value` must be a positive integer, and `unit` must be one of `SECOND`, `MINUTE`, `HOUR`, `DAY`, and `WEEK`. If this parameter is not specified, the interval is controlled by the FE configuration item `automated_cluster_snapshot_interval_seconds`.

`storage_volume_name`: Specifies the storage volume used to store the snapshot. If this parameter is not specified, the built-in storage volume `builtin_storage_volume` is used, even if another storage volume is set as the default. If `builtin_storage_volume` does not exist (for example, because `enable_load_volume_from_conf` is `false`), the statement fails, and you must specify a storage volume. For details on creating a storage volume, see [CREATE STORAGE VOLUME](/documents/4.2/sql-reference/sql-statements/cluster-management/storage_volume/CREATE_STORAGE_VOLUME.md).

`snapshot_scope`: Use `local` (the default) for recovery within the same region, or `external` to replicate data to the specified storage volume for cross-region recovery.

Each time the snapshot interval has elapsed since the previous automated snapshot started, the Leader FE performs a metadata checkpoint to create a new metadata image, and creates a snapshot from it. The name of the snapshot is generated by the system, following the format `automated_cluster_snapshot_{timestamp}`.

Metadata snapshots are stored under `/{storage_volume_locations}/{service_id}/meta/image/automated_cluster_snapshot_timestamp`. With `snapshot_scope=local`, data files stay in their original location.

FE configuration item `automated_cluster_snapshot_interval_seconds` controls the snapshot automation cycle when no `INTERVAL` is specified for the feature. The default value is 600 seconds (10 minutes).

Use the following statement to change the interval while the feature is enabled (supported from v4.0.5 onwards, as is the `INTERVAL` clause):

```SQL theme={null}
ADMIN ALTER AUTOMATED CLUSTER SNAPSHOT SET INTERVAL <value> <unit>
```

Use the following statement to view whether the feature is enabled, the effective interval, the storage volume, and the time of the last and the next snapshot (supported from v4.0.6 onwards):

```SQL theme={null}
ADMIN SHOW AUTOMATED CLUSTER SNAPSHOT
```

### Disable automated cluster snapshot

Use the following statement to disable automated cluster snapshot:

```SQL theme={null}
ADMIN SET AUTOMATED CLUSTER SNAPSHOT OFF
```

Disabling automated snapshots removes local automated snapshots and retains the latest completed external snapshot if the scope was `external`.

### Cross-region incremental replication

Cross-region incremental replication supports only external automated snapshots (`snapshot_scope=external`). Create the destination [storage volume](/documents/4.2/sql-reference/sql-statements/cluster-management/storage_volume/CREATE_STORAGE_VOLUME.md) in the recovery region and make sure the source cluster can write to it. If automated snapshots are already enabled, disable them before enabling them with the new scope and destination.

```sql theme={null}
ADMIN SET AUTOMATED CLUSTER SNAPSHOT ON
STORAGE VOLUME dr_volume
PROPERTIES ("snapshot_scope" = "external");
```

The first successful run copies the data files referenced by the snapshot. Subsequent runs copy only the new or changed data files and write a complete FE metadata image each time. Each completed snapshot can be used for cross-region recovery. Before using the snapshot, query `information_schema.cluster_snapshot_jobs` and confirm that the job's `state` is `FINISHED`.

Before a recovery, record the completed snapshot's `storage_path` from `information_schema.cluster_snapshots`. Use that full URI in the [cross-region recovery configuration](#cross-region-recovery-configuration).

## Manual cluster snapshot

Create a named snapshot before a change for which you want to retain a restore point. The example writes the snapshot to the existing storage volume `snapshot_volume`.

```sql theme={null}
CREATE CLUSTER SNAPSHOT before_upgrade STORAGE VOLUME snapshot_volume;

SELECT state, error_message
FROM information_schema.cluster_snapshot_jobs
WHERE snapshot_name = 'before_upgrade';
```

Wait for the job to reach `FINISHED`. To recover the entire cluster, see [Restore the cluster](#restore-the-cluster). To recover one table, see [Restore a table from a manual snapshot](#restore-a-table-from-a-manual-snapshot). Drop the manual snapshot with `DROP CLUSTER SNAPSHOT before_upgrade` when you no longer need it. The FE parameter `max_manual_cluster_snapshot_jobs` controls how many manual snapshots can be retained (default `50`).

### Cross-region limits for manual snapshots

Manual snapshots always use local scope. Even when `STORAGE VOLUME` points to a remote volume, the snapshot job writes only metadata to that volume. The underlying data files stay in their original storage, so the metadata alone is insufficient for cross-region recovery.

### Restore a table from a manual snapshot

On the same shared-data cluster, restore a table from a completed snapshot into a new table. The destination database must exist and the destination table must be absent. For example, restore `sales.orders` as it was at `before_upgrade` into `sales.orders_restored`.

```sql theme={null}
RESTORE TABLE sales.orders
FROM SNAPSHOT before_upgrade
TO TABLE sales.orders_restored;
```

The restore runs asynchronously. Run `SHOW RESTORE FROM sales` to check the job status.

## View cluster snapshot

You can query the view `information_schema.cluster_snapshots` to view the latest cluster snapshot and the snapshots yet to be dropped.

```SQL theme={null}
SELECT * FROM information_schema.cluster_snapshots;
```

Return:

| Field | Description |
| - | - |
| snapshot\_name | The name of the snapshot. |
| snapshot\_type | The snapshot type. Valid values: `AUTOMATED`, `MANUAL`, `INCREMENTAL`, and `AUTO_FULL`. |
| created\_time | The time at which the snapshot was created. |
| fe\_journal\_id | The ID of the FE journal. |
| starmgr\_journal\_id | The ID of the StarManager journal. |
| properties | Applies to a feature not yet available. |
| storage\_volume | The storage volume where the snapshot is stored. |
| storage\_path | The storage path under which the snapshot is stored. |

## View cluster snapshot job

You can query the view `information_schema.cluster_snapshot_jobs` to view the job information of cluster snapshots.

```SQL theme={null}
SELECT * FROM information_schema.cluster_snapshot_jobs;
```

Return:

| Field | Description |
| - | - |
| snapshot\_name | The name of the snapshot. |
| job\_id | The ID of the job. |
| created\_time | The time at which the job was created. |
| finished\_time | The time at which the job was finished. |
| state | The state of the job. Valid values: `INITIALIZING`, `SNAPSHOTING`, `FINISHED`, `EXPIRED`, `DELETED`, and `ERROR`. |
| detail\_info | The specific progress information of the current execution stage. |
| error\_message | The error message (if any) of the job. |

## Restore the cluster

Follow these steps to restore the cluster with the cluster snapshot.

1. To select a named snapshot or recover into a different cluster, configure **cluster\_snapshot.yaml** in the Leader FE's `fe/conf` directory.

   * **Named manual snapshot.** Start with the [Appendix](#appendix) template. Set `cluster_snapshot.cluster_snapshot_path` to the full snapshot directory URI from `storage_path` in `information_schema.cluster_snapshots`. Set `cluster_snapshot.storage_volume_name` to the snapshot's storage volume and include that volume in `storage_volumes`. A path ending in `/meta` selects an automated snapshot.
   * **Cross-cluster recovery within a region.** Use the [Appendix](#appendix) template. If the target cluster uses a new storage path, copy all files under the original storage path to the new one.
   * **Cross-region recovery from an external snapshot.** Use the [cross-region recovery configuration](#cross-region-recovery-configuration) to read the completed snapshot and map the recovered cluster's writable storage.

2. Start the Leader FE node.

   ```Bash theme={null}
   ./fe/bin/start_fe.sh --cluster_snapshot --daemon
   ```

3. Start other FE nodes **after cleaning the `meta` directories**.

   ```Bash theme={null}
   ./fe/bin/start_fe.sh --helper <leader_ip>:<leader_edit_log_port> --daemon
   ```

   Add the nodes to the cluster.

   ```SQL theme={null}
   -- Add the Follower node:
   ALTER SYSTEM ADD FOLLOWER "<follower_host>:<follower_edit_log_port>";

   -- Add the Observer node:
   ALTER SYSTEM ADD OBSERVER "<observer_host>:<observer_edit_log_port>";
   ```

4. Start CN nodes **after cleaning the `storage_root_path` directories**.

   ```Bash theme={null}
   ./be/bin/start_cn.sh --daemon
   ```

   Add the node to the cluster.

   ```SQL theme={null}
   ALTER SYSTEM ADD COMPUTE NODE "<cn_host>:<cn_heartbeat_service_port>";
   ```

If you have modified **cluster\_snapshot.yaml** in the step 1, the node and storage volumes will be re-configured in the new cluster according to the information in the file.

## Appendix

Template of **cluster\_snapshot.yaml** for cross-cluster recovery:

```Yaml theme={null}
# Information of the cluster snapshot to be downloaded for restoration.
cluster_snapshot:
    # The URI of the snapshot.
    # Example 1: s3://defaultbucket/test/f7265e80-631c-44d3-a8ac-cf7cdc7adec811019/meta/image/automated_cluster_snapshot_1704038400000
    # Example 2: s3://defaultbucket/test/f7265e80-631c-44d3-a8ac-cf7cdc7adec811019/meta
    cluster_snapshot_path: <cluster_snapshot_uri>
    # The name of the storage volume to store the snapshot. You must define it in the `storage_volumes` section.
    # NOTE: It must be identical with that in the original cluster.
    storage_volume_name: my_s3_volume

# [Optional] Node information of the new cluster where the snapshot is to be restored.
# If this section is not specified, the new cluster after recovery only has the Leader FE node.
# CN nodes retain the information of the original cluster.
# NOTE: DO NOT include the Leader FE node in this section.

frontends:
    # FE host.
  - host: xxx.xx.xx.x1
    # FE edit_log_port.
    edit_log_port: 9010
    # The FE node type. Valid values: `follower` (Default) and `observer`.
    type: follower
  - host: xxx.xx.xx.x2
    edit_log_port: 9010
    type: observer

compute_nodes:
    # CN host.
  - host: xxx.xx.xx.x3
    # CN heartbeat_service_port.
    heartbeat_service_port: 9050
  - host: xxx.xx.xx.x4
    heartbeat_service_port: 9050

# Information of the storage volume in the new cluster. It is used for restoring a cloned snapshot.
# NOTE: The name of the storage volume must be identical with that in the original cluster.
storage_volumes:
  # Example for S3-compatible storage volume.
  - name: my_s3_volume
    type: S3
    location: s3://defaultbucket/test/
    comment: my s3 volume
    properties:
      - key: aws.s3.region
        value: us-west-2
      - key: aws.s3.endpoint
        value: https://s3.us-west-2.amazonaws.com
      - key: aws.s3.access_key
        value: xxxxxxxxxx
      - key: aws.s3.secret_key
        value: yyyyyyyyyy
  # Example for HDFS storage volume.
  - name: my_hdfs_volume
    type: HDFS
    location: hdfs://127.0.0.1:9000/sr/test/
    comment: my hdfs volume
    properties:
      - key: hadoop.security.authentication
        value: simple
      - key: username
        value: starrocks
```

**Note**

For more information on credentials for AWS, see [Authenticate to AWS S3](/documents/4.2/integrations/csp_auth/authenticate_to_aws_resources.md).

### Cross-region recovery configuration

The following `fe/conf/cluster_snapshot.yaml` example uses S3 in the recovery region. Replace `<completed_external_snapshot_uri>` with the `storage_path` of a finished external snapshot. The target cluster needs read access to `snapshot_storage_volume` and write access to the locations in `storage_volumes`. This example uses the AWS SDK default credential chain.

```yaml theme={null}
cluster_snapshot:
  cluster_snapshot_path: <completed_external_snapshot_uri>
  storage_volume_name: dr_volume
  snapshot_scope: external

snapshot_storage_volume:
  name: dr_volume
  type: S3
  location: s3://example-dr-snapshots/cluster-a/
  properties:
    - key: aws.s3.region
      value: us-west-2
    - key: aws.s3.endpoint
      value: https://s3.us-west-2.amazonaws.com
    - key: aws.s3.use_aws_sdk_default_behavior
      value: "true"

storage_volumes:
  - name: source_data_volume
    type: S3
    location: s3://example-dr-live/cluster-a/data/
    properties:
      - key: aws.s3.region
        value: us-west-2
      - key: aws.s3.endpoint
        value: https://s3.us-west-2.amazonaws.com
      - key: aws.s3.use_aws_sdk_default_behavior
        value: "true"
  - name: dr_volume
    type: S3
    location: s3://example-dr-live/cluster-a/dr-volume/
    properties:
      - key: aws.s3.region
        value: us-west-2
      - key: aws.s3.endpoint
        value: https://s3.us-west-2.amazonaws.com
      - key: aws.s3.use_aws_sdk_default_behavior
        value: "true"
```

The example assumes the source snapshot contains `source_data_volume` and `dr_volume`. Include all source storage volume names from your snapshot in `storage_volumes` and give each a writable location separate from the snapshot location. With the configuration in place, continue with the Leader FE startup step under [Restore the cluster](#restore-the-cluster).

## Limitations

* Currently, standby mode is not supported. The primary and secondary clusters cannot be online simultaneously. Otherwise, the normal operation of the secondary cluster cannot be guaranteed.
* Currently, only one automated cluster snapshot can be retained.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.