1. ckPart恢复
- 删除表或者清空表
bash
#模拟删除备份过的表,的重新创建表
echo 'drop table your_data_name.your_table_name' | clickhouse-client -udefault --password 123456
或者
echo 'truncate table your_data_name.your_table_name' | clickhouse-client -udefault --password 123456
#模拟删除备份过的表,的重新创建表
echo 'drop table your_data_name.your_table_name' | clickhouse-client -udefault --password 123456
或者
echo 'truncate table your_data_name.your_table_name' | clickhouse-client -udefault --password 123456
- 复制备份数据到清空表的目录下的detached
将之前备份的表分区目录复制到新创建表的 detached 目录
bash
cp -r /var/lib/clickhouse/shadow/1/store/72a/72ad70a1-093a-4254-9098-14d5735fc0d3/* /var/lib/clickhouse/data/nginxlogs/nginx_access/detached/
#修改权限,否则会报没有权限
chown -R clickhouse. /var/lib/clickhouse/data/nginxlogs/nginx_access/detached/*
#查看
[root@kubeadm-master01 detached]# pwd
/var/lib/clickhouse/data/nginxlogs/nginx_access/detached
[root@kubeadm-master01 detached]# ll
总用量 0
drwxr-x--- 2 root root 244 11月 6 16:58 20241101_1_2_1
drwxr-x--- 2 root root 244 11月 6 16:58 20241104_3_10_2
drwxr-x--- 2 root root 244 11月 6 16:58 20241105_11_13_1
cp -r /var/lib/clickhouse/shadow/1/store/72a/72ad70a1-093a-4254-9098-14d5735fc0d3/* /var/lib/clickhouse/data/nginxlogs/nginx_access/detached/
#修改权限,否则会报没有权限
chown -R clickhouse. /var/lib/clickhouse/data/nginxlogs/nginx_access/detached/*
#查看
[root@kubeadm-master01 detached]# pwd
/var/lib/clickhouse/data/nginxlogs/nginx_access/detached
[root@kubeadm-master01 detached]# ll
总用量 0
drwxr-x--- 2 root root 244 11月 6 16:58 20241101_1_2_1
drwxr-x--- 2 root root 244 11月 6 16:58 20241104_3_10_2
drwxr-x--- 2 root root 244 11月 6 16:58 20241105_11_13_1
- 执行 attach
bash
echo 'alter table nginxlogs.nginx_access attach partition 20241105' |clickhouse-client -udefault --password 123456
#查看表是否有数据
SELECT * FROM nginxlogs.nginx_access na LIMIT 10
echo 'alter table nginxlogs.nginx_access attach partition 20241105' |clickhouse-client -udefault --password 123456
#查看表是否有数据
SELECT * FROM nginxlogs.nginx_access na LIMIT 10
至此结束。