Last active
August 29, 2015 14:09
-
-
Save irneh/75daee0dffa9185e9637 to your computer and use it in GitHub Desktop.
Delete S3 files that aren't in your Postgres database anymore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
psql -t -c "select key from media order by 1;" hikerpix > db.asc | |
s3cmd ls s3://{{your-bucket-path}} | sort > s3.asc | |
join -v 2 db.asc <(cut -c 55-74 s3.asc | sort -u) > orphans.asc | |
awk '{print $4}' s3.asc | grep -f orphans.asc > urls.asc | |
xargs -P 4 s3cmd del $1 < urls.asc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment