Skip to content

Instantly share code, notes, and snippets.

@concubidated
Last active October 5, 2016 17:17
Show Gist options
  • Save concubidated/28178afa1434270db86325cd488552d1 to your computer and use it in GitHub Desktop.
Save concubidated/28178afa1434270db86325cd488552d1 to your computer and use it in GitHub Desktop.
Delete with s3cmd, X at a time in BG.
#!/bin/bash
CONFIG="/etc/pod/.s3cfg-live"
BUCKET="live"
NUM_DELETES=20
CHANNELS=$(s3cmd -c $CONFIG ls s3://$BUCKET/ | grep DIR | awk -F'/' '{print $4}')
i=0
TOTAL=0
for CHAN in $CHANNELS
do
echo "Deleting $CHAN"
EPOCH_GROUP=$(s3cmd -c $CONFIG ls s3://$BUCKET/$CHAN/ | grep DIR | awk -F'/' '{print $5}')
for GROUP in $EPOCH_GROUP
do
echo "Deleting $GROUP"
#delete group
s3cmd -c $CONFIG rm --recursive s3://live/$CHAN/$GROUP/ >> deletelog.log &
i=$((i+1))
TOTAL=$((TOTAL+1))
if [ "$i" -ge "$NUM_DELETES" ]
then
#wait for bath to finish deleting in BG
wait;
i=0;
fi
done
echo $TOTAL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment