tips
1. Enabling the versioning feature is for the entire bucket, not for a single object.
2. After enabling versioning, all operations must be performed based on the version-ID corresponding to object.
3. The ACL permission of object depends on the latest Version of Object
4. If an object needs to be deleted after versioning is enabled, all versions of the object should be deleted first and then the object should be deleted.
5. After versioning is enabled, each version of an object occupies an independent object space, so reasonable planning avoids wasting space.
6. This feature can be used by AWS2 and AWS4 for JEWEL (CEPH 10.2.6). No bugs have been found.
Boto use cases and instructions
# -*- coding: utf-8 -*- from boto.s3.connection import S3Connection import boto import os import requests os.environ['S3_USE_SIGV4'] = 'True' endpoint = 's3.ceph.work' bucket_name = 'version-test4' access_key = '' secret_key = '' key_name = 'version_object2' conn = boto.connect_s3( aws_access_key_id=access_key, aws_secret_access_key=secret_key, host=endpoint, is_secure=False, calling_format=boto.s3.connection.SubdomainCallingFormat(), validate_certs=True, Bucket = conn.create_bucket(bucket_name) print "get versioning status={}".format(bucket.get_versioning_status()) bucket.configure_versioning(True) print "afert set Versioning =enable,get versioning status={}". Format (bucket.get_versioning_status()) # Create 5 different versions of obj for I in range(5): content_ = "{}{}".format(content_info,i) key_ = bucket.new_key(key_name) key_.set_metadata('metadata',i) Key_.set_contents_from_string (content_) # Get the versioning list of obJ and related properties bucket = conn.get_bucket(bucket_name) version_list_ = [] for i in bucket.list_versions(prefix=key_name): key_ = bucket.get_key(key_name,version_id=i.version_id) print "content={} version_id={} etag={} acl={} metadata={}".format(key_.get_contents_as_string(version_id=i.version_id),i.version_id,i.etag,bucket.get_acl(key_name,ver Sion_id = I.version_id),key_.get_metadata('metadata')) version_list_.append(I.version_id) # SET the ACL for obJ with verioning key_ = bucket.get_key(key_name) print "get key acl={}".format(key_.get_acl()) key_.set_acl('public-read') print "after set key acl=public-read,get key acl={}".format(key_.get_acl()) url_ = "http://{}.{}/{}".format(bucket_name,endpoint,key_name) If resp. Status_code == 200: print "before set acl=public-read -> download successful!" else: Print "before set acl=public-read -> download failed" print "before set acl=public-read -> download failed" Key_name, version_id=version_list_[0]) resp = requests. Get (url_) print "after set acl=public-read ->download successful!" else: Key_ = bucket.get_key(key_name) print "after set acl=public-read -> download failed "get key acl = {}".format(key_.get_acl()) key_ = bucket.get_key(key_name,version_id=version_list_[0]) print "get key Version_id ={} acl= {}". Format (version_list_[0],key_.get_acl()) # Print the current OBj URL key_ = buckey.get_key (key_name) print "Generate_url ={}". Format (key_.generate_URL (300)) #version Rollback operation to obtain the current object information key_ = bucket.get_key(key_name) print "before roll back, content={} metadata={}".format(key_.get_contents_as_string(),key_.get_metadata('metadata')) Key_ = bucket.get_key(key_name,version_id=version_list_[-1]) metadata_ =) {'metadata': key_.get_metadata('metadata')} print "roll back to version_id={} content_={} metadata={}".format(version_list_[-1],key_.get_contents_as_string(version_id=version_list_[-1]),key_.get_metadata('metad ata')) bucket.copy_key(key_name, bucket_name, key_name ,metadata=metadata_, Key_ = bucket.get_key(key_name) print "after roll back, Content ={} metadata={}". Format (key.get_contents_as_string (), key.get_metadata ('metadata')) # Delete key key_ = Bucket.get_key (key_name) key_.delete() bucket = conn.get_bucket(bucket_name) #obj The corresponding versioning still exists for I in bucket.list_versions(prefix=key_name): key_ = bucket.get_key(key_name) print "key {} was deleted,but version_id={} remain".format(i.name,i.version_id) # Even if versioning is closed, Buck.configure_versioning (False) for I in buck.list_versions (prefix=key_name): Key_ = bucket.get_key(key_name) print "get key={} version_id={}". Format (i.name,i.version_id) # Delete versioning for I in bucket.list_versions(prefix=key_name): bucket.delete_key(key_name,version_id=i.version_id) print "deleted versioning -> {}".format(i.version_id) # print For I in bucket. List_versions (prefix=key_name): key_ = bucket.get_key(key_name) print i.name,i.version_idCopy the code
The appendix
Docs.aws.amazon.com/AmazonS3/la… Versioning feature description