Skip to content

Instantly share code, notes, and snippets.

@haiy
Created May 27, 2015 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haiy/e260f6fde3253fe5aadf to your computer and use it in GitHub Desktop.
Save haiy/e260f6fde3253fe5aadf to your computer and use it in GitHub Desktop.
clone hbase table
#!/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