Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Restore files from latest version in s3
if [ -z "$1" ]; then
echo "An input file is required"
echo "usage: $0 <input-file>"
exit 1
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment