1.下載
下載地址
https://github.com/Altinity/clickhouse-backup
2.安裝
[root@dc-biz-ck-192 soft]# rpm -ivh clickhouse-backup-2.4.35-1.x86_64.rpm
3.檢視版本號
[root@dc-biz-ck-192 soft]# clickhouse-backup -v
Version: 2.4.35
Git Commit: 5e41c8be05849a4ce9e171fe2e11f55f9ece309b
Build Date: 2024-03-24
4.編輯配置檔案
複製一份模版檔案為配置檔案
[root@dc-biz-ck-192 clickhouse-backup]# cd /etc/clickhouse-backup/
[root@dc-biz-ck-192 clickhouse-backup]# cp config.yml.example config.yml
修改配置檔案config.yml
general:
backups_to_keep_local: 3
clickhouse:
username: default
password: "123456"
5.檢視可備份的表
[root@localhost clickhouse-backup]# clickhouse-backup tables
db_test.app_message_80 233.65MiB default
db_test.app_message_80_cp 0B default
6.建立備份
[root@localhost clickhouse-backup]#clickhouse-backup create
備份儲存在中 $data_path/backup 下,備份名稱預設為時間戳,可手動指定備份名稱。例如:
[root@localhost clickhouse-backup]#clickhouse-backup create bak20240222
備份檔案在clickhouse的data目錄下
[root@dc-biz-ck-192 clickhouse-backup]# pwd
/etc/clickhouse-backup
[root@dc-biz-ck-192 click
[root@dc-biz-ck-192 clickhouse-backup]# ls -al /opt/clickhouse/data/backup/bak20240222
總用量 12
drwxr-x--- 3 clickhouse clickhouse 43 4月 22 16:39 .
drwxr-x--- 3 clickhouse clickhouse 25 4月 22 16:39 ..
drwxr-x--- 3 clickhouse clickhouse 20 4月 22 16:39 metadata
-rw-r----- 1 clickhouse clickhouse 8246 4月 22 16:39 metadata.json
7.檢視備份檔案
[root@localhost clickhouse-backup]# clickhouse-backup list
8.刪除備份
clickhouse-backup delete local bak20240222
9.整理成備份指令碼
[root@localhost scripts]# more backup_clickhouse.sh
#!/bin/sh
backup_date=`date "+%Y%m%d"`
delete_date=`date +%Y%m%d -d "3 days ago"`
/usr/local/bin/clickhouse-backup create bak${backup_date}
/usr/local/bin/clickhouse-backup delete local bak${delete_date}