917.1.1
by Curtis Hovey
Added script to delete old s3 buckets to allow tests to pass again. |
1 |
#!/bin/bash
|
2 |
||
3 |
CONFIG=$1 |
|
4 |
if [[ -z $CONFIG ]]; then |
|
5 |
echo $0 path/to/s3config |
|
6 |
exit 1 |
|
7 |
fi
|
|
8 |
||
9 |
# Never delete the juju-ci4 control bucket.
|
|
1139
by Curtis Hovey
Setup up proposed pocket. Pass control-bucket. |
10 |
CI_CONTROL_BUCKET=${2:-$(juju get-env -e juju-ci4 control-bucket)} |
1129.5.1
by Curtis Hovey
Delete s3 control buckets that are about 2 hours old. |
11 |
# This could be almost 3 hours ago.
|
12 |
HOURS_AGO=$(($(date +"%Y%m%d%H") - 2)) |
|
917.1.1
by Curtis Hovey
Added script to delete old s3 buckets to allow tests to pass again. |
13 |
|
14 |
# Get the list of buckets that are 32 hex chars long except the control-bucket.
|
|
15 |
BUCKETS=$(s3cmd -c $CONFIG ls | |
|
16 |
grep -v $CI_CONTROL_BUCKET | |
|
17 |
grep -E 's3://[0-9a-f]{32,32}' | |
|
1129.5.1
by Curtis Hovey
Delete s3 control buckets that are about 2 hours old. |
18 |
cut -d ' ' -f 1,2,4 | |
19 |
sed -r 's,:.* ,_,g; s, ,:,g;') |
|
917.1.1
by Curtis Hovey
Added script to delete old s3 buckets to allow tests to pass again. |
20 |
|
21 |
for bucket in $BUCKETS; do |
|
22 |
name=$(echo "$bucket" | cut -d '_' -f 2) |
|
1129.5.1
by Curtis Hovey
Delete s3 control buckets that are about 2 hours old. |
23 |
datestamp=$(echo "$bucket" | cut -d '_' -f 1 | sed -r 's,:, ,') |
24 |
then=$(date -d "$datestamp" +"%Y%m%d%H") |
|
25 |
if [[ $((then)) -le $((HOURS_AGO)) ]]; then |
|
917.1.1
by Curtis Hovey
Added script to delete old s3 buckets to allow tests to pass again. |
26 |
echo "Deleting $name" created "$datestamp" |
27 |
s3cmd -c $CONFIG del --recursive --force $name |
|
28 |
s3cmd -c $CONFIG rb $name |
|
29 |
else
|
|
30 |
echo "Skipping $name" created "$datestamp" |
|
31 |
fi
|
|
32 |
done
|