|
| 1 | +--- |
| 2 | +title: Backing Up and Restoring Data with BendSave |
| 3 | +--- |
| 4 | + |
| 5 | +This tutorial walks you through how to back up and restore data using BendSave. We'll use a local MinIO instance as both the S3-compatible storage backend for Databend and the destination for storing backups. |
| 6 | + |
| 7 | +## Before You Start |
| 8 | + |
| 9 | +Before you start, ensure you have the following prerequisites in place: |
| 10 | + |
| 11 | +- A Linux machine (x86_64 or aarch64 architecture): In this tutorial, we'll deploy Databend on a Linux machine. You can use a local machine, a virtual machine, or a cloud instance such as AWS EC2. |
| 12 | + - [Docker](https://www.docker.com/): Used to deploy a local MinIO instance. |
| 13 | + - [AWS CLI](https://aws.amazon.com/cli/): Used to manage buckets in MinIO. |
| 14 | + - If you are on AWS EC2, make sure your security group allows inbound traffic on port `8000`, as this is required for BendSQL to connect to Databend. |
| 15 | + |
| 16 | +- BendSQL is installed on your local machine. See [Installing BendSQL](/guides/sql-clients/bendsql/#installing-bendsql) for instructions on how to install BendSQL using various package managers. |
| 17 | + |
| 18 | +## Step 1: Launch MinIO in Docker |
| 19 | + |
| 20 | +1. Start a MinIO container on your Linux machine. The following command launches a MinIO container named **minio**, with ports `9000` (for the API) and `9001` (for the web console) exposed: |
| 21 | + |
| 22 | +```bash |
| 23 | +docker run -d --name minio \ |
| 24 | + -e "MINIO_ACCESS_KEY=minioadmin" \ |
| 25 | + -e "MINIO_SECRET_KEY=minioadmin" \ |
| 26 | + -p 9000:9000 \ |
| 27 | + -p 9001:9001 \ |
| 28 | + minio/minio server /data \ |
| 29 | + --address :9000 \ |
| 30 | + --console-address :9001 |
| 31 | +``` |
| 32 | + |
| 33 | +2. Set your MinIO credentials as environment variables, then use the AWS CLI to create two buckets: one for storing backups (**backupbucket**) and another for Databend data (**databend**): |
| 34 | + |
| 35 | +```bash |
| 36 | +export AWS_ACCESS_KEY_ID=minioadmin |
| 37 | +export AWS_SECRET_ACCESS_KEY=minioadmin |
| 38 | + |
| 39 | +aws --endpoint-url http://127.0.0.1:9000/ s3 mb s3://backupbucket |
| 40 | +aws --endpoint-url http://127.0.0.1:9000/ s3 mb s3://databend |
| 41 | +``` |
| 42 | + |
| 43 | +## Step 2: Set up Databend |
| 44 | + |
| 45 | +1. Download the latest Databend release and extract it to get the necessary binaries: |
| 46 | + |
| 47 | +```bash |
| 48 | +wget https://github.com/databendlabs/databend/releases/download/v1.2.719-nightly/databend-dbg-v1.2.719-nightly-x86_64-unknown-linux-gnu.tar.gz |
| 49 | + |
| 50 | +tar -xzvf databend-dbg-v1.2.719-nightly-x86_64-unknown-linux-gnu.tar.gz |
| 51 | +``` |
| 52 | + |
| 53 | +2. Configure the **databend-query.toml** configuration file in the **configs** folder. |
| 54 | + |
| 55 | +```bash |
| 56 | +vi configs/databend-query.toml |
| 57 | +``` |
| 58 | + |
| 59 | +The following shows the key configuration required for this tutorial: |
| 60 | + |
| 61 | +```toml |
| 62 | +... |
| 63 | +[[query.users]] |
| 64 | +name = "root" |
| 65 | +auth_type = "no_password" |
| 66 | +... |
| 67 | +# Storage config. |
| 68 | +[storage] |
| 69 | +# fs | s3 | azblob | gcs | oss | cos | hdfs | webhdfs |
| 70 | +type = "s3" |
| 71 | +... |
| 72 | +# To use an Amazon S3-like storage service, uncomment this block and set your values. |
| 73 | +[storage.s3] |
| 74 | +bucket = "databend" |
| 75 | +endpoint_url = "http://127.0.0.1:9000" |
| 76 | +access_key_id = "minioadmin" |
| 77 | +secret_access_key = "minioadmin" |
| 78 | +enable_virtual_host_style = false |
| 79 | +``` |
| 80 | + |
| 81 | +3. Use the following commands to start the Meta and Query services: |
| 82 | + |
| 83 | +```bash |
| 84 | +./databend-meta -c ../configs/databend-meta.toml > meta.log 2>&1 & |
| 85 | +``` |
| 86 | + |
| 87 | +```bash |
| 88 | +./databend-query -c ../configs/databend-query.toml > query.log 2>&1 & |
| 89 | +``` |
| 90 | + |
| 91 | +After launching the services, verify they are running by checking their health endpoints. A successful response should return HTTP status 200 OK. |
| 92 | + |
| 93 | +```bash |
| 94 | +curl -I http://127.0.0.1:28101/v1/health |
| 95 | + |
| 96 | +curl -I http://127.0.0.1:8080/v1/health |
| 97 | +``` |
| 98 | + |
| 99 | +4. Connect to your Databend instance from your local machine with BendSQL, then apply your Databend Enterprise license, create a table, and insert some sample data. |
| 100 | + |
| 101 | +```bash |
| 102 | +bendsql -h <your-linux-host> |
| 103 | +``` |
| 104 | + |
| 105 | +```sql |
| 106 | +SET GLOBAL enterprise_license='<your-license-key>'; |
| 107 | +``` |
| 108 | + |
| 109 | +```sql |
| 110 | +CREATE TABLE books ( |
| 111 | + id BIGINT UNSIGNED, |
| 112 | + title VARCHAR, |
| 113 | + genre VARCHAR DEFAULT 'General' |
| 114 | +); |
| 115 | + |
| 116 | +INSERT INTO books(id, title) VALUES(1, 'Invisible Stars'); |
| 117 | +``` |
| 118 | + |
| 119 | +5. Back on your Linux machine, verify that the table data has been stored in your Databend bucket: |
| 120 | + |
| 121 | +```bash |
| 122 | +aws --endpoint-url http://127.0.0.1:9000 s3 ls s3://databend/ --recursive |
| 123 | +``` |
| 124 | + |
| 125 | +```bash |
| 126 | +2025-04-07 15:27:06 748 1/169/_b/h0196160323247b1cab49be6060d42df8_v2.parquet |
| 127 | +2025-04-07 15:27:06 646 1/169/_sg/h0196160323247c5eb0a1a860a6442c70_v4.mpk |
| 128 | +2025-04-07 15:27:06 550 1/169/_ss/h019610dcc72474adb32ef43698db2a09_v4.mpk |
| 129 | +2025-04-07 15:27:06 143 1/169/last_snapshot_location_hint_v2 |
| 130 | +``` |
| 131 | + |
| 132 | +## Step 3: Back up with BendSave |
| 133 | + |
| 134 | +1. Run the following command to back up your Databend data to the **backupbucket** in MinIO: |
| 135 | + |
| 136 | +```bash |
| 137 | +export AWS_ACCESS_KEY_ID=minioadmin |
| 138 | +export AWS_SECRET_ACCESS_KEY=minioadmin |
| 139 | + |
| 140 | +./databend-bendsave backup \ |
| 141 | + --from ../configs/databend-query.toml \ |
| 142 | + --to 's3://backupbucket?endpoint=http://127.0.0.1:9000/®ion=us-east-1' |
| 143 | +<jemalloc>: Number of CPUs detected is not deterministic. Per-CPU arena disabled. |
| 144 | +Backing up from ../configs/databend-query.toml to s3://backupbucket?endpoint=http://127.0.0.1:9000/®ion=us-east-1 |
| 145 | +``` |
| 146 | + |
| 147 | +2. After the backup completes, you can verify that the files were written to the backupbucket by listing its contents: |
| 148 | + |
| 149 | +```bash |
| 150 | +aws --endpoint-url http://127.0.0.1:9000 s3 ls s3://backupbucket/ --recursive |
| 151 | +``` |
| 152 | + |
| 153 | +```bash |
| 154 | +2025-04-07 15:44:29 748 1/169/_b/h0196160323247b1cab49be6060d42df8_v2.parquet |
| 155 | +2025-04-07 15:44:29 646 1/169/_sg/h0196160323247c5eb0a1a860a6442c70_v4.mpk |
| 156 | +2025-04-07 15:44:29 550 1/169/_ss/h019610dcc72474adb32ef43698db2a09_v4.mpk |
| 157 | +2025-04-07 15:44:29 143 1/169/last_snapshot_location_hint_v2 |
| 158 | +2025-04-07 15:44:29 344781 databend_meta.db |
| 159 | +``` |
| 160 | + |
| 161 | +## Step 4: Restore with BendSave |
| 162 | + |
| 163 | +1. Remove all the file in the **databend** bucket: |
| 164 | + |
| 165 | +```bash |
| 166 | +aws --endpoint-url http://127.0.0.1:9000 s3 rm s3://databend/ --recursive |
| 167 | +``` |
| 168 | + |
| 169 | +2. After the removal, you can verify using BendSQL that querying the table in Databend fails: |
| 170 | + |
| 171 | +```sql |
| 172 | +SELECT * FROM books; |
| 173 | +``` |
| 174 | + |
| 175 | +```bash |
| 176 | +error: APIError: QueryFailed: [3001]NotFound (persistent) at read, context: { uri: http://127.0.0.1:9000/databend/1/169/_ss/h019610dcc72474adb32ef43698db2a09_v4.mpk, response: Parts { status: 404, version: HTTP/1.1, headers: {"accept-ranges": "bytes", "content-length": "423", "content-type": "application/xml", "server": "MinIO", "strict-transport-security": "max-age=31536000; includeSubDomains", "vary": "Origin", "vary": "Accept-Encoding", "x-amz-id-2": "dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8", "x-amz-request-id": "18342C51C209C7E9", "x-content-type-options": "nosniff", "x-ratelimit-limit": "144", "x-ratelimit-remaining": "144", "x-xss-protection": "1; mode=block", "date": "Mon, 07 Apr 2025 23:14:45 GMT"} }, service: s3, path: 1/169/_ss/h019610dcc72474adb32ef43698db2a09_v4.mpk, range: 0- } => S3Error { code: "NoSuchKey", message: "The specified key does not exist.", resource: "/databend/1/169/_ss/h019610dcc72474adb32ef43698db2a09_v4.mpk", request_id: "18342C51C209C7E9" } |
| 177 | +``` |
| 178 | +
|
| 179 | +3. Run the following command to restore your Databend data to the **databend** bucket in MinIO: |
| 180 | +
|
| 181 | +```bash |
| 182 | +./databend-bendsave restore \ |
| 183 | + --from "s3://backupbucket?endpoint=http://127.0.0.1:9000/®ion=us-east-1" \ |
| 184 | + --to-query ../configs/databend-query.toml \ |
| 185 | + --to-meta ../configs/databend-meta.toml \ |
| 186 | + --confirm |
| 187 | +<jemalloc>: Number of CPUs detected is not deterministic. Per-CPU arena disabled. |
| 188 | +Restoring from s3://backupbucket?endpoint=http://127.0.0.1:9000/®ion=us-east-1 to query ../configs/databend-query.toml and meta ../configs/databend-meta.toml with confirmation |
| 189 | +``` |
| 190 | +
|
| 191 | +4. After the restore completes, you can verify that the files were written back to the **databend** bucket by listing its contents: |
| 192 | +
|
| 193 | +```bash |
| 194 | +aws --endpoint-url http://127.0.0.1:9000 s3 ls s3://databend/ --recursive |
| 195 | +``` |
| 196 | +
|
| 197 | +```bash |
| 198 | +2025-04-07 23:21:39 748 1/169/_b/h0196160323247b1cab49be6060d42df8_v2.parquet |
| 199 | +2025-04-07 23:21:39 646 1/169/_sg/h0196160323247c5eb0a1a860a6442c70_v4.mpk |
| 200 | +2025-04-07 23:21:39 550 1/169/_ss/h019610dcc72474adb32ef43698db2a09_v4.mpk |
| 201 | +2025-04-07 23:21:39 143 1/169/last_snapshot_location_hint_v2 |
| 202 | +2025-04-07 23:21:39 344781 databend_meta.db |
| 203 | +``` |
| 204 | +
|
| 205 | +5. Query the table again using BendSQL, and you will see that the query now succeeds: |
| 206 | +
|
| 207 | +```sql |
| 208 | +SELECT * FROM books; |
| 209 | +``` |
| 210 | +
|
| 211 | +```sql |
| 212 | +┌────────────────────────────────────────────────────────┐ |
| 213 | +│ id │ title │ genre │ |
| 214 | +├──────────────────┼──────────────────┼──────────────────┤ |
| 215 | +│ 1 │ Invisible Stars │ General │ |
| 216 | +└────────────────────────────────────────────────────────┘ |
| 217 | +``` |
0 commit comments