Skip to content

Instantly share code, notes, and snippets.

@motiejus
Last active April 11, 2016 08:14
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 motiejus/4cd9eb7031da0fa95f50f2109a7abd9e to your computer and use it in GitHub Desktop.
Save motiejus/4cd9eb7031da0fa95f50f2109a7abd9e to your computer and use it in GitHub Desktop.
invalidate s3 versions of a given period
#!/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