This repository has been archived on 2023-08-03. You can view files and clone it, but cannot push or open issues or pull requests.
scripts/prod/cleanup-stale-minio-files.zsh

9 lines
652 B
Bash
Executable file

#!/bin/zsh
# Get all files so we can delete them later
files=$(sudo -iu postgres psql -d e2net -c "SELECT \"url\" FROM \"public\".\"drive_file\" WHERE \"isLink\" = 'FALSE' AND \"storedInternal\" = 'FALSE' UNION ALL SELECT \"thumbnailUrl\" FROM \"public\".\"drive_file\" WHERE \"isLink\" = 'FALSE' AND \"storedInternal\" = 'FALSE'" -t -A --csv | sed 's/https:\/\/e2net.cdn.ztn.sh\/drive\///g' | awk NF | sort)
miniofiles=$(mcli ls garage/e2net/drive | grep -Po '[^\s]*$' | grep -Pv '^webpublic-' | sort)
comm -23 <(echo "$miniofiles") <(echo "$files") | sed 's/^/garage\/e2net\/drive\//g' | grep -P '\/e2net\/drive\/.{16,}' | mcli rm --stdin --force