Powershell Get-S3Version not returning all delete markers

0

I am running a powershell against an S3 bucket to get delete markers for object recovery but not getting all the results back for folders deleted.

Here is the code

$bucketName = "BucketName"
$prefix = "BucketFolder"
((Get-S3Version -BucketName $s3Bucket -Prefix $prefix).Versions | Where { $_.IsDeleteMarker -eq "True"})

The results I get back will contain the delete marker for "FolderA" which was deleted but not "FolderB" which was also deleted. The only way I can get results that include FolderB is to set the $prefix value to explicitly list FolderB like this

$bucketName = "BucketName"
$prefix = "BucketFolder/FolderB"
((Get-S3Version -BucketName $s3Bucket -Prefix $prefix).Versions | Where { $_.IsDeleteMarker -eq "True"})

It seems odd that the results will only show the delete markers for FolderB if it is specified but will show the delete marker for FolderA.

Has anyone seen this behavior before or know a way to get it to return all delete markers?

Mike
질문됨 9달 전267회 조회
2개 답변
0

Did you try adding "/" at the end and see how it works.

Here is how I use to delete the delete markers:

    import boto3
    bucket = 'bkt_name'
    my_session = boto3.Session(profile_name='cli_profile_name')
    s3_client = dev_session.client('s3')
    #s3_client = boto3.client('s3')
    object_response_paginator = s3_client.get_paginator('list_object_versions')
    delete_marker_list = []
    for object_response_itr in object_response_paginator.paginate(Bucket=bucket , Prefix ="prefix_name/",PaginationConfig={
            'MaxItems': 22000,
            'PageSize': 100
        }):
        if 'DeleteMarkers' in object_response_itr:
            for delete_marker in object_response_itr['DeleteMarkers']:
                if(len(delete_marker['Key'].split('/')[len(delete_marker['Key'].split('/')) -1 ] ) > 0 ):
                    output = dev_s3_client.delete_objects(Bucket=bucket,Delete={'Objects': [{'Key': delete_marker['Key'], 'VersionId': delete_marker['VersionId']}]  , 'Quiet': True })
                    print(output)

Replace bkt_name, cli_profile_name and prefix_name in the above script. Test it first in your lower test environment and verify if this is working as expected for you and then only do it in your actual environment.

Hope you find this useful.

Comment here if you have additional questions, happy to help.

Abhishek

profile pictureAWS
전문가
답변함 9달 전
  • Would you mind pasting your snippet here, I can definitely help.

0

I have tried adding / at the end and it doesn't change the results. I'd like to accomplish this with Powershell instead of Python if possible.

Mike
답변함 9달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