Skip to content

Instantly share code, notes, and snippets.

@ohookins
Created September 10, 2012 11:52
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 ohookins/3690514 to your computer and use it in GitHub Desktop.
Save ohookins/3690514 to your computer and use it in GitHub Desktop.
S3 Bucket Versioning
1.8.7 :018 > bucket = s3.buckets['oliver-test-versioning']
=> #<AWS::S3::Bucket:oliver-test-versioning>
1.8.7 :026 > bucket.enable_versioning
=> nil
1.8.7 :027 > bucket.versioned?
=> true
1.8.7 :029 > bucket.versions.each { |v| puts v.class }
AWS::S3::ObjectVersion
AWS::S3::ObjectVersion
AWS::S3::ObjectVersion
=> nil
1.8.7 :030 > bucket.objects.each { |o| o.delete }
=> nil
1.8.7 :031 > bucket.versions.each { |v| puts v.class }
AWS::S3::ObjectVersion
AWS::S3::ObjectVersion
AWS::S3::ObjectVersion
AWS::S3::ObjectVersion
AWS::S3::ObjectVersion
AWS::S3::ObjectVersion
=> nil
1.8.7 :033 > bucket.versions.each { |v| puts "#{v.object.key} => #{v.version_id} (#{v.delete_marker?})" }
24_StdNetz_0107_2012.pdf => WZ5sC9WmMWciIDk928diy_XwJGLMbeH5 (true)
24_StdNetz_0107_2012.pdf => null (false)
S%2BU-Bahn_0107_2012.pdf => Hkkn52r0VOD7kv2ahDukT.pREcmMxQUA (true)
S%2BU-Bahn_0107_2012.pdf => null (false)
TramMetro_0608_2012.pdf => bgQaftdD_d8AdUbxxf8ylzT1EURwItRQ (true)
TramMetro_0608_2012.pdf => null (false)
=> nil
1.8.7 :034 > bucket.versions.each { |v| v.delete }
=> nil
1.8.7 :035 > bucket.versions.each { |v| puts "#{v.object.key} => #{v.version_id} (#{v.delete_marker?})" }
=> nil
@ohookins
Copy link
Author

Note that MFA Delete is not enabled, hence it is possible to just delete all versions.

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