Skip to content

Instantly share code, notes, and snippets.

@andreafalzetti
Last active September 5, 2018 14:20
Show Gist options
  • Save andreafalzetti/01135920dbc47fef9c0ffe6985858b76 to your computer and use it in GitHub Desktop.
Save andreafalzetti/01135920dbc47fef9c0ffe6985858b76 to your computer and use it in GitHub Desktop.
Simple bash script to download and bundle an s3 bucket
#!/usr/bin/env bash
# Simple bash script to download and bundle an s3 bucket
# Usage:
# AWS_PROFILE=... S3_BUCKET_NAME=... ./s3bucket-to-tar
# Requires:
# aws cli, tar
set -euo pipefail
typeset -r DIR=$(cd "$(dirname "$0")" && pwd)
TMP_FOLDER=$(mktemp -d)
S3_BUCKET_NAME=${S3_BUCKET_NAME:-""}
aws s3 sync s3://$S3_BUCKET_NAME $TMP_FOLDER --quiet
DATE=`date +%Y-%m-%d`
OUTPUT=$DIR/$S3_BUCKET_NAME.tar.gz
tar czfP $OUTPUT $TMP_FOLDER
# Clean-up
rm -r $TMP_FOLDER
echo $OUTPUT
@andreafalzetti
Copy link
Author

andreafalzetti commented Sep 5, 2018

curl -O https://gist.githubusercontent.com/andreafalzetti/01135920dbc47fef9c0ffe6985858b76/raw/601cde6aa74dfb38c5ae676354ccb11426652c1f/s3bucket-to-tar && chmod +x s3bucket-to-tar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment