File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111 id-token : write
1212 contents : read
1313 env :
14- LOGNAME : ${{ needs.config.outputs.logname }}
1514 BUCKET : " quic-interop-runner"
15+ RETENTION_DAYS : " 3"
1616 steps :
1717 - uses : actions/checkout@v3
1818 - uses : actions/setup-python@v4
2626 B2_APPLICATION_KEY : ${{ secrets.BACKBLAZE_APPLICATION_KEY }}
2727 - name : upload a file
2828 run : |
29- b2 ls --long ${{ env.BUCKET }}
30- b2 ls --long ${{ env.BUCKET}} | awk -v days=3 -v today=$(date +%s) '$1=="upload" && (today - $3) > days*86400 {print $4}'
31-
29+ threshold_time=$((($(date +%s) * 1000) - (${{ env.RETENTION_DAYS }} * 24 * 60 * 60 * 1000)))
30+ old_files=$(b2 ls --json ${{ env.BUCKET}} | jq -r ".[] | select(.uploadTimestamp > $threshold_time)")
31+ echo "Deleting files:"
32+ echo $old_files | jq ".fileName"
33+ # Now delete them
34+ echo $old_files | jq -r ".fileName" | while read -r filename; do
35+ dir_name="${filename%%/*}"
36+ echo "Deleting $dir_name"
37+ # see https://github.com/Backblaze/B2_Command_Line_Tool/issues/495#issuecomment-413932585
38+ mkdir empty # create an empty directory
39+ b2 sync --delete --allowEmptySource empty b2://${{ env.BUCKET }}/"$dir_name"
40+ rmdir empty
41+ done
3242
You can’t perform that action at this time.
0 commit comments