s3-pit-restore icon indicating copy to clipboard operation
s3-pit-restore copied to clipboard

Restoring latest deleted files (no date range)

Open Mauricio-RPP opened this issue 3 years ago • 1 comments

Hi, I'd like to suggest to add an option to restore all files that have been deleted from a bucket, but without the need to specify a date/range.

It would be important to list only the latest version before the delete marker (or with flags to restore all versions maybe).

would it be too hard to implement in this tool?

cheers

Mauricio-RPP avatar Oct 15 '21 20:10 Mauricio-RPP

In my case, I had a list of exact object names to restore so was able to come up with a loop to find the latest version of the an object that was deleted at any point in time, and copy it over to another S3 bucket (or simply remove the deleted flag on same bucket too).

the key command was this line: aws s3api list-object-versions --bucket MY_BUCKET --prefix 'FOLDER/FILE.TXT' --query 'Versions[?Key==FOLDER/FILE.TXT]' | jq -c '[.[]] | max_by(.LastModified)|.VersionId' -r

while it needs the exact object name and thus is slow, it gets the latest version from what could be many. With object NAME+VersionId, we can also copy it to a new bucket with no need to restore first (not sure if this would be well fit for this project, but there is the idea).

Mauricio-RPP avatar Nov 01 '21 19:11 Mauricio-RPP