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

Indicate Glacier restore in progress #11469

Open
cyberduck opened this issue Dec 15, 2020 · 1 comment
Open

Indicate Glacier restore in progress #11469

cyberduck opened this issue Dec 15, 2020 · 1 comment
Labels
enhancement s3 AWS S3 Protocol Implementation

Comments

@cyberduck
Copy link
Collaborator

d8d6957 created the issue

It would be nice to have some indication where in the restore process a particular file is at. Thus when getting information on a S3 object, has a restore request been placed, has it now been restored and is ready for download? Even just a history of restore requests would be nice. As it is, when I place a restore request via CyberDuck I never know when it is ready for download other than to try to download it. With a few objects, this is ok but with dozens it's quite tedious. Thx!

@dirkpetersen
Copy link

dirkpetersen commented Nov 3, 2023

I agree, this is quite confusing right now, as a first step it would be great to change the error message when you try to download an object for which a restore request has already been made, something along the lines of

        try {
            // Attempt to get the object
            s3Client.getObject(BUCKET_NAME, OBJECT_KEY);
        } catch (AmazonServiceException e) {
            // Check if it's a 403 error and the operation is not valid for the object's storage class
            if (e.getStatusCode() == 403 && e.getErrorCode().equals("InvalidObjectState")) {
                LocalDateTime restoreInitiationTime = restoreInitiationTimes.get(OBJECT_KEY);
                
                if (restoreInitiationTime == null) {
                    // Initiate a restore request if one has not been initiated before
                    RestoreObjectRequest restoreObjectRequest = new RestoreObjectRequest(BUCKET_NAME, OBJECT_KEY)
                            .withExpirationInDays(7) // Keep the restored data for 7 days
                            .withGlacierJobParameters(new RestoreObjectRequest.GlacierJobParameters()
                                    .withTier(RestoreObjectRequest.Tier.Bulk)); // Initiate a bulk retrieval job

                    s3Client.restoreObject(restoreObjectRequest);
                    
                    // Store the current time as the initiation time for the restore
                    restoreInitiationTimes.put(OBJECT_KEY, LocalDateTime.now());

                    System.out.println("A restore request has been triggered. Please come back in 3-10 hours when the data will be accessible.");
                } else {
                    // Calculate the time passed since the initiation
                    long hoursPassed = java.time.Duration.between(restoreInitiationTime, LocalDateTime.now()).toHours();
                    long hoursRemaining = Math.max(3, 12 - hoursPassed); // Assume max time is 12 hours

                    // Format the initiation time
                    String formattedTime = restoreInitiationTime.format(DateTimeFormatter.ofPattern("dd MMM yyyy 'at' HH:mm"));

                    System.out.println("A restore request was already triggered on " + formattedTime + 
                        ". You may have to wait another " + hoursRemaining + " hours until the object is available for download.");
                }
            } else {
                // Other exceptions can be handled here
                e.printStackTrace();
            }
        }

Also when requesting it is not clear what type of request was made. This should default to "Bulk" -> the cheapest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement s3 AWS S3 Protocol Implementation
Projects
None yet
Development

No branches or pull requests

3 participants