Skip to content

Instantly share code, notes, and snippets.

@prasincs
Created May 29, 2015 06:29
Show Gist options
  • Save prasincs/bb38e6049ce3938c9731 to your computer and use it in GitHub Desktop.
Save prasincs/bb38e6049ce3938c9731 to your computer and use it in GitHub Desktop.
Removing Hbase snapshots
#!/bin/bash
function remove_bucket() {
s3cmd rm --force --recursive s3://$1 && s3cmd rb s3://$1
}
dry_run=0
HBASE_SNAPSHOT_BUCKETS=$(aws s3api list-buckets | jq -r ".Buckets[].Name" | grep "hbase-snapshots")
echo "About to delete the following buckets: $HBASE_SNAPSHOT_BUCKETS"
for bucket in $HBASE_SNAPSHOT_BUCKETS; do
echo "Checking $bucket"
if [ $dry_run == 1 ]; then
echo "Would Delete $bucket";
else
read -p $'All contents in \e[1;33m'"$bucket"$'\e[0m will be deleted including the bucket. Do you want to continue?' -n 1 -r -e
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
else
remove_bucket $bucket
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment