| --- |
| { |
| "title": "CREATE-REPOSITORY", |
| "language": "en" |
| } |
| --- |
| |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| |
| ## CREATE-REPOSITORY |
| |
| ### Name |
| |
| CREATE REPOSITORY |
| |
| ### Description |
| |
| This statement is used to create a repository. Repositories are used for backup or restore. Only root or superuser users can create repositories. |
| |
| grammar: |
| |
| ```sql |
| CREATE [READ ONLY] REPOSITORY `repo_name` |
| WITH [S3|hdfs] |
| ON LOCATION `repo_location` |
| PROPERTIES ("key"="value", ...); |
| ``` |
| |
| illustrate: |
| |
| - Creation of repositories, accessing cloud storage directly through AWS S3 protocol, or accessing HDFS directly. |
| - If it is a read-only repository, restores can only be done on the repository. If not, backup and restore operations are available. |
| - PROPERTIES are different according to different types of S3 or hdfs, see the example for details. |
| - ON LOCATION : if it is S3 , here followed by the Bucket Name. |
| |
| ### Example |
| |
| 1. Create a repository named s3_repo. |
| |
| ```sql |
| CREATE REPOSITORY `s3_repo` |
| WITH S3 |
| ON LOCATION "s3://s3-repo" |
| PROPERTIES |
| ( |
| "s3.endpoint" = "http://s3-REGION.amazonaws.com", |
| "s3.region" = "s3-REGION", |
| "s3.access_key" = "AWS_ACCESS_KEY", |
| "s3.secret_key"="AWS_SECRET_KEY", |
| "s3.region" = "REGION" |
| ); |
| ``` |
| |
| 2. Create a repository named hdfs_repo. |
| |
| ```sql |
| CREATE REPOSITORY `hdfs_repo` |
| WITH hdfs |
| ON LOCATION "hdfs://hadoop-name-node:54310/path/to/repo/" |
| PROPERTIES |
| ( |
| "fs.defaultFS"="hdfs://hadoop-name-node:54310", |
| "hadoop.username"="user" |
| ); |
| |
| ### Keywords |
| |
| ``` |
| 6. Create a repository named minio_repo to link minio storage directly through the S3 protocol. |
| |
| ```sql |
| CREATE REPOSITORY `minio_repo` |
| WITH S3 |
| ON LOCATION "s3://minio_repo" |
| PROPERTIES |
| ( |
| "s3.endpoint" = "http://minio.com", |
| "s3.access_key" = "MINIO_USER", |
| "s3.secret_key"="MINIO_PASSWORD", |
| "s3.region" = "REGION", |
| "use_path_style" = "true" |
| ); |
| ``` |
| |
| |
| 7. Create a repository named minio_repo via temporary security credentials. |
| |
| ```sql |
| CREATE REPOSITORY `minio_repo` |
| WITH S3 |
| ON LOCATION "s3://minio_repo" |
| PROPERTIES |
| ( |
| "s3.endpoint" = "AWS_ENDPOINT", |
| "s3.access_key" = "AWS_TEMP_ACCESS_KEY", |
| "s3.secret_key" = "AWS_TEMP_SECRET_KEY", |
| "s3.session_token" = "AWS_TEMP_TOKEN", |
| "s3.region" = "AWS_REGION" |
| ) |
| ``` |
| |
| 1. Create repository using Tencent COS |
| |
| ```sql |
| CREATE REPOSITORY `cos_repo` |
| WITH S3 |
| ON LOCATION "s3://backet1/" |
| PROPERTIES |
| ( |
| "s3.access_key" = "ak", |
| "s3.secret_key" = "sk", |
| "s3.endpoint" = "http://cos.ap-beijing.myqcloud.com", |
| "s3.region" = "ap-beijing" |
| ); |
| ``` |
| |
| ### Keywords |
| |
| CREATE, REPOSITORY |
| |
| ### Best Practice |
| |
| 1. A cluster can create multiple warehouses. Only users with ADMIN privileges can create repositories. |
| 2. Any user can view the created repositories through the [SHOW REPOSITORIES](../../Show-Statements/SHOW-REPOSITORIES.md) command. |
| 3. When performing data migration operations, it is necessary to create the exact same warehouse in the source cluster and the destination cluster, so that the destination cluster can view the data snapshots backed up by the source cluster through this warehouse. |