Delete snapshots older than 7 days

To avoid running out of disk space in our test environment, we developed a plan to regularly execute shell scripts to clean up unnecessary snapshots.

#!/bin/bash

week=`date --date='7 days ago' +'%Y%m%d'`
echo "list_snapshots" | /home/webuser/hbase-1.2.9/bin/hbase shell | grep "pattern " | \
while read CMD; do
    filename=($CMD)
#    echo $filename
    date=`echo $filename | awk -F "_" '{print $2}'`
#    echo  "${filename#*_}"
#    echo $date
#    echo ${date:0:8}
    if [ "${date:0:8}" -lt $week ]
    then
        echo "delete_snapshot '$filename'" | /home/webuser/hbase-1.2.9/bin/hbase shell
    fi
done
This entry was posted in HBase, Shell Script. Bookmark the permalink.