IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 8, 2019, 3:17:21 PM (7 years ago)
Author:
fairlamb
Message:

Fleshed out basic copy functionality; based off of atlassian backups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ipp-259_genericise_backups/tools/backups/backup.py

    r40920 r40923  
    44
    55import backups.utils.config_parse_helper as cfg_help
    6 from backups.utils.errors import ConfigError
     6import backups.utils.errors as errs
     7import backups.utils.subprocess_utils as sub_utils
    78from configparser import ConfigParser
    89
     
    2425        config = ConfigParser()
    2526        if config_class_or_filepath is None:
    26             raise ConfigError(config_class_or_filepath, "Neither config settings or filepath of config given")
     27            raise errs.ConfigError(config_class_or_filepath, "Neither config settings or filepath of config given")
    2728        elif isinstance(config_class_or_filepath, configparser.ConfigParser):
    2829            config = config_class_or_filepath
     
    119120        actual_hostname = socket.gethostname()
    120121        return actual_hostname == self.default_dict['source_machine']
     122
     123    def run_backup(self):
     124            self._run_copy()
     125            self._run_tar()
     126            self._run_rsync()
     127            self._run_mysqldump()
     128
     129    def _run_copy(self):
     130        if self.run_copy is None or False:
     131            return 0
     132
     133        for bp in self.default_dict['backup_paths']:
     134            if not path.exists(bp):
     135                    raise errs.ValidationError(f"ValidationError: target path does not exist: {bp}")
     136
     137            for s in self.copy_dict['sources']:
     138                if not path.exists(s):
     139                    raise errs.ValidationError(f"ValidationError: target path does not exist: {s}")
     140                try:
     141                    args = [s, bp]
     142                    if 'additional_args' in self.copy_dict.keys():
     143                        print("hiya")
     144                        args = args + self.copy_dict['additional_args']
     145                    sub_utils.cp_wrapper(args)
     146                except errs.SubprocessError as e:
     147                    raise errs.SubprocessError( f"Error: copying\n"
     148                                                f"    from: {s}\n"
     149                                                f"    to: {bp}\n"
     150                                              ) from e
     151        return 0
     152
     153    def _run_tar(self):
     154        if self.run_tar is None or False:
     155            return False
     156        return True
     157
     158    def _run_rsync(self):
     159        if self.run_rsync is None or False:
     160            return False
     161        return True
     162
     163    def _run_mysqldump(self):
     164        if self.run_mysqldump is None or False:
     165            return False
     166        return True
Note: See TracChangeset for help on using the changeset viewer.