首页 > 其他分享 >Clickhouse备份

Clickhouse备份

时间:2024-03-27 09:23:46浏览次数:26  
标签:14 root 备份 Clickhouse clickhouse backup bak20220114 localhost

版本:1.2.2

1.下载
wget https://github.com/AlexAkulov/clickhouse-backup/releases/download/v0.6.0/clickhouse-backup.tar.gz
wget https://github.com/AlexAkulov/clickhouse-backup/releases/download/v1.2.1/clickhouse-backup.tar.gz

下载地址
https://github.com/AlexAkulov/clickhouse-backup/releases

 

2.解压即可使用
[root@localhost soft]# tar -xf clickhouse-backup.tar.gz
[root@localhost soft]# cd clickhouse-backup/
[root@localhost soft]# cp clickhouse-backup /usr/local/bin/

查看版本
[root@localhost clickhouse-backup]# clickhouse-backup -v
Version: 1.2.2
Git Commit: 09d6131b6a44e8881db7cc99aa4e5c7ce263afc3
Build Date: 2021-11-26

 

3.编辑配置文件
mkdir -p /etc/clickhouse-backup/
vi /etc/clickhouse-backup/config.yml

general:
  remote_storage: none
  backups_to_keep_local: 7
  backups_to_keep_remote: 31
clickhouse:
  username: default
  password: ""
  host: localhost
  port: 9000
  data_path: "/var/lib/clickhouse"


这里注意,需要填写所在ck服务器的账号密码

 

4.查看全部默认的配置项
clickhouse-backup default-config

# 查看可备份的表
[root@localhost clickhouse-backup]# clickhouse-backup tables
db_test.app_message_80 233.65MiB default
db_test.app_message_80_cp 0B default

 

 

5.创建备份
[root@localhost clickhouse-backup]#clickhouse-backup create
备份存储在中 $data_path/backup 下,备份名称默认为时间戳,可手动指定备份名称。例如:
[root@localhost clickhouse-backup]#clickhouse-backup create bak20220114

备份包含两个目录:
'metadata'目录: 包含重新创建所需的DDL SQL
'shadow'目录: 包含作为ALTER TABLE ... FREEZE操作结果的数据.

 

6.查看备份文件
[root@localhost clickhouse-backup]# clickhouse-backup list
2022-01-14T02-58-42 233.65MiB 14/01/2022 02:58:42 local
bak20220114 233.65MiB 14/01/2022 02:59:35 local


7.删除备份
clickhouse-backup delete local 2022-01-14T02-58-42
clickhouse-backup delete local bak20220114

 

8.整理成备份脚本

[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}

 

 

 

-----------------数据恢复-----------------------------------
A.本地恢复
1.删除表
localhost :) drop table app_message_80;

2.恢复

[root@localhost clickhouse-backup]# clickhouse-backup restore bak20220114 -table db_test.app_message_80
2022/01/14 13:59:37 error can't create table `db_test`.`app_message_80`: code: 57, message: Directory for table data store/9a2/9a2875bb-3dfb-4ba8-9a28-75bb3dfbdba8/ already exists after 1 times, please check your schema dependencies
[root@localhost clickhouse-backup]# clickhouse-backup restore bak20220114 -table db_test.app_message_80
2022/01/14 14:01:36 error can't create table `db_test`.`app_message_80`: code: 57, message: Directory for table data store/9a2/9a2875bb-3dfb-4ba8-9a28-75bb3dfbdba8/ already exists after 1 times, please check your schema dependencies
[root@localhost clickhouse-backup]# clickhouse-backup restore bak20220114 -table db_test.app_message_80
2022/01/14 14:04:17 error can't create table `db_test`.`app_message_80`: code: 57, message: Directory for table data store/9a2/9a2875bb-3dfb-4ba8-9a28-75bb3dfbdba8/ already exists after 1 times, please check your schema dependencies

这里需要等待1分钟左右,不知道那个参数控制的

 

[root@localhost clickhouse-backup]# clickhouse-backup restore bak20220114 -table db_test.app_message_80
2022/01/14 14:07:38 info done backup=bak20220114 operation=restore table=db_test.app_message_80
2022/01/14 14:07:38 info done backup=bak20220114 duration=81ms operation=restore
2022/01/14 14:07:38 info done backup=bak20220114 operation=restore

 

b.异机恢复
1.将源端备份目录打包并传到恢复机器
tar -cvf bak20220114.tar ./bak20220114
scp bak20220114.tar [email protected]:/tmp/

 

2.恢复机器上创建备份目录
[root@localhost clickhouse-backup]# cd /var/lib/clickhouse
[root@localhost clickhouse]# mkdir backup

将源端备份的文件解压并将目录拷贝到恢复机器的备份目录
cd /tmp/
tar -xvf bak20220114.tar
mv /tmp/bak20220114 /var/lib/clickhouse/backup/

 

3.恢复
[root@localhost tmp]# clickhouse-backup list
2022/01/14 14:36:28 error can't connect to clickhouse: code: 516, message: default: Authentication failed: password is incorrect or there is no user with such name

注意这里需要配置/etc/clickhouse-backup/config.yml 指定正确的账号密码
[root@localhost tmp]# clickhouse-backup list
bak20220114 239.01MiB 14/01/2022 05:54:25 local

再次执行恢复
[root@localhost tmp]# clickhouse-backup restore bak20220114 -table db_test.app_message_80
2022/01/14 14:38:48 info done backup=bak20220114 operation=restore table=db_test.app_message_80
2022/01/14 14:38:48 info done backup=bak20220114 duration=240ms operation=restore
2022/01/14 14:38:48 info done backup=bak20220114 operation=restore

 

