buliang/json/TextJson/dataCopy.shell

44 lines
1.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 源库配置(宿主机)
SRC_HOST="192.168.1.128"
SRC_PORT=9000
# 目标库配置Docker容器
DEST_HOST="192.168.1.128"
DEST_PORT=9001
echo "开始迁移:"
# 获取迁移表清单
tables=$(clickhouse-client --host $SRC_HOST --port $SRC_PORT -q "
SELECT DISTINCT concat(database, '.', name)
FROM system.tables
WHERE database NOT IN ('system','information_schema')
")
# 优化参数配置
max_retries=3 # 单表最大重试次数
timeout=3600 # 单表超时时间(秒)
for table in $tables; do
echo "正在迁移表: $table"
# 带重试机制的迁移命令
for ((i=1; i<=$max_retries; i++)); do
timeout $timeout \
clickhouse-client --host $SRC_HOST --port $SRC_PORT \
--query "SELECT * FROM $table FORMAT Native" \
| clickhouse-client --host $DEST_HOST --port $DEST_PORT \
--query "INSERT INTO $table FORMAT Native"
if [ $? -eq 0 ]; then
echo "$table 迁移成功"
break
else
echo "$table$i次迁移失败,等待重试..."
sleep 10
fi
done
done