ClickHouse 备份恢复工具:CLICKHOUSE-BACKUP
官方網(wǎng)址:
https://altinity.com/blog/introduction-to-clickhouse-backups-and-clickhouse-backup
GitHub地址:
https://github.com/AlexAkulov/clickhouse-backup
Limitations
ClickHouse above 1.1.54390 is supported
Only MergeTree family tables engines
Backup of 'Tiered storage' orstorage_policyIS NOT SUPPORTED!
Maximum backup size on cloud storages is 5TB
Maximum number of parts on AWS S3 is 10,000 (increase part_size if your database is more than 1TB)
一、下載安裝
wget https://github.com/AlexAkulov/clickhouse-backup/releases/download/v0.5.2/clickhouse-backup.tar.gz tar -xf clickhouse-backup.tar.gz cd clickhouse-backup/ sudo cp clickhouse-backup /usr/local/bin clickhouse-backup -v
當(dāng)前版本
https://github.com/AlexAkulov/clickhouse-backup/releases/tag/v0.6.0
可以直接下載rpm或者tar包
二、配置clickhouse-backup
最小配置
$ cat /etc/clickhouse-backup/config.yml general: remote_storage: none
生成全配置
clickhouse-backup default-config
查看clickhouse-backup幫助
$ clickhouse-backup help NAME: clickhouse-backup - Tool for easy backup of ClickHouse with cloud support ... COMMANDS: tables Print list of tables create Create new backup 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 delete Delete specific backup default-config Print default config freeze Freeze tables clean Remove data in 'shadow' folder server Run API server help, h Shows a list of commands or help for one command
三、使用clickhouse-backup
1、查看可備份的表
$ clickhouse-backup tables default.events system.metric_log (ignored) system.query_log (ignored) system.query_thread_log (ignored) system.trace_log (ignored)
2、創(chuàng)建備份
$ sudo clickhouse-backup create 2020/07/06 20:13:02 Create backup '2020-07-06T20-13-02' 2020/07/06 20:13:02 Freeze `default`.`events` 2020/07/06 20:13:02 Skip `system`.`metric_log` 2020/07/06 20:13:02 Skip `system`.`query_log` 2020/07/06 20:13:02 Skip `system`.`query_thread_log` 2020/07/06 20:13:02 Skip `system`.`trace_log` 2020/07/06 20:13:02 Copy metadata 2020/07/06 20:13:02 Done. 2020/07/06 20:13:02 Move shadow 2020/07/06 20:13:02 Done.
3、查看備份
$ sudo clickhouse-backup list Local backups: - '2020-07-06T20-13-02' (created at 06-07-2020 20:13:02)clickhouse-backup如上所述,在內(nèi)部盡可能使用硬鏈接。備份存儲(chǔ)在中/var/lib/clickhouse/backup/BACKUPNAME。
備份名稱默認(rèn)為時(shí)間戳,但是您可以選擇使用–name標(biāo)志指定備份名稱。備份包含兩個(gè)目錄:一個(gè)“元數(shù)據(jù)”目錄,
其中包含重新創(chuàng)建架構(gòu)所需的DDL SQL語(yǔ)句;以及一個(gè)“影子”目錄,其中包含作為ALTER TABLE ... FREEZE操作結(jié)果的數(shù)據(jù)。
4、數(shù)據(jù)還原
$ echo 'drop table events' | clickhouse-client $ sudo clickhouse-backup restore 2020-07-06T20-13-02 2020/07/06 20:14:46 Create table `default`.`events` 2020/07/06 20:14:46 Prepare data for restoring `default`.`events` 2020/07/06 20:14:46 ALTER TABLE `default`.`events` ATTACH PART '202006_1_1_4' 2020/07/06 20:14:46 ALTER TABLE `default`.`events` ATTACH PART '202006_2_2_2' 2020/07/06 20:14:46 ALTER TABLE `default`.`events` ATTACH PART '202006_3_3_3' 2020/07/06 20:14:46 ALTER TABLE `default`.`events` ATTACH PART '202006_4_4_3' 2020/07/06 20:14:46 ALTER TABLE `default`.`events` ATTACH PART '202006_5_5_2' 2020/07/06 20:14:46 ALTER TABLE `default`.`events` ATTACH PART '202006_6_6_1'
該restore子命令自動(dòng)模式和數(shù)據(jù)恢復(fù)。如果只想還原架構(gòu),請(qǐng)使用可選--schema標(biāo)志。或者,如果只想還原數(shù)據(jù)(假設(shè)架構(gòu)已存在),則可以使用該--data標(biāo)志。后一種情況在還原到已經(jīng)具有現(xiàn)有數(shù)據(jù)的服務(wù)器時(shí)特別有用。
5、備份指定表與數(shù)據(jù)庫(kù)
另一個(gè)有用的功能是支持使用大多數(shù)命令(例如創(chuàng)建和還原)指定表模式。該--table參數(shù)允許您備份(或還原)特定表。你也可以使用一個(gè)正則表達(dá)式,例如,針對(duì)特定的數(shù)據(jù)庫(kù):--table=dbname.*。
6、備份到遠(yuǎn)程機(jī)器
略,查看官網(wǎng)
原創(chuàng)內(nèi)容,轉(zhuǎn)載請(qǐng)標(biāo)明出處
總結(jié)
以上是生活随笔為你收集整理的ClickHouse 备份恢复工具:CLICKHOUSE-BACKUP的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 牛霖是牛的哪个部位
- 下一篇: boss直聘是真的吗