clickhourse-007之click-backup工具介绍
作者:互联网
## 一、官方资料和使用说明:
**参考文档资料如下:**
https://github.com/AlexAkulov/clickhouse-backup
https://segmentfault.com/a/1190000038604737
**使用限制:**
支持1.1.54390以上的ClickHouse
仅MergeTree系列表引擎
**此外,clickhouse-backup文档还包含以下重要警告:**
切勿在中更改文件权限/var/lib/clickhouse/backup。此路径包含硬链接。磁盘上相同数据的所有硬链接上的权限始终相同。这意味着,如果您更改备份路径中硬链接上的权限/所有者/属性,与ClickHouse一起使用的文件的权限也将更改。这可能会导致数据损坏。
## 二、安装方式:
**2.1、二进制文件安装:**
**clickhouse-backup下载:**
```
tar -xf clickhouse-backup.tar.gz
cd clickhouse-backup /
sudo cp clickhouse-backup /usr/local/bin
```
**2.2、下载rpm安装包安装:**
```
rpm -ivh clickhouse-backup-1.0.0-1.x86_64.rpm
```
**2.3、亲自测试可用配置文件如下:**
```
[root@tidb06 backup]# cat /etc/clickhouse-backup/config.yml
general:
remote_storage: s3
max_file_size: 1099511627776
disable_progress_bar: false
backups_to_keep_local: 3
backups_to_keep_remote: 3
log_level: info
allow_empty_backups: false
clickhouse:
username: default
password: "j780UJy9D2tn"
host: localhost
port: 9000
data_path: ""
#disk_mapping: {}
skip_tables:
- system.*
- default.*
timeout: 5m
freeze_by_part: false
secure: false
skip_verify: false
sync_replicated_tables: true
skip_sync_replica_timeouts: true
log_sql_queries: false
s3:
access_key: "HYdGDq289324ustSWI82JHw2sU8"
secret_key: "J38l8nq289324ustSWI8SR22Jl"
bucket: "test-bucket"
endpoint: "oss-cn-beijing-internal.aliyuncs.com"
path: "./files_download/"
#region: us-east-1
#acl: private
force_path_style: false
disable_ssl: false
part_size: 536870912
compression_level: 1
compression_format: tar
sse: ""
disable_cert_verification: false
storage_class: STANDARD
```
## 三、命令具体使用演示:
**3.1、查看全部默认的配置项**
clickhouse-backup default-config
**3.2、查看可备份的表:**
```
[root@tidb06 clickhouse-backup]# clickhouse-backup tables
db01.t_order_mt 0B default
db01.test_table 255B default
test001.hits_v1 0B default
test001.t_order_mt 0B default
test001.test_table 1.25KiB default
test001.test_table01 0B default
test001.test_table02 0B default
test002.test_table 0B default
test008.test_table 805B default
testdb01.test_table 723B default
testdb01.test_table01 723B default
testdb01.test_table02 0B default
tutorial.hits_v1 1.18GiB default
tutorial.hits_v2 1.18GiB default
tutorial.visits_v1 527.47MiB default
```
**3.3、创建本地备份和删除本地备份,利用本地备份进行恢复:**
**1. 全库备份**
```
clickhouse-backup create
[root@tidb06 data1]# clickhouse-backup create
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=db01.t_order_mt
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=db01.test_table
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=test001.hits_v1
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=test001.t_order_mt
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=test001.test_table
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=test001.test_table01
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=test001.test_table02
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=test002.test_table
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=test008.test_table
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=testdb01.test_table
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=testdb01.test_table01
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=testdb01.test_table02
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=tutorial.hits_v1
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=tutorial.hits_v2
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create table=tutorial.visits_v1
2021/06/25 22:58:13 info done backup=2021-06-25T14-58-13 operation=create
```
**默认备份在下面的目录:**
```
/var/lib/clickhouse/backup
[root@tidb06 backup]# ll
total 4
drwxr-x--- 4 clickhouse clickhouse 4096 Jun 25 22:58 2021-06-25T14-58-13
```
**备份存储在中 $data_path/backup 下,备份名称默认为时间戳,可手动指定备份名称。例如:**
```
[root@tidb06 backup]# clickhouse-backup create click-bak0625
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=db01.t_order_mt
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=db01.test_table
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=test001.hits_v1
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=test001.t_order_mt
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=test001.test_table
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=test001.test_table01
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=test001.test_table02
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=test002.test_table
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=test008.test_table
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=testdb01.test_table
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=testdb01.test_table01
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=testdb01.test_table02
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=tutorial.hits_v1
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=tutorial.hits_v2
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create table=tutorial.visits_v1
2021/06/25 23:02:19 info done backup=click-bak0625 operation=create
[root@tidb06 backup]# ls
2021-06-25T14-58-13 click-bak0625
```
**备份包含两个目录:**
'metadata'目录: 包含重新创建所需的DDL SQL
'shadow'目录: 包含作为ALTER TABLE ... FREEZE操作结果的数据。
**2、单表备份**
**语法:**
clickhouse-backup create [-t, --tables=.]
标签:06,0625,007,2021,table,clickhourse,db01,backup 来源: https://blog.51cto.com/wujianwei/3034609