Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring latest deleted files (no date range) #20

Open
Mauricio-RPP opened this issue Oct 15, 2021 · 1 comment
Open

Restoring latest deleted files (no date range) #20

Mauricio-RPP opened this issue Oct 15, 2021 · 1 comment

Comments

@Mauricio-RPP
Copy link

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
Copy link
Author

Mauricio-RPP commented Nov 1, 2021

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant