b2-data-retention/b2-retention.sh

16 lines
316 B
Bash
Executable file

#!/usr/bin/env sh
FILE_QUOTA=${FILE_QUOTA:-7}
FILE_QUOTA=$((FILE_QUOTA + 1))
TO_DELETE=$( b2v4 ls b2://"$BUCKET_NAME" | tac | tail -n +"$FILE_QUOTA" | tr '\n' ' ' )
PIDS=""
for file in $TO_DELETE; do
b2v4 rm "b2://${BUCKET_NAME}/${file}" &
PIDS="$PIDS $!"
done
for pid in $PIDS; do
wait "${pid}"
done