Last active
April 11, 2016 08:14
-
-
Save motiejus/4cd9eb7031da0fa95f50f2109a7abd9e to your computer and use it in GitHub Desktop.
invalidate s3 versions of a given period
This file contains 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
#!/usr/bin/awk -f | |
# Finds objects between two versions, and creates | |
# "aws s3api delete-objects"-compatible json file. | |
# BUG: skips some of the input lines. Should emit the key/val on every line! | |
# Input: | |
# aws s3api --bucket=BUCKET list-object-versions --output text | |
BEGIN { i=0; page=0; } | |
/VERSIONS/ && $5 > "2016-04-06T10:30:00.000Z" && $5 < "2016-04-06T12:30:00.000Z" { | |
page_str=sprintf("%03d.json", page); | |
if (i == 0) { | |
print "{ \"Objects\": [" > page_str; | |
i++; | |
first=1; | |
final=0; | |
} else if (i == 999) { | |
print "]}" >> page_str; | |
i=0; | |
page += 1 | |
final=1 | |
} else { | |
if (first != 1) { | |
print "," >> page_str; | |
} | |
printf ("%s", " {\"Key\": \"" $4 "\", \"VersionId\": " $8 "\"}") >> page_str; | |
first=0; | |
i++; | |
final=0; | |
} | |
} | |
END { if (final != 1) { print "]}" >> page_str; } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment