Created
May 27, 2015 03:31
-
-
Save haiy/e260f6fde3253fe5aadf to your computer and use it in GitHub Desktop.
clone hbase table
This file contains hidden or 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 | |
#author: haiy | |
#date: Mon Mar 30 17:01:00 CST 2015 | |
src=$1 | |
dst=$2 | |
tmp=$dst"_tmp" | |
red=$'\e[31m' | |
reset=$'\e[0m' | |
if [[ $# -lt 2 ]]; then | |
echo "Usage: clone_table source_table_name target_table_name" | |
echo "$red Warning:$reset Use this carefully! It'll delete the target table if it exists." | |
exit | |
fi | |
log=$(pwd)/clone_table.log | |
#log=/dev/null | |
echo "delete_snapshot '$tmp';disable '$dst';" | hbase shell > $log 2>&1 | |
echo "drop '$dst';" | hbase shell >> $log 2>&1 | |
echo "snapshot '$src', '$tmp';clone_snapshot '$tmp', '$dst';delete_snapshot '$tmp';" | hbase shell >> $log 2>&1 | |
stat=$(echo "exists '$dst'" | hbase shell | grep "does exist" | wc -l) | |
if [[ $stat -eq "1" ]]; then | |
rm -f $log | |
echo Clone Table Success! | |
exit 0 | |
else | |
echo Clone Failed!Check $log . | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment