def runJobs(self): """Runs the requested backup jobs. Backup jobs are either explicitly listed on the command line or all active backup jobs in configuration file are run. """ dry_run = self._globalConf.get('dry_run', False) for job_name in self._jobs: self._numJobs += 1 logmgr.setContext(job_name) job_conf = self._jobsConf.get(job_name) if job_conf is not None: active = parse_value(job_conf.get('active', 'yes'), True) if active: job_pre_exec = job_conf.get('job_pre_exec') job_post_exec = job_conf.get('job_post_exec') if job_pre_exec is not None: logger.info("Executing job pre-execution script.") try: execExternalCmd(job_pre_exec.split(), None, dry_run) job_pre_exec_ok = True except errors.ExternalCmdError, e: job_pre_exec_ok = False job_ok = False logger.error("Job pre-execution script failed.") logger.error(e.desc) for line in e: logger.error(" %s" , line) else: job_pre_exec_ok = True if job_pre_exec_ok: try: logger.info("Starting execution of backup job.") job = BackupJob(job_name, self._globalConf, job_conf) job.run() logger.info("Finished execution of backup job.") job_ok = True except errors.BackupError, e: logger.error("Execution of backup job failed.") job_ok = False if e.trace or e.fatal: raise else: if e.fatal: level = logging.CRITICAL else: level = logging.ERROR logger.log(level, e.desc) for line in e: logger.log(level, " %s" , line) if job_post_exec is not None and job_pre_exec_ok: logger.info("Executing job post-execution script.") try: execExternalCmd(job_post_exec.split(), None, dry_run) except errors.ExternalCmdError, e: job_ok = False logger.error("Job pre-execution script failed.") logger.error(e.desc) for line in e: logger.error(" %s" , line) if job_ok: self._numJobsSuccess += 1 else: self._numJobsError += 1
execExternalCmd(job_post_exec.split(), None, dry_run) except errors.ExternalCmdError, e: job_ok = False logger.error("Job pre-execution script failed.") logger.error(e.desc) for line in e: logger.error(" %s" , line) if job_ok: self._numJobsSuccess += 1 else: self._numJobsError += 1 else: logger.warn("Backup job disabled by configuration.") self._numJobsDisabled += 1 else: logger.error("No configuration found for backup job.") self._numJobsError += 1 def run(self): """Runs backup process. """ self.loggingInit() self.parseConfFile() self.loadPlugins() if self._help is not None: if self._help == 'list-jobs': self.listJobs() elif self._help == 'list-plugins': self.listPlugins() elif self._help == 'list-methods':