- Internal databases, tables (of all types and partitioning strategies), and partitions
- Metadata of external catalogs (supported from v3.4.0 onwards)
- Synchronous materialized views and asynchronous materialized views
- Logical views (supported from v3.4.0 onwards)
- User-defined functions (supported from v3.4.0 onwards)
CAUTION
- Shared-data clusters do not support data BACKUP and RESTORE.
- In each database, only one running BACKUP or RESTORE job is allowed each time. Otherwise, the database returns an error.
- the database does not support specifying data compression algorithm for data backup.
Privilege requirement
In versions earlier than v3.0, users with theadmin_priv privilege can perform this operation. In v3.0 and later versions, to back up a specific object, users must have the REPOSITORY privilege at the System level and the EXPORT privilege for the corresponding table or all tables under the corresponding database. For example:
-
Grant the role permission to export data from the specified table.
-
Grant the role permission to export data from all tables under the specified data.
-
Grant the role permission to export data from all tables in all databases.
Syntax compatible with earlier versions
Parameters
Syntax supported from v3.4.0 onwards
Parameters
Snapshot retention
Thettl property sets how long the snapshot created by a BACKUP job is kept. It is resolved to an absolute expiration time when the backup finishes, and written into the snapshot itself, together with the ID of the cluster that created it. Both are shown by SHOW SNAPSHOT.
A snapshot is deleted automatically once it expires. Only a snapshot that was given a ttl ever carries an expiration, so a backup taken without one is never touched. Set the FE configuration item enable_backup_snapshot_auto_clean to false to stop cleanup entirely. Cleanup only ever deletes snapshots created by the cluster running it, so clusters sharing a repository never delete each other’s snapshots. Snapshots created before v4.2.0 record no cluster ID and are never deleted automatically.
The retention of an existing snapshot cannot be changed. Use DROP SNAPSHOT to delete a snapshot before it expires.
Retention is supported from v4.2.0 onwards.
Examples
Examples with syntax compatible with earlier versions
Example 1: Backs up the databaseexample_db to the repository example_repo.
example_tbl in example_db to example_repo.
p1 and p2 of example_tbl and the table example_tbl2 in example_db to example_repo.
Examples with syntax supported from v3.4.0 onwards
Example 1: Backs up a database.Usage notes
- Performing backup and restore operations on global, database, table, and partition levels requires different privileges.
- In each database, only one running BACKUP or RESTORE job is allowed each time. Otherwise, the database returns an error.
- Because BACKUP and RESTORE jobs occupy many resources of your cluster, you can back up and restore your data while your cluster is not heavily loaded.
- The database does not support specifying data compression algorithms for data backup.
- Because data is backed up as snapshots, the data loaded upon snapshot generation is not included in the snapshot. Therefore, if you load data into the old cluster after the snapshot is generated and before the RESTORE job is completed, you also need to load the data into the cluster that data is restored into. It is recommended that you load data into both clusters in parallel for a period of time after the data migration is complete, and then migrate your application to the new cluster after verifying the correctness of the data and services.
- Before the RESTORE job is completed, you cannot operate the table to be restored.
- Primary Key tables cannot be restored to a cluster earlier than v2.5.
- You do not need to create the table to be restored in the new cluster before restoring it. The RESTORE job automatically creates it.
- If there is an existing table that has a duplicated name with the table to be restored, the database first checks whether or not the schema of the existing table matches that of the table to be restored. If the schemas match, the database overwrites the existing table with the data in the snapshot. If the schema does not match, the RESTORE job fails. You can either rename the table to be restored using the keyword
AS, or delete the existing table before restoring data. - If the RESTORE job overwrites an existing database, table, or partition, the overwritten data cannot be restored after the job enters the COMMIT phase. If the RESTORE job fails or is canceled at this point, the data may be corrupted and inaccessible. In this case, you can only perform the RESTORE operation again and wait for the job to complete. Therefore, we recommend that you do not restore data by overwriting unless you are sure that the current data is no longer used. The overwrite operation first checks metadata consistency between the snapshot and the existing database, table, or partition. If an inconsistency is detected, the RESTORE operation cannot be performed.
- Currently, the database does not support backing up and restoring the configuration data related to user accounts, privileges, and resource groups.
- By default, the database does not restore the Colocate Join relationship among tables. From v3.2.10 and v3.3.2 onwards, in shared-nothing clusters, you can set the FE configuration item
enable_colocate_restoretotrueso that the restored tables keep their Colocate Join relationship. This applies only to tables that do not already exist in the target cluster.