Created
April 30, 2019 01:54
-
-
Save JCotton1123/8ab4f925b37217379da9c3d5aaca5d94 to your computer and use it in GitHub Desktop.
Restore files from latest version in s3
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
#!/bin/bash | |
if [ -z "$1" ]; then | |
echo "An input file is required" | |
echo "usage: $0 <input-file>" | |
exit 1 | |
fi | |
files=$(cat $1) | |
for f in $files; do | |
bucket=$(echo $f | cut -d/ -f3) | |
prefix=$(echo $f | sed "s/^s3:\/\/$bucket\///") | |
versions=$(aws s3api list-object-versions --bucket $bucket --prefix $prefix) | |
version_id=$(echo "$versions" | jq '.Versions[0].VersionId' | tr -d '"') | |
mkdir -p $(dirname $prefix) | |
aws s3api get-object --bucket $bucket --key $prefix --version-id $version_id $prefix | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment