From c8731b0c5ce61d7e45f3be2aa83ad96eb1c2404a Mon Sep 17 00:00:00 2001 From: Alexandre Lavigne Date: Sun, 14 Apr 2024 13:14:43 +0200 Subject: [PATCH] Improve recursive object restore When restoring a complete bucket stop and raise an error only when the configuration is set to stop on the first error. otherwise keep trying to restore the next objects. Ignore the following errors: - When the object is currently in transition - When the object is not concerned by the restore request (already in standard storage-class etc) closes #1369 Signed-off-by: Alexandre Lavigne --- s3cmd | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/s3cmd b/s3cmd index 2db88f25..65472d56 100755 --- a/s3cmd +++ b/s3cmd @@ -923,6 +923,8 @@ def cmd_object_restore(args): warning(u"Exiting now because of --dry-run") return EX_OK + ret = EX_OK + for key in remote_list: item = remote_list[key] @@ -932,13 +934,17 @@ def cmd_object_restore(args): response = s3.object_restore(S3Uri(item['object_uri_str'])) output(u"restore: '%s'" % item['object_uri_str']) except S3Error as e: - if e.code == "RestoreAlreadyInProgress": + if e.code in ("RestoreAlreadyInProgress", "InvalidObjectState"): warning("%s: %s" % (e.message, item['object_uri_str'])) - else: + elif cfg.stop_on_error: raise e + else: + error("restore failed for: '%s' (%s)", item['object_uri_str'], e) + ret = EX_PARTIAL + else: debug(u"Skipping directory since only files may be restored") - return EX_OK + return ret def subcmd_cp_mv(args, process_fce, action_str, message):