Clone A Database In ClickHouse

Different methods can be made to clone a database. In some databases, this is quite easy to do. But no development has yet been made by ClickHouse to copy a database. As a solution to this issue, I developed a small tool. This tool takes a backup of the desired database and then restores it under a different name.

In this article, I will tell you how to do this.

First, download ClickHouse Clone Database Tool

git clone https://github.com/cansayin/ClickHouse-Clone-Database.git

Then create a directory and give permission to ClickHouse user

mkdir /backups
chown clickhouse:clickhouse /backups

Go into directory and change information with your password

cd ClickHouse-Clone-Database
chmod 777 ch-dbClone.sh

Then run the sh

./ch-dbClone.sh

You have to select your database that you want to clone. Then you have to give a clone name. I will select “test” database and will clone it as “test_clone” in the example below

----------------------------------------------------------------------
################# ClickHouse Database Clone Tool #################
----------------------------------------------------------------------

Please enter ClickHouse User Name
User Name : default
Please enter ClickHouse Password
Password : password

######### ClickHouse Databases ###########
------------------------------------------
"INFORMATION_SCHEMA"
"default"
"information_schema"
"system"
"test"

Please choose a database name:
Database Name :test

Please write a clone name:
Clone Name : clone

37360f96-e75d-436b-9a3f-abe44230f67c	BACKUP_CREATED
INFO: test Backup Has Been Taken
bbe08e69-2fb0-46f0-86de-d9f543f60cf7	RESTORED
INFO: test_clone Restore Finished
clickhouse01 :) show databases;

SHOW DATABASES

Query id: cf0de9a1-2c0d-464b-bf60-91e6c7e0f669

┌─name───────────────┐
│ INFORMATION_SCHEMA │
│ default            │
│ information_schema │
│ system             │
│ test               │
│ test_clone         │
└────────────────────┘

GitHub Link

Related Post

2 thoughts on “Clone A Database In ClickHouse

  1. Hi,

    Is ClickHouse Clone Database Tool only support for MySQL and MariaDB ?

    I saw the example and i think it similar with MySQL and MariaDB

    Thanks and Regards!

Leave a Reply

Your email address will not be published. Required fields are marked *