4.查看恢复情况
clickhouse-client --host 192.168.1.136 --port=9000 --password 123456

 

 

 

-------------------------备份集群多个节点---------------------

[root@localhost all_1_4_1]# clickhouse-backup -help
NAME:
clickhouse-backup - Tool for easy backup of ClickHouse with cloud support

USAGE:
clickhouse-backup <command> [-t, --tables=<db>.<table>] <backup_name>

VERSION:
1.2.2

DESCRIPTION:
Run as 'root' or 'clickhouse' user

COMMANDS:
tables Print list of tables
create Create new backup
create_remote Create and upload
upload Upload backup to remote storage
list Print list of backups
download Download backup from remote storage
restore Create schema and restore data from backup
restore_remote Download and restore
delete Delete specific backup
default-config Print default config
server Run API server
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--config FILE, -c FILE Config FILE name. (default: "/etc/clickhouse-backup/config.yml") [$CLICKHOUSE_BACKUP_CONFIG]
--help, -h show help
--version, -v print the version

 

通过指定--config 参数备份多个节点

标签:14,root,备份,Clickhouse,clickhouse,backup,bak20220114,localhost
From: https://www.cnblogs.com/MoDian/p/18098163

相关文章

  • Web举例:防火墙二层,上下行连接交换机的主备备份组网
    Web举例:防火墙二层,上下行连接交换机的主备备份组网介绍了业务接口工作在二层,上下行连接交换机的主备备份组网的Web举例。组网需求如图1所示,两台FW的业务接口都工作在二层,上下行分别连接交换机。FW的上下行业务接口都加入到VLAN10和VLAN20中。现在希望两台FW以主备备份方......
  • Oracle备份的几种方式
    原文出处:https://www.cnblogs.com/lcword/p/11775657.html 从物理与逻辑的角度来分类:从物理与逻辑的,备份可以分为物理备份和逻辑备份。物理备份:对数据库操作系统的物理文件(数据文件,控制文件和日志文件)的备份。物理备份又可以分为脱机备份(冷备份)和联机备份(热备份),前者是在关闭数......
  • SVN服务器备份_svn服务器迁移
    SVN服务器备份_svn服务器迁移发布于2022-11-1115:01:38目录前言1hotcopy备份1.1方法说明1.2手动备份1.3自动备份1.3.1备份脚本1.3.2定时任务1.4还原方法1.4.1VisualSVN还原1.4.2SubVersion还原1.5异常提示2dump......
  • 为什么使用gs_probackup执行全量备份时,提示无法连接到数据库?
    为什么使用gs_probackup执行全量备份时,提示无法连接到数据库?背景介绍:在使用gs_probackup执行全量备份时,提示无法连接到数据库。报错内容:[ommdoc@hostname]$gs_probackupbackup-B/opt/mogdb/backup_dir--instancecluster_doc-bFULLINFO:Backupstart,gs_proback......
  • MySQL 数据库的日志管理、备份与恢复
    一.数据库备份1.数据备份的重要性 备份的主要目的是灾难恢复。在生产环境中,数据的安全性至关重要。任何数据的丢失都可能产生严重的后果。造成数据丢失的原因:程序错误人为,操作错误,运算错误,磁盘故障灾难(如火灾、地震)和盗窃.容灾概念:容灾(DisasterRecovery,DR)......
  • 038Confluence数据导出或备份
    一、从Confluence导出zip文件Server版导出步骤打开需要迁移的空间,选择空间管理,点击内容工具>导出。在导出格式中勾选HTML,点击下一个,选择普通导出。勾选需要导出的空间页面,选择完毕后点击导出。导出完毕后,点击here下载到本地 注:空间管理按键通常在页面左下......
  • 将一个Windows系统备份成ISO文件,您可以遵循以下步骤
    将一个Windows系统备份成ISO文件,您可以遵循以下步骤:使用Windows内置工具制作ISO映像准备源文件:首先,您需要找到Windows安装媒体的ISO文件。如果您没有现成的ISO文件,可以从Microsoft官方网站下载Windows10或Windows11的ISO文件。提取ISO内容:将ISO文件复制到一个文件夹中,例如D盘上......
  • Linux文件上传百度云盘轻松解决数据传输和备份
    本文主要的目的就是在Linux环境下通过命令行来使用百度云盘,直接在服务器上打包压缩备份将数据传输到百度网盘,之后可以进行轻松分享,而且还可以支持备份,解决文件的传输和分享难题插件介绍bypy是一个Python客户端,用于操作百度网盘提供了丰富的命令行操作。该工具能够直接在Lin......
  • 常用命令--数据库备份--mysqdump
    常用命令--数据库备份--mysqdump常用选项mysqldump是MySQL数据库的一个重要工具,用于创建数据库的逻辑备份。以下是mysqldump的一些常用选项及其功能:1.-uusername或--user=username:指定连接MySQL服务器的用户名。2.-p或--password:提示输入密码。也可以直接跟在-u......
  • 电脑数据安全新利器:自动备份文件的重要性与实用方案
    一、数据安全的守护神:自动备份文件的重要性在数字化时代,电脑中的文件承载着我们的工作成果、个人回忆以及众多重要信息。然而,数据丢失的风险无处不在,无论是硬件故障、软件崩溃,还是恶意软件的攻击,都可能让我们的文件面临灭顶之灾。因此,自动备份文件的重要性愈发凸显。电......