IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 5, 2019, 10:34:28 AM (7 years ago)
Author:
fairlamb
Message:

Added a new option to place rsyncs in specific subdirs (for clearer naming)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ipp-350_add_to_jira_conf_backups/backup.py

    r41059 r41060  
    3333    [ ConfigSchemaLine('sources', True, list, SpecialSchemaProcessing.commma_separated)
    3434    , ConfigSchemaLine('additional_args', False, list, SpecialSchemaProcessing.space_separated)
     35    , ConfigSchemaLine('sub-dirs', False, list, SpecialSchemaProcessing.commma_separated)
    3536    ]
    3637)
     
    205206        sources = self.rsync_dict['sources']
    206207        for i in range(0, len(sources)):
    207             s = sources[i]
    208             if not path.exists(s):
    209                     raise errs.ValidationError(f"ValidationError: target path does not exist: {s}")
     208            source = sources[i]
     209            if not path.exists(source):
     210                    raise errs.ValidationError(f"ValidationError: target path does not exist: {source}")
    210211
    211212            for bp in backup_paths:
    212213                try:
    213                     args = [s, bp]
    214 
     214                    additional_args = []
    215215                    if 'additional_args' in self.rsync_dict.keys():
    216                         args = args + self.rsync_dict['additional_args']
     216                        additional_args = self.rsync_dict['additional_args']
     217
     218                    source_and_target_args = [source, bp]
     219
     220                    # sub-dirs option allows items to be backed up to subdirs within
     221                    # the source for better naming
     222                    if 'sub-dirs' in self.rsync_dict:
     223                        sub_dirs = self.rsync_dict['sub-dirs']
     224                        if len(sub_dirs) != len(sources):
     225                            raise errs.ValidationError(f"ValidationError: if using " +
     226                                "subdirs the number of subdirs must equal the number of sources")
     227                        bp_with_subdir = os.path.join(bp, sub_dirs[i])
     228                        if not os.path.exists(bp_with_subdir):
     229                            os.makedirs(bp_with_subdir)
     230                        source_and_target_args = [source, bp_with_subdir]
     231
     232                    args = source_and_target_args + additional_args
    217233                    sub_utils.local_rsync_wrapper(args)
    218234
    219235                except errs.SubprocessError as e:
    220236                    raise errs.SubprocessError( f"Error: rsync\n"
    221                                                 f"    from: {s}\n"
    222                                                 f"    to: {bp}\n"
     237                                                f"    from: {source_and_target_args[0]}\n"
     238                                                f"    to: {source_and_target_args[1]}\n"
    223239                                              ) from e
    224240        return 0
Note: See TracChangeset for help on using the changeset viewer.