CREATE-REPOSITORY

Name

CREATE REPOSITORY

Description

该语句用于创建仓库。仓库用于属于备份或恢复。仅 root 或 superuser 用户可以创建仓库。

语法:

  1. CREATE [READ ONLY] REPOSITORY `repo_name`
  2. WITH [BROKER `broker_name`|S3|hdfs]
  3. ON LOCATION `repo_location`
  4. PROPERTIES ("key"="value", ...);

说明:

  • 仓库的创建,依赖于已存在的 broker 或者直接通过AWS s3 协议访问云存储,或者直接访问HDFS
  • 如果是只读仓库,则只能在仓库上进行恢复。如果不是,则可以进行备份和恢复操作。
  • 根据 broker 或者S3、hdfs的不同类型,PROPERTIES 有所不同,具体见示例。
  • ON LOCATION ,如果是 S3 , 这里后面跟的是 Bucket Name。

Example

  1. 创建名为 bos_repo 的仓库,依赖 BOS broker “bos_broker”,数据根目录为:bos://palo_backup
  1. CREATE REPOSITORY `bos_repo`
  2. WITH BROKER `bos_broker`
  3. ON LOCATION "bos://palo_backup"
  4. PROPERTIES
  5. (
  6. "bos_endpoint" = "http://gz.bcebos.com",
  7. "bos_accesskey" = "bos_accesskey",
  8. "bos_secret_accesskey"="bos_secret_accesskey"
  9. );
  1. 创建和示例 1 相同的仓库,但属性为只读:
  1. CREATE READ ONLY REPOSITORY `bos_repo`
  2. WITH BROKER `bos_broker`
  3. ON LOCATION "bos://palo_backup"
  4. PROPERTIES
  5. (
  6. "bos_endpoint" = "http://gz.bcebos.com",
  7. "bos_accesskey" = "bos_accesskey",
  8. "bos_secret_accesskey"="bos_accesskey"
  9. );
  1. 创建名为 hdfs_repo 的仓库,依赖 Baidu hdfs broker “hdfs_broker”,数据根目录为:hdfs://hadoop-name-node:54310/path/to/repo/
  1. CREATE REPOSITORY `hdfs_repo`
  2. WITH BROKER `hdfs_broker`
  3. ON LOCATION "hdfs://hadoop-name-node:54310/path/to/repo/"
  4. PROPERTIES
  5. (
  6. "username" = "user",
  7. "password" = "password"
  8. );
  1. 创建名为 s3_repo 的仓库,直接链接云存储,而不通过broker.
  1. CREATE REPOSITORY `s3_repo`
  2. WITH S3
  3. ON LOCATION "s3://s3-repo"
  4. PROPERTIES
  5. (
  6. "AWS_ENDPOINT" = "http://s3-REGION.amazonaws.com",
  7. "AWS_ACCESS_KEY" = "AWS_ACCESS_KEY",
  8. "AWS_SECRET_KEY"="AWS_SECRET_KEY",
  9. "AWS_REGION" = "REGION"
  10. );
  1. 创建名为 hdfs_repo 的仓库,直接链接HDFS,而不通过broker.
  1. CREATE REPOSITORY `hdfs_repo`
  2. WITH hdfs
  3. ON LOCATION "hdfs://hadoop-name-node:54310/path/to/repo/"
  4. PROPERTIES
  5. (
  6. "fs.defaultFS"="hdfs://hadoop-name-node:54310",
  7. "hadoop.username"="user"
  8. );
  1. 创建名为 minio_repo 的仓库,直接通过 s3 协议链接 minio.
  1. CREATE REPOSITORY `minio_repo`
  2. WITH S3
  3. ON LOCATION "s3://minio_repo"
  4. PROPERTIES
  5. (
  6. "AWS_ENDPOINT" = "http://minio.com",
  7. "AWS_ACCESS_KEY" = "MINIO_USER",
  8. "AWS_SECRET_KEY"="MINIO_PASSWORD",
  9. "AWS_REGION" = "REGION",
  10. "use_path_style" = "true"
  11. );

Keywords

  1. CREATE, REPOSITORY

Best Practice

  1. 一个集群可以创建过多个仓库。只有拥有 ADMIN 权限的用户才能创建仓库。
  2. 任何用户都可以通过 SHOW REPOSITORIES 命令查看已经创建的仓库。
  3. 在做数据迁移操作时,需要在源集群和目的集群创建完全相同的仓库,以便目的集群可以通过这个仓库,查看到源集群备份的数据快照。