clickhouse设置备份路径

发布时间 2023-03-23 15:05:50作者: abce

1.修改备份配置文件

# vi /etc/clickhouse-server/config.d/backup_disk.xml
<clickhouse>
    <storage_configuration>
        <disks>
            <backups>
                <type>local</type>
                <path>/abce/backups/</path>
            </backups>
        </disks>
    </storage_configuration>
    <backups>
        <allowed_disk>backups</allowed_disk>
        <allowed_path>/abce/backups/</allowed_path>
    </backups>
</clickhouse>

添加了XML文件后,需要重启clickhouse。

2.查看配置信息

:) SELECT
                                 name,
                                 path,
                                 formatReadableSize(free_space) AS free,
                                 formatReadableSize(total_space) AS total,
                                 formatReadableSize(keep_free_space) AS reserved
                             FROM system.disks
                             ;

SELECT
    name,
    path,
    formatReadableSize(free_space) AS free,
    formatReadableSize(total_space) AS total,
    formatReadableSize(keep_free_space) AS reserved
FROM system.disks

Query id: 873603ba-adeb-4ea1-a240-d6aff32f429a

┌─name────┬─path──────────────────────────┬─free──────┬─total──────┬─reserved─┐
│ backups │ /abce/backups/                │ 0.00 B    │ 0.00 B     │ 0.00 B   │
│ default │ /abce/clickhouse-server/abce/ │ 44.49 GiB │ 199.90 GiB │ 0.00 B   │
└─────────┴───────────────────────────────┴───────────┴────────────┴──────────┘

2 rows in set. Elapsed: 0.001 sec.

3.在设置了备份路径后,就可以执行备份了。

BACKUP TABLE|DATABASE table_name|abcebase_name TO Disk('<backup_location>', 'backupName.zip');

RESTORE TABLE|DATABASE table_name|abcebase_name FROM Disk('<backup_location>', 'backupName.zip')