-
Notifications
You must be signed in to change notification settings - Fork 1
/
bulk-delete-buckets-r2.sh
51 lines (44 loc) · 1.86 KB
/
bulk-delete-buckets-r2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
CPUS=$(nproc)
MAX_CONCURRENT=$(($CPUS*2))
# Update PATH to include /usr/local/bin
export PATH=$PATH:/usr/local/bin
# Check if metadata source argument is passed
if [ $# -eq 0 ]
then
echo "No arguments supplied. Please provide the following:"
echo
echo "aws cli profile name i.e. r2"
echo "s3 sharded bucket prefix"
echo "and shard count as an argument."
echo "r2 endpoint-url i.e. https://your_cf_acount_id.r2.cloudflarestorage.com/"
echo
echo "Example if you're JuiceFS sharded bucket name prefix is:"
echo "juicefs-shard-% for juicefs-shard-0, juicefs-shard-1 ... juicefs-shard-60 etc"
echo
echo "$0 r2 juicefs-shard- 60 https://your_cf_acount_id.r2.cloudflarestorage.com/"
exit 1
fi
AWS_PROFILE=$1
BUCKET_PREFIX=$2
SHARD_COUNT=$(($3-1))
ENDPOINT=$4
AWS_DEFAULT_CONCURRENT_REQUESTS=$(aws configure get s3.max_concurrent_requests --profile $AWS_PROFILE)
aws configure set s3.max_concurrent_requests $MAX_CONCURRENT --profile $AWS_PROFILE
AWS_OPTIMAL_CONCURRENT_REQUESTS=$(aws configure get s3.max_concurrent_requests --profile $AWS_PROFILE)
echo "Default s3.max_concurrent_requests: $AWS_DEFAULT_CONCURRENT_REQUESTS"
echo "Optimally set s3.max_concurrent_requests: $AWS_OPTIMAL_CONCURRENT_REQUESTS"
i=0
while [ $i -le $SHARD_COUNT ]
do
# Check if the bucket exists
if aws s3api head-bucket --bucket ${BUCKET_PREFIX}$i --profile "$AWS_PROFILE" --endpoint-url=${ENDPOINT} > /dev/null 2>&1
then
aws s3 rm s3://${BUCKET_PREFIX}$i/myjuicefs --recursive --profile "$AWS_PROFILE" --endpoint-url=${ENDPOINT}
else
echo "Bucket s3://${BUCKET_PREFIX}$i does not exist or you do not have permission to access it."
fi
((i++))
done
aws configure set s3.max_concurrent_requests $AWS_DEFAULT_CONCURRENT_REQUESTS --profile $AWS_PROFILE
echo "Reset to default s3.max_concurrent_requests: $AWS_DEFAULT_CONCURRENT_REQUESTS"