IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 5, 2019, 3:18:35 PM (7 years ago)
Author:
fairlamb
Message:

merge of branch ipp-350 into trunk

Location:
trunk/backups
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/backups

  • trunk/backups/backup.py

    r40973 r41067  
    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)
     
    8384
    8485        self.read_config_and_schema(config, schema)
    85         # self.read_copy_config_section(config, schema)
    86         # self.read_tar_config_section(config, schema)
    87         # self.read_rsync_config_section(config, schema)
    88         # self.read_mysqldump_config_section(config, schema)
    8986
    9087    def read_config_and_schema(self, config: ConfigParser, schema: ConfigSchema):
     
    206203        self.target_backup_paths_ok(raise_error=True)
    207204        backup_paths = self.default_dict['backup_paths']
    208         for bp in backup_paths:
    209             # if not path.exists(bp):
    210             #     raise errs.ValidationError(f"ValidationError: target path does not exist: {bp}")
    211 
    212             for s in self.rsync_dict['sources']:
    213                 if not path.exists(s):
    214                     raise errs.ValidationError(f"ValidationError: target path does not exist: {s}")
     205
     206        sources = self.rsync_dict['sources']
     207        for i in range(0, len(sources)):
     208            source = sources[i]
     209            if not path.exists(source):
     210                    raise errs.ValidationError(f"ValidationError: target path does not exist: {source}")
     211
     212            for bp in backup_paths:
    215213                try:
    216                     args = [s, bp]
     214                    additional_args = []
    217215                    if 'additional_args' in self.rsync_dict.keys():
    218                         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
    219233                    sub_utils.local_rsync_wrapper(args)
     234
    220235                except errs.SubprocessError as e:
    221236                    raise errs.SubprocessError( f"Error: rsync\n"
    222                                                 f"    from: {s}\n"
    223                                                 f"    to: {bp}\n"
     237                                                f"    from: {source_and_target_args[0]}\n"
     238                                                f"    to: {source_and_target_args[1]}\n"
    224239                                              ) from e
    225240        return 0
Note: See TracChangeset for help on using the changeset viewer.