-
-
Save adubovikov/9ef3aac41b0ad186d0377ea1eabd5aaf to your computer and use it in GitHub Desktop.
dump all clickhouse databases and tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PASSWORD="--password=password" | |
DBLIST="db1 db2 db3" | |
OUTDIR=. | |
while read -r db ; do | |
while read -r table ; do | |
if [[ "$table" == ".inner."* ]]; then | |
echo "skip materialized view $table ($db)" | |
continue; | |
fi | |
echo "export table $table from database $db" | |
# dump schema | |
clickhouse-client ${PASSWORD} -q "SHOW CREATE TABLE ${db}.${table}" > "${OUTDIR}/${db}_${table}_schema.sql" | |
# dump | |
clickhouse-client ${PASSWORD} -q "SELECT * FROM ${db}.${table} FORMAT TabSeparated" | gzip > "${OUTDIR}/${db}_${table}_data.tsv.gz" | |
done < <(clickhouse-client ${PASSWORD} -q "SHOW TABLES FROM $db") | |
done < <(echo ${DBLIST}) |
TabSeparatedRaw
Differs from TabSeparated format in that the rows are written without escaping.
I dont know why, but TabSeparated broke my migration, when TabSeparatedRaw didn't.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recommended to use TabSeparatedRaw format for schema migration:
clickhouse-client ${PASSWORD} -q "SHOW CREATE TABLE ${db}.${table}" --format=TabSeparatedRaw > "${OUTDIR}/${db}_${table}_schema.sql"