Skip to content

Instantly share code, notes, and snippets.

@rjeczalik
Created March 28, 2019 07:00
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 rjeczalik/b31b531536adbaf6f297077ad6506861 to your computer and use it in GitHub Desktop.
Save rjeczalik/b31b531536adbaf6f297077ad6506861 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
bucket=${1}
mkdir -p ${bucket}
aws s3 ls ${bucket} | grep PRE | tr -s ' ' | cut -d' ' -f3 | while read snapshot_tag; do
snapshot_tag=${snapshot_tag%%/*}
echo "# $(date) reading backup metadata into ${bucket}/${snapshot_tag}.txt" >&2
echo >&2
aws s3api list-objects \
--bucket ${bucket} \
--prefix ${snapshot_tag} \
--query 'Contents[].{Key: Key, ETag: ETag, Size: Size}' |
jq -r '.[] | .Key + "\t" + (.ETag | fromjson) + "\t" + (.Size | tostring)' > ${bucket}/${snapshot_tag%%/*}.txt
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment