su ods -c "hadoop distcp hdfs://source_cluster/apps/hive/warehouse/db_name.db hdfs://target_cluster/apps/hive/warehouse/db_name/db"
如果网络不互通,需要先把数据下载下来,再手动传到目标集群。如果数据量不大还是可行的 su hdfs -c “hdfs dfs -get hdfs://cluster_name/apps/hive/warehouse/db_name.db/table_name”
for current_table in ${table_arr[@]} do su hdfs -c “hdfs dfs -get hdfs://cluster_name/apps/hive/warehouse/db_name.db/${current_table}” done
表结构迁移
1 2 3 4 5 6 7 8
table_arr=(需要导出的表列表)
echo "" >> /tmp/ddl.sql for current_table in ${table_arr[@]} do beeline -u jdbc:hive2://hive_server_host:10000/dw -n hive -e "show create table ${current_table}" 2>/dev/null | sed 's/.*createtab_stmt.*//g' | sed 's/.*--.*//g' | sed 's/| //g' | sed -E 's/ +\|//g' >> /tmp/ddl.sql echo ";" >> /tmp/ddl.sql done
然后在目标环境 执行导出的 ddl.sql
1
beeline -n user -u jdbc:hive2://hive_server_host:10000/db_name -f /tmp/ddl.txt
批量添加 ssh key
1 2 3 4 5 6 7 8 9 10 11 12 13 14
ip_list=(需要添加的机器列表) ssh_port=22
ssh_public_key_arr=("ssh-rsa ...")
IFS="" for current_ip in ${ip_list[@]} do ssh -p${ssh_port} ${current_ip} "echo '' | sudo tee -a /root/.ssh/authorized_keys" for current_ssh_key in ${ssh_public_key_arr[@]} do ssh -p${ssh_port} ${current_ip} "echo '${current_ssh_key}' | sudo tee -a /root/.ssh/authorized_keys" done done
if [ $# -lt 2 ]; then echo "Invalid input!" exit fi
node_name=$1 env_name=$2
# goto container dev_zsh if [ "$node_name" == "container" ]; then container_name=$env_name container_count=`docker ps -a --filter name=^$container_name\$ | grep -v "CREATED" | wc -l | sed 's/\t//g' | sed 's/ //g'` if [ "1" == "$container_count" ]; then container_id=`docker ps -a --filter name=^$container_name\$ | grep -v "CREATED" | sed 's/ .*//g'` docker exec -it $container_id /bin/zsh if [ 0 -ne $? ]; then docker exec -it $container_id /bin/bash fi else echo "container: $env_name, get count $container_count, will not enter" fi exit else echo "command not valid" fi
# goto container dev: bash into container name "dev"