From 634b23368544451f1d75c87e106682a5a1060af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 26 Aug 2016 17:50:40 +0200 Subject: [PATCH] mass_copy_between_backends: Also catch unexpected exceptions, and simply move on to the next file. --- pillar/cli.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/pillar/cli.py b/pillar/cli.py index 9c017e0e..a91e9255 100644 --- a/pillar/cli.py +++ b/pillar/cli.py @@ -423,18 +423,24 @@ def mass_copy_between_backends(src_backend='cdnsun', dest_backend='gcs'): projection={'_id': True}) copied_ok = 0 copy_errs = 0 - for fdoc in fdocs: - try: - moving.change_file_storage_backend(fdoc['_id'], dest_backend) - except moving.PrerequisiteNotMetError as ex: - log.error('Error copying %s: %s', fdoc['_id'], ex) - copy_errs += 1 - except requests.exceptions.HTTPError as ex: - log.error('Error copying %s (%s): %s', - fdoc['_id'], ex.response.url, ex) - copy_errs += 1 - else: - copied_ok += 1 + try: + for fdoc in fdocs: + try: + moving.change_file_storage_backend(fdoc['_id'], dest_backend) + except moving.PrerequisiteNotMetError as ex: + log.error('Error copying %s: %s', fdoc['_id'], ex) + copy_errs += 1 + except requests.exceptions.HTTPError as ex: + log.error('Error copying %s (%s): %s', + fdoc['_id'], ex.response.url, ex) + copy_errs += 1 + except Exception: + log.exception('Unexpected exception handling file %s', fdoc['_id']) + copy_errs += 1 + else: + copied_ok += 1 + except KeyboardInterrupt: + log.error('Stopping due to keyboard interrupt') log.info('%i files copied ok', copied_ok) log.info('%i files we did not copy', copy_errs)