代码改变世界

clickhouse设置备份路径

2023-03-23 14:58  abce  阅读(350)  评论(0编辑  收藏  举报

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。这里<path>/backups/</path>指定了备份的路径。

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')

  

备份可以是全备、增量备份;可以包含表,数据库;可以是同步的、异步的,默认是同步的;可以是压缩的、非压缩的。