Skip to content

Instantly share code, notes, and snippets.

@RobinUS2
Created December 1, 2015 16:04
Show Gist options
  • Save RobinUS2/43618165a1204c5389d5 to your computer and use it in GitHub Desktop.
Save RobinUS2/43618165a1204c5389d5 to your computer and use it in GitHub Desktop.
Cleanup cassandra tables one by one, starting with the smallest
#!/bin/bash
# This will work in case you have very limited disk space, it will also show more digestable progress compared to nodetool compactionstats
DATA_FOLDER="/var/lib/cassandra/data"
CMD="cleanup"
cd $DATA_FOLDER
# list keyspaces from small to large
KEYSPACES=`du -s * | sort -n | awk '{print $2}'`
# iterate keyspaes
for KS in $KEYSPACES; do
echo "Starting with $KS"
cd $KS
# list tables
TABLES=`du -s * | sort -n | awk '{print $2}'`
# iterate tables
for TABLE in $TABLES; do
echo " Processing $TABLE"
nodetool $CMD $KS $TABLE
done
# back
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment