#!/bin/bash
set -e
DB=$1
if [ -z $1 ];then
echo “Usage:$0 DbName”
exit 1
fi
row=$(sed -n '/sjob_exec.sh/=' /etc/crontab)
sed -i "$row s/^/#/" /etc/crontab
ret=$(sudo -u hdfs hive -e "use ${DB};show tables;"|grep -v _tmp|grep -v importinfo)
for tem in $ret;
do
echo ${tem}
sudo -u hdfs hive -e "use ${DB};drop table ${tem}_tmp"
sudo -u hdfs hive -e "use ${DB};create table ${tem}_tmp_1 as select * from ${tem}"
sudo -u hdfs hive -e "use ${DB};alter table ${tem} rename to ${tem}_tmp"
sudo -u hdfs hive -e "use ${DB};alter table ${tem}_tmp_1 rename to ${tem}"
done
impala-shell -q 'invalidate metadata' -i hslave1
row=$(sed -n '/sjob_exec.sh/=' /etc/crontab)
sed -i "$row s/#//" /etc/crontab