BACKUP / RESTORE to or from an S3 endpoint
This article covers backing up or restoring backups to/from an S3 bucket via an S3 endpoint.
Syntax
See "command summary" for more details of each command.
Usage example
Incremental backup to an S3 endpoint
In this example, we will create a backup to an S3 endpoint and then restore from it again.
For an explanation of the differences between a full backup and an incremental backup, see "Backup types"
You will need the following information to use this method:
| Parameter | Example |
|---|---|
| An S3 endpoint | https://backup-ch-docs.s3.us-east-1.amazonaws.com/backups/ |
| Access key ID | BKIOZLE2VYN3VXXTP9RC |
| Secret access key | 40bwYnbqN7xU8bVePaUCh3+YEyGXu8UOMV9ANpwL |
Creating an S3 bucket is covered in section "use S3 Object Storage as a ClickHouse disk"
The destination for a backup is specified as:
Create a base backup
Incremental backups require a base backup to start from. The first parameter of
the S3 destination is the S3 endpoint followed by the directory within the bucket
to use for this backup. In this example the directory is named my_backup.
Run the following command to create the base backup:
Add more data
Incremental backups are populated with the difference between the base backup and the current content of the table being backed up. Add more data before taking the incremental backup:
Take an incremental backup
This backup command is similar to the base backup, but adds SETTINGS base_backup and the location of the base backup. Note that the destination for the incremental backup is not the same directory as the base, it is the same endpoint with a different target directory within the bucket. The base backup is in my_backup, and the incremental will be written to my_incremental:
Restore from the incremental backup
This command restores the incremental backup into a new table, test_table_restored.
Note that when an incremental backup is restored, the base backup is also included.
Specify only the incremental backup when restoring:
Verify the count
There were two inserts into the original table data, one with 1,000 rows and one with 100 rows, for a total of 1,100.
Verify that the restored table has 1,100 rows:
Verify the content
This compares the content of the original table, test_table with the restored table test_table_restored: