Browse code

Add option to ignore error on copy when key no longer exists

Børge Nerdal Kjelsrud authored on 2013/03/20 18:26:11
Showing 2 changed files
... ...
@@ -98,6 +98,7 @@ class Config(object):
98 98
     additional_destinations = []
99 99
     cache_file = ""
100 100
     add_headers = ""
101
+    ignore_failed_copy = False
101 102
 
102 103
     ## Creating a singleton
103 104
     def __new__(self, configfile = None):
... ...
@@ -566,10 +566,16 @@ def subcmd_cp_mv(args, process_fce, action_str, message):
566 566
         dst_uri = S3Uri(item['dest_name'])
567 567
 
568 568
         extra_headers = copy(cfg.extra_headers)
569
-        response = process_fce(src_uri, dst_uri, extra_headers)
570
-        output(message % { "src" : src_uri, "dst" : dst_uri })
571
-        if Config().acl_public:
572
-            info(u"Public URL is: %s" % dst_uri.public_url())
569
+        try:
570
+            response = process_fce(src_uri, dst_uri, extra_headers)
571
+            output(message % { "src" : src_uri, "dst" : dst_uri })
572
+            if Config().acl_public:
573
+                info(u"Public URL is: %s" % dst_uri.public_url())
574
+        except S3Error, e:
575
+            if cfg.ignore_failed_copy and e.code == "NoSuchKey":
576
+                warning(u"Key not found %s" % item['object_uri_str'])
577
+            else:
578
+                raise
573 579
 
574 580
 def cmd_cp(args):
575 581
     s3 = S3(Config())
... ...
@@ -1784,6 +1790,7 @@ def main():
1784 1784
     optparser.add_option(      "--include-from", dest="include_from", action="append", metavar="FILE", help="Read --include GLOBs from FILE")
1785 1785
     optparser.add_option(      "--rinclude", dest="rinclude", action="append", metavar="REGEXP", help="Same as --include but uses REGEXP (regular expression) instead of GLOB")
1786 1786
     optparser.add_option(      "--rinclude-from", dest="rinclude_from", action="append", metavar="FILE", help="Read --rinclude REGEXPs from FILE")
1787
+    optparser.add_option(      "--ignore-failed-copy", dest="ignore_failed_copy", action="store_true", help="Don't exit unsuccessfully because of missing keys")
1787 1788
 
1788 1789
     optparser.add_option(      "--bucket-location", dest="bucket_location", help="Datacentre to create bucket in. As of now the datacenters are: US (default), EU, ap-northeast-1, ap-southeast-1, sa-east-1, us-west-1 and us-west-2")
1789 1790
     optparser.add_option(      "--reduced-redundancy", "--rr", dest="reduced_redundancy", action="store_true", help="Store object with 'Reduced redundancy'. Lower per-GB price. [put, cp, mv]")