Created
October 9, 2019 09:15
-
-
Save subhajeet2107/24c9d1c98b282d58095c9fdc7770725c to your computer and use it in GitHub Desktop.
Dump Databases from clichouse
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 | |
OUTDIR=. | |
while read -r db ; do | |
while read -r table ; do | |
if [ "$db" == "system" ]; then | |
echo "skip system db" | |
continue 2; | |
fi | |
if [[ "$table" == ".inner."* ]]; then | |
echo "skip materialized view $table ($db)" | |
continue; | |
fi | |
echo "export table $table from database $db" | |
# dump schema | |
clickhouse-client -q "SHOW CREATE TABLE ${db}.${table}" > "${OUTDIR}/${db}_${table}_schema.sql" | |
# dump | |
clickhouse-client -q "SELECT * FROM ${db}.${table} FORMAT TabSeparated" | pigz > "${OUTDIR}/${db}_${table}_data.tsv.gz" | |
done < <(clickhouse-client -q "SHOW TABLES FROM $db") | |
done < <(clickhouse-client -q "SHOW DATABASES") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment