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
Raw Permalink Normal View History

2023-05-16 17:33:37 +02:00
#!/bin/zsh
# Get all files so we can delete them later
2023-07-15 22:53:20 +02:00
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)
2023-05-16 17:33:37 +02:00
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