Skip to content

Instantly share code, notes, and snippets.

@irneh
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irneh/75daee0dffa9185e9637 to your computer and use it in GitHub Desktop.
Save irneh/75daee0dffa9185e9637 to your computer and use it in GitHub Desktop.
Delete S3 files that aren't in your Postgres database anymore
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