Skip to content

Instantly share code, notes, and snippets.

@ibspoof
Last active September 2, 2016 20:56
Show Gist options
  • Save ibspoof/f63e1c075516e9d805824695444d38d6 to your computer and use it in GitHub Desktop.
Save ibspoof/f63e1c075516e9d805824695444d38d6 to your computer and use it in GitHub Desktop.
EPOCH_START=1472838
JBOD_DRIVES=/app/cassandra/datastax/dse-data*
SNAPSHOT_DATE="Sep 2"
SNAPSHOT_TIME="10:4"
## don't edit below
declare -A refresh_tables
SNAPS=$(ls -R $JBOD_DRIVES | grep $EPOCH_START | grep "app/")
while read -r line; do
MOVE_FROM=$(echo $line | awk -F":" '{print $1}')
#echo "MOVE_FROM = $MOVE_FROM"
TABLE_NAME=$(echo $line | awk -F"/" '{print $7}' | awk -F"-" '{print $1}')
#echo "TABLENAME = $TABLE_NAME"
KEYSPACE_DIR=$(echo $line | awk -F/ '{print "/"$2"/"$3"/"$4"/"$5"/"$6}')
KEYSPACE_NAME=$(echo $line | awk -F"/" '{print $6}')
#echo "KEYSPACE_DIR = $KEYSPACE_DIR"
TABLE_UUID=$(ls -la $KEYSPACE_DIR | grep "${TABLE_NAME}-" | grep $SNAPSHOT_DATE | grep $SNAPSHOT_TIME | awk '{print $9}')
TABLE_UUID_CNT=$(echo "$TABLE_UUID" | wc -l)
if [ "$TABLE_UUID_CNT" != 1 ]; then
echo "ERROR: $KEYSPACE_DIR - $TABLE_UUID has to many results, skipping"
continue
fi
echo "NEW_TABLE_DIR = $KEYSPACE_DIR/$TABLE_UUID/"
TABLE_CNT=$(ls $MOVE_FROM | grep -v .json | wc -l)
if [ "$TABLE_CNT" == "0" ]; then
echo "TBL_CNT of $MOVE_FROM == 0. Skipping."
continue
fi
# if table uuid isn't found, then skip it
if [ "x$TABLE_UUID" == "x" ]; then
continue
fi
refresh_tables[$TABLE_NAME]="refresh"
echo "Moving $MOVE_FROM/* TO $KEYSPACE_DIR/$TABLE_UUID/"
mv $MOVE_FROM/* $KEYSPACE_DIR/$TABLE_UUID/
done <<< "$SNAPS"
echo "Refreshing the tables using nodetool..."
for i in "${!refresh_tables[@]}"
do
#echo "nohup nodetool refresh $KEYSPACE_NAME $i > nohup_$i.out &"
nohup nodetool refresh $KEYSPACE_NAME $i > nohup_$i.out &
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment