环境:
OS:Centos 7
clickhouse:24.8.11.5
备份工具:clickhouse-backup,版本:2.6.5
1.备份
clickhouse-backup create mybak20250123 --config=/etc/clickhouse-backup/config.yml
2.查看备份
[root@localhost tmp]#clickhouse-backup list --config=/etc/clickhouse-backup/config.yml
mybak20250123 15.38GiB 23/01/2025 00:28:40 local regular
3.查看备份目录
查看备份目录占用空间大小
[root@localhost data]# du -h ./ --max-depth=1
92K ./preprocessed_configs
0 ./flags
0 ./dictionaries_lib
0 ./user_scripts
0 ./data
20K ./metadata
0 ./metadata_dropped
17G ./store
0 ./cores
76K ./backup
4.0K ./shadow
17G ./
发现backup目录没有体现大小出来(可能是硬链接的原因),进入到备份的具体目录查看占用大小
[root@localhost backup]# du -h ./ --max-depth=1
16G ./mybak20250123
16G ./
4.拷贝备份目录到其他目录查看具体大小
[root@localhost backup]# cp -r mybak20250123 /tmp/
[root@localhost tmp]#cd /tmp/
[root@localhost tmp]#du -h ./ --max-depth=1
16G ./mybak20250123
5.删除备份
[root@localhost backup]# clickhouse-backup delete local mybak20250123 --config=/etc/clickhouse-backup/config.yml
这个时候备份目录会删除掉了
[root@localhost backup]# pwd
/home/middle/clickhouse/data/backup
[root@localhost backup]# ls -al
total 0
drwxr-xr-x 2 clickhouse clickhouse 6 Jan 24 13:57 .
drwxrwxr-x 13 clickhouse clickhouse 223 Jan 17 17:56 ..
6.删除数据库
clickhouse-client -h 192.168.1.134 -m -u default --password clickhouse123
use db_test;
show tables;
┌─name────────────┐
1. │ app_message_all │
└─────────────────┘
localhost :) drop database db_test;
7.把备份文件拷贝到clikchouse备份目录
cp -r /tmp/mybak20250123 /home/middle/clickhouse/data/backup/
[root@localhost backup]# ls
mybak20250123
[root@localhost backup]# pwd
/home/middle/clickhouse/data/backup
这个时候备份目录里可以看得到刚才拷贝过来的备份文件了
使用clickhouse-backup list也有体现
[root@localhost backup]# clickhouse-backup list --config=/etc/clickhouse-backup/config.yml
mybak20250123 15.38GiB 23/01/2025 00:28:40 local regular
8.恢复
恢复整个备份
clickhouse-backup restore mybak20250123 --config=/etc/clickhouse-backup/config.yml
速度很快完成
登录查看恢复情况
clickhouse-client -h 192.168.1.134 -m -u default --password clickhouse123
localhost :) select count(1) from app_message_all;
SELECT count(1)
FROM app_message_all
Query id: 4ecdbb2a-de5e-4e74-a5ea-678c1d2441cc
┌──count(1)─┐
1. │ 200000000 │ -- 200.00 million
└───────────┘
1 row in set. Elapsed: 0.004 sec.