表結構備份
10.138.87.7所有庫的表結構備份,導出到文件複製表結構的語句
腳本1:
#!/bin/bash
hive -e "show tables;" > tables.txt
sleep(2)
cat tables.txt |while read eachline
do
hive -e "show create table $eachline" >>tablesDDL.txt
done
腳本2 針對hive的:
#!/bin/bash
# bak the hive tables
hive -e "show databases "> database.txt
rm -rf bak_table.hql bak_table_create.txt
while read database
do
echo "the database is :$database "
echo "xxxxxxxxxxxxxxxxxxxxxxxxx database: $database xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">> bak_table_create.txt
hive -e "show tables in $database" > tables.txt
echo "! echo xxxxxxxxxxxxxxxxxxxx database: ${database} xxxxxxxxxxxxxxxxxxxxxxxxxxxx;" >> bak_table.hql
while read table
do
echo "! echo ..................... table: ${database}.${table} ......................;" >> bak_table.hql
echo "show create table ${database}.${table};" >>bak_table.hql
echo ! echo "\;" ; >>bak_table.hql
done < tables.txt
# hive -f "bak_table.hql" >> bak_table_create.txt
# rm -rf bak_table.hql
done < database.txt
hive -f "bak_table.hql" >> bak_table_create.txt
注:hive -e 執行查詢
hive -f 調用文件傳遞參數
shell中的
> 創建
>> 追加
show create table t_name; 查看錶結構
腳本3:針對impala的(用的)
#!/bin/bash
impala-shell -B -q "show databases "> database.txt
rm -rf bak_table.hql bak_table_create.txt
while read database
do
echo "the database is :$database "
echo "xxxxxxxxxxxxxx database: $database xxxxxxxxxxx">> bak_table_create.txt
impala-shell -B -q "show tables in $database" > tables.txt
echo "! echo xxxxx database: ${database} xxxxxx;" >> bak_table.hql
while read table
do
echo "! echo ..... table: ${database}.${table} .....;" >> bak_table.hql
impala-shell -B -q "show create table ${database}.${table};" >>bak_table.hql
echo ! echo "\;" ; >>bak_table.hql
done < tables.txt
# hive -f "bak_table.hql" >> bak_table_create.txt
# rm -rf bak_table.hql
done < database.txt
hive -f "bak_table.hql" >> bak_table_create.txt
chmod 777 copy.sh 賦權限
注:impala-shell -B -q 'select * from t_name;' -o a.txt
impala-shell -f 執行文件
-q 不進入命令行執行sql
備份需要的存儲過程(窮舉了需要的存過)
#!/bin/bash
proc_names=(proc_name1 proc_name2 proc_name3 proc_name4 proc_name5)
#proc_names[@]這樣才能獲取數組中所有 proc_names只能獲取第一個
for proc_name in ${proc_names[@]}
do
beeline -u "jdbc:hive://ip:port" -e "desc plsql function extended ${proc_name}" > /home/target/beifen/${proc_name}.sql
done
將hadoop上某個文件down至本地已有目錄下(備份表數據)
hdfs dfs -get [文件目錄] [本地目錄]
所有就hdfs dfs –get /user/t/ok.txt /home/t/*
將數據放入,再將外表創建上去的時候
ERROR: ImpalaRuntimeException: Error making 'createTable' RPC to Hive Metastore:
原因是權限不足: hadoop fs -chmod -R 777 /hadoop/data/hive