def run_backup_job(cfg, run_type, lock_file=LOCK_FILE): """ Grab a lock waiting up to allowed timeout and start backup jobs :param cfg: Tool configuration :type cfg: ConfigParser.ConfigParser :param run_type: Run type :type run_type: str :param lock_file: File used as a lock :type lock_file: str """ with timeout(get_timeout(run_type)): try: file_desriptor = open(lock_file, 'w') fcntl.flock(file_desriptor, fcntl.LOCK_EX) LOG.debug(run_type) if cfg.getboolean('intervals', "run_%s" % run_type): backup_everything(run_type, cfg) else: LOG.debug('Not running because run_%s is no', run_type) except IOError as err: if err.errno != errno.EINTR: raise err msg = 'Another instance of twindb-backup is running?' if run_type == 'hourly': LOG.debug(msg) else: LOG.error(msg)
def run_backup_job(twindb_config, run_type, lock_file=LOCK_FILE, binlogs_only=False): """ Grab a lock waiting up to allowed timeout and start backup jobs :param twindb_config: Tool configuration :type twindb_config: TwinDBBackupConfig :param run_type: Run type :type run_type: str :param lock_file: File used as a lock :type lock_file: str :param binlogs_only: If True copy only binlogs. :type binlogs_only: bool """ with timeout(get_timeout(run_type)): try: file_desriptor = open(lock_file, 'w') fcntl.flock(file_desriptor, fcntl.LOCK_EX) LOG.debug(run_type) if getattr(twindb_config.run_intervals, run_type): backup_everything( run_type, twindb_config, binlogs_only=binlogs_only ) else: LOG.debug('Not running because run_%s is no', run_type) except IOError as err: if err.errno != errno.EINTR: LOG.debug(traceback.format_exc()) raise LockWaitTimeoutError(err) msg = 'Another instance of twindb-backup is running?' if run_type == 'hourly': LOG.debug(msg) else: LOG.error(msg)
def run_backup_job(twindb_config, run_type, lock_file=LOCK_FILE, binlogs_only=False): """ Grab a lock waiting up to allowed timeout and start backup jobs :param twindb_config: Tool configuration :type twindb_config: TwinDBBackupConfig :param run_type: Run type :type run_type: str :param lock_file: File used as a lock :type lock_file: str :param binlogs_only: If True copy only binlogs. :type binlogs_only: bool """ with timeout(get_timeout(run_type)): try: file_desriptor = open(lock_file, "w") fcntl.flock(file_desriptor, fcntl.LOCK_EX) LOG.debug(run_type) if getattr(twindb_config.run_intervals, run_type): backup_everything(run_type, twindb_config, binlogs_only=binlogs_only) else: LOG.debug("Not running because run_%s is no", run_type) except IOError as err: if err.errno != errno.EINTR: LOG.debug(traceback.format_exc()) raise LockWaitTimeoutError(err) msg = "Another instance of twindb-backup is running?" if run_type == "hourly": LOG.debug(msg) else: LOG.error(msg)
def test_get_timeout(run_type, timeout): assert get_timeout(run_type) == timeout