def __init__(self): GeneralClass.__init__(self) # ================================= # Connecting To MySQL # ================================= #self.password = re.search(r'\-\-password\=(.*)[\s]*', self.myuseroption) self.config = { 'user': self.mysql_user, 'password': self.mysql_password, 'host': 'localhost', #'database': 'bck', 'raise_on_warnings': True, 'port' : self.mysql_port } try: self.cnx = mysql.connector.connect(**self.config) self.cur = self.cnx.cursor() except mysql.connector.Error as err: print("MySQL server connection problem. ") print("Check if your MySQL server is up and running or if there is no firewall blocking connection.") print(err) exit(0)
def __init__(self, config=path_config.config_path_file): self.conf = config GeneralClass.__init__(self, self.conf) self._xtrabackup_history_log = [[ 'command', 'xtrabackup_function', 'start time', 'end time', 'duration', 'exit code' ]]
def __init__(self): GeneralClass.__init__(self) # ================================= # Connecting To MySQL # ================================= self.password = re.search(r"\-\-password\=(.*)[\s]*", self.myuseroption) self.config = { "user": "******", "password": self.password.group(1), "host": "localhost", "database": "bck", "raise_on_warnings": True, } try: self.cnx = mysql.connector.connect(**self.config) self.cur = self.cnx.cursor() except mysql.connector.Error as err: print("MySQL server connection problem. ") print("Check if your MySQL server is up and running or if there is no firewall blocking connection.") print(err) exit(0)
def __init__(self, config='/etc/bck.conf', full_dir=None, inc_dir=None): self.conf = config GeneralClass.__init__(self, self.conf) if full_dir is not None: self.full_dir = full_dir if inc_dir is not None: self.inc_dir = inc_dir
def __init__(self, config=path_config.config_path_file, full_dir=None, inc_dir=None): self.conf = config GeneralClass.__init__(self, self.conf) if full_dir: self.full_dir = full_dir if inc_dir: self.inc_dir = inc_dir
def __init__(self): GeneralClass.__init__(self) # ================================= # Connecting To MySQL # ================================= self.password = re.search(r'\-\-password\=(.*)[\s]*', self.myuseroption) self.config = { 'user': '******', 'password': self.password.group(1), 'host': 'localhost', 'database': 'bck', 'raise_on_warnings': True, } try: self.cnx = mysql.connector.connect(**self.config) self.cur = self.cnx.cursor() except mysql.connector.Error as err: print("MySQL server connection problem. ") print( "Check if your MySQL server is up and running or if there is no firewall blocking connection." ) print(err) exit(0)
def __init__(self, config="/etc/bck.conf", dry_run=0): self.conf = config self.dry = dry_run GeneralClass.__init__(self, self.conf) self.check_env_obj = CheckEnv(self.conf) # If prepare_tool option enabled in config, make backup_tool to use this. if hasattr(self, 'prepare_tool'): self.backup_tool = self.prepare_tool
def __init__(self): GeneralClass.__init__(self) self.password_reg = re.search(r'\-\-password\=(.*)[\s]*', self.myuseroption) self.user_reg = re.search(r'\-\-user\=(.*)[\s]--', self.myuseroption) self.password = self.password_reg.group(1) self.user = self.user_reg.group(1)
def __init__(self, config='/etc/bck.conf'): self.conf = config GeneralClass.__init__(self, self.conf) if shutil.which('mysqlfrm') is None: logger.critical( "Could not find mysqlfrm! Please install it or check if it is in PATH" ) logger.critical("Aborting!") sys.exit(-1)
def __init__(self, config=path_config.config_path_file): self.conf = config GeneralClass.__init__(self, self.conf) if shutil.which('mysqlfrm') is None: logger.critical( "Could not find mysqlfrm! Please install it or check if it is in PATH" ) raise RuntimeError( "Could not find mysqlfrm! Please install it or check if it is in PATH" )
def test_show_tags(self): gen_obj = GeneralClass() for conf_files in gen_obj.xb_configs.split(): if '2_3' in conf_files and '5_6' in conf_files: obj = Backup( config='{}/{}'.format(gen_obj.testpath, conf_files)) obj.show_tags(obj.backupdir)
def all_procedure(prepare, backup, partial, verbose, log, defaults_file): logger.setLevel(log) formatter = logging.Formatter( fmt='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S') if verbose: ch = logging.StreamHandler() ch.setFormatter(formatter) logger.addHandler(ch) validate_file(defaults_file) config = GeneralClass(defaults_file) pid_file = pid.PidFile(piddir=config.pid_dir) try: with pid_file: # User PidFile for locking to single instance if (not prepare) and (not backup) and (not partial) and ( not defaults_file): print( "ERROR: you must give an option, run with --help for available options" ) elif prepare: a = Prepare(config=defaults_file) a.prepare_backup_and_copy_back() # print("Prepare") elif backup: b = Backup(config=defaults_file) b.all_backup() # print("Backup") elif partial: c = PartialRecovery(config=defaults_file) c.final_actions() except pid.PidFileAlreadyLockedError as error: if hasattr(config, 'pid_runtime_warning'): if time.time() - os.stat( pid_file.filename).st_ctime > config.pid_runtime_warning: pid.fh.seek(0) pid_str = pid.fh.read(16).split("\n", 1)[0].strip() logger.critical("Backup (pid: " + pid_str + ") has been running for logger than: " + str( humanfriendly.format_timespan( config.pid_runtime_warning))) #logger.warn("Pid file already exists: " + str(error)) except pid.PidFileAlreadyRunningError as error: if hasattr(config, 'pid_runtime_warning'): if time.time() - os.stat( pid_file.filename).st_ctime > config.pid_runtime_warning: pid.fh.seek(0) pid_str = pid.fh.read(16).split("\n", 1)[0].strip() logger.critical("Backup (pid: " + pid_str + ") has been running for logger than: " + str( humanfriendly.format_timespan( config.pid_runtime_warning))) #logger.warn("Pid already running: " + str(error)) except pid.PidFileUnreadableError as error: logger.warn("Pid file can not be read: " + str(error)) except pid.PidFileError as error: logger.warn("Generic error with pid file: " + str(error))
def test_options_combination_generator(self, return_config_generator_obj): mysql_options = GeneralClass( config='{}/{}'.format(return_config_generator_obj.testpath, 'xb_2_4_ps_5_6.conf')).mysql_options assert len( return_config_generator_obj.options_combination_generator( mysql_options)) > 0 assert isinstance( return_config_generator_obj.options_combination_generator( mysql_options), list)
def test_inc_backup(self): # Method for running inc_backup() gen_obj = GeneralClass() for conf_files in gen_obj.xb_configs.split(): if '2_3' in conf_files and '5_6' in conf_files: obj = Backup(config='{}/{}'.format(gen_obj.testpath, conf_files), dry_run=0, tag="My first inc backup") obj.inc_backup()
def __init__(self): GeneralClass.__init__(self) # ================================= # Connecting To MySQL # ================================= self.password = re.search(r'\-\-password\=(.*)[\s]*', self.myuseroption) self.config = { 'user': '******', 'password': self.password.group(1), 'host': 'localhost', 'database': 'bck', 'raise_on_warnings': True, } self.cnx = mysql.connector.connect(**self.config) self.cur = self.cnx.cursor()
def __init__(self): GeneralClass.__init__(self) # ================================= # Connecting To MySQL # ================================= self.password = re.search(r'\-\-password\=(.*)[\s]*',self.myuseroption) self.config = { 'user': '******', 'password': self.password.group(1), 'host': 'localhost', 'database': 'bck', 'raise_on_warnings': True, } self.cnx = mysql.connector.connect(**self.config) self.cur = self.cnx.cursor()
def test_add_tag(self): # Method for checking the add_tag() static method. All parameters are hard coded. gen_obj = GeneralClass() for conf_files in gen_obj.xb_configs.split(): if '2_3' in conf_files and '5_6' in conf_files: obj = Backup(config='{}/{}'.format(gen_obj.testpath, conf_files), dry_run=0, tag="My first full backup") backup_name = obj.recent_full_backup_file() obj.add_tag(backup_dir=obj.backupdir, backup_name=backup_name, type='Full', tag_string=obj.tag)
def __init__(self): GeneralClass.__init__(self) # ================================= # Connecting To MySQL # ================================= #self.password = re.search(r'\-\-password\=(.*)[\s]*', self.myuseroption) self.config = { 'user': self.mysql_user, 'password': self.mysql_password, #'database': 'bck', 'raise_on_warnings': True, } if hasattr(self, 'mysql_socket'): self.config['unix_socket'] = self.mysql_socket elif hasattr(self, 'mysql_host') and hasattr(self, 'mysql_port'): self.config['host'] = self.mysql_host self.config['port'] = self.mysql_port else: logger.critical( "Neither mysql_socket nor mysql_host and mysql_port are defined in config!" ) try: self.cnx = mysql.connector.connect(**self.config) self.cur = self.cnx.cursor() except mysql.connector.Error as err: logger.error("MySQL server connection problem. ") logger.error( "Check if your MySQL server is up and running or if there is no firewall blocking connection." ) logger.error(err) exit(0)
def __init__(self): GeneralClass.__init__(self) from master_backup_script.check_env import CheckEnv self.check_env_obj = CheckEnv() self.result = self.check_env_obj.check_systemd_init()
def __init__(self, config='/etc/bck.conf', dry_run=0): self.conf = config self.dry = dry_run # Call GeneralClass for storing configuration GeneralClass.__init__(self, self.conf)
def __init__(self): GeneralClass.__init__(self)
def __init__(self, config="/etc/bck.conf"): self.conf = config GeneralClass.__init__(self, self.conf) self.check_env_obj = CheckEnv(self.conf) self.result = self.check_env_obj.check_systemd_init()
def __init__(self, *args, **kwargs): GeneralClass.__init__(self, *args, **kwargs)
def __init__(self, config='/etc/bck.conf'): self.conf = config #Call GeneralClass for storing configuration GeneralClass.__init__(self, self.conf)
def test_run_all_backup(self): gen_obj = GeneralClass() for conf_files in gen_obj.xb_configs.split(): obj = WrapperForBackupTest( config='{}/{}'.format(gen_obj.testpath, conf_files)) obj.run_all_backup()
def __init__(self, config=path_config.config_path_file): self.conf = config self.testpath = GeneralClass(self.conf).testpath self.basedir = CloneBuildStartServer(self.conf).get_basedir()
def __init__(self): GeneralClass.__init__(self) self.variable_values=[]
def __init__(self, config='/etc/bck.conf'): self.conf = config GeneralClass.__init__(self, self.conf)
def __init__(self, *args, **kwargs): #Call GeneralClass for storing configuration GeneralClass.__init__(self, *args, **kwargs)
def all_procedure(ctx, prepare, backup, partial, tag, show_tags, verbose, log_file, log, defaults_file, dry_run, test_mode, log_file_max_bytes, log_file_backup_count, keyring_vault): config = GeneralClass(defaults_file) formatter = logging.Formatter( fmt='%(asctime)s %(levelname)s [%(module)s:%(lineno)d] %(message)s', datefmt='%Y-%m-%d %H:%M:%S') if verbose: ch = logging.StreamHandler() # control console output log level ch.setLevel(logging.INFO) ch.setFormatter(formatter) logger.addHandler(ch) if log_file: try: if config.log_file_max_bytes and config.log_file_backup_count: file_handler = RotatingFileHandler( log_file, mode='a', maxBytes=int(config.log_file_max_bytes), backupCount=int(config.log_file_backup_count)) else: file_handler = RotatingFileHandler( log_file, mode='a', maxBytes=log_file_max_bytes, backupCount=log_file_backup_count) file_handler.setFormatter(formatter) logger.addHandler(file_handler) except PermissionError as err: exit("{} Please consider to run as root or sudo".format(err)) # set log level in order: 1. user argument 2. config file 3. @click default if log is not None: logger.setLevel(log) elif 'log_level' in config.__dict__: logger.setLevel(config.log_level) else: # this is the fallback default log-level. logger.setLevel('INFO') validate_file(defaults_file) pid_file = pid.PidFile(piddir=config.pid_dir) try: with pid_file: # User PidFile for locking to single instance if (prepare is False and backup is False and partial is False and verbose is False and dry_run is False and test_mode is False and show_tags is False): print_help(ctx, None, value=True) elif show_tags and defaults_file: b = Backup(config=defaults_file) b.show_tags(backup_dir=b.backupdir) elif test_mode and defaults_file: logger.warning("Enabled Test Mode!!!") logger.info("Starting Test Mode") test_obj = RunnerTestMode(config=defaults_file) for basedir in test_obj.basedirs: if ('5.7' in basedir) and ('2_4_ps_5_7' in defaults_file): if keyring_vault == 1: test_obj.wipe_backup_prepare_copyback( basedir=basedir, keyring_vault=1) else: test_obj.wipe_backup_prepare_copyback( basedir=basedir) elif ('8.0' in basedir) and ('8_0_ps_8_0' in defaults_file): if keyring_vault == 1: test_obj.wipe_backup_prepare_copyback( basedir=basedir, keyring_vault=1) else: test_obj.wipe_backup_prepare_copyback( basedir=basedir) elif ('5.6' in basedir) and ('2_4_ps_5_6' in defaults_file): test_obj.wipe_backup_prepare_copyback(basedir=basedir) elif ('5.6' in basedir) and ('2_3_ps_5_6' in defaults_file): test_obj.wipe_backup_prepare_copyback(basedir=basedir) elif ('5.5' in basedir) and ('2_3_ps_5_5' in defaults_file): test_obj.wipe_backup_prepare_copyback(basedir=basedir) elif ('5.5' in basedir) and ('2_4_ps_5_5' in defaults_file): test_obj.wipe_backup_prepare_copyback(basedir=basedir) else: logger.error( "Please pass proper already generated config file!" ) logger.error( "Please check also if you have run prepare_env.bats file" ) elif prepare and not test_mode: if not dry_run: if tag: a = Prepare(config=defaults_file, tag=tag) a.prepare_backup_and_copy_back() else: a = Prepare(config=defaults_file) a.prepare_backup_and_copy_back() else: logger.warning("Dry run enabled!") logger.warning("Do not recover/copy-back in this mode!") if tag: a = Prepare(config=defaults_file, dry_run=1, tag=tag) a.prepare_backup_and_copy_back() else: a = Prepare(config=defaults_file, dry_run=1) a.prepare_backup_and_copy_back() elif backup and not test_mode: if not dry_run: if tag: b = Backup(config=defaults_file, tag=tag) b.all_backup() else: b = Backup(config=defaults_file) b.all_backup() else: logger.warning("Dry run enabled!") if tag: b = Backup(config=defaults_file, dry_run=1, tag=tag) b.all_backup() else: b = Backup(config=defaults_file, dry_run=1) b.all_backup() elif partial: if not dry_run: c = PartialRecovery(config=defaults_file) c.final_actions() else: logger.critical( "Dry run is not implemented for partial recovery!") except pid.PidFileAlreadyLockedError as error: if hasattr(config, 'pid_runtime_warning'): if time.time() - os.stat( pid_file.filename).st_ctime > config.pid_runtime_warning: pid.fh.seek(0) pid_str = pid.fh.read(16).split("\n", 1)[0].strip() logger.critical("Backup (pid: " + pid_str + ") has been running for logger than: " + str( humanfriendly.format_timespan( config.pid_runtime_warning))) # logger.warn("Pid file already exists: " + str(error)) except pid.PidFileAlreadyRunningError as error: if hasattr(config, 'pid_runtime_warning'): if time.time() - os.stat( pid_file.filename).st_ctime > config.pid_runtime_warning: pid.fh.seek(0) pid_str = pid.fh.read(16).split("\n", 1)[0].strip() logger.critical("Backup (pid: " + pid_str + ") has been running for logger than: " + str( humanfriendly.format_timespan( config.pid_runtime_warning))) # logger.warn("Pid already running: " + str(error)) except pid.PidFileUnreadableError as error: logger.warning("Pid file can not be read: " + str(error)) except pid.PidFileError as error: logger.warning("Generic error with pid file: " + str(error)) logger.info("Xtrabackup command history:") for i in ProcessRunner.xtrabackup_history_log: logger.info(str(i)) logger.info("Autoxtrabackup completed successfully!") return True
def test_run_copy_back(self): gen_obj = GeneralClass() for conf_files in gen_obj.xb_configs.split(): obj = WrapperForPrepareTest( config='{}/{}'.format(gen_obj.testpath, conf_files)) obj.run_copy_back()
def all_procedure(ctx, prepare, backup, partial, tag, show_tags, verbose, log_file, log, defaults_file, dry_run, test_mode, log_file_max_bytes, log_file_backup_count, keyring_vault): logger.setLevel(log) formatter = logging.Formatter(fmt='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S') if verbose: ch = logging.StreamHandler() ch.setFormatter(formatter) logger.addHandler(ch) if log_file: try: file_handler = RotatingFileHandler(log_file, mode='a', maxBytes=log_file_max_bytes, backupCount=log_file_backup_count) file_handler.setFormatter(formatter) logger.addHandler(file_handler) except PermissionError as err: exit("{} Please consider to run as root or sudo".format(err)) validate_file(defaults_file) config = GeneralClass(defaults_file) pid_file = pid.PidFile(piddir=config.pid_dir) try: with pid_file: # User PidFile for locking to single instance if (prepare is False and backup is False and partial is False and verbose is False and dry_run is False and test_mode is False and show_tags is False): print_help(ctx, None, value=True) elif show_tags and defaults_file: b = Backup(config=defaults_file) b.show_tags(backup_dir=b.backupdir) elif test_mode and defaults_file: # TODO: do staff here to implement all in one things for running test mode logger.warning("Enabled Test Mode!!!") logger.debug("Starting Test Mode") test_obj = RunnerTestMode(config=defaults_file) for basedir in test_obj.basedirs: if ('5.7' in basedir) and ('2_4_ps_5_7' in defaults_file): if keyring_vault == 1: test_obj.wipe_backup_prepare_copyback(basedir=basedir, keyring_vault=1) else: test_obj.wipe_backup_prepare_copyback(basedir=basedir) elif ('5.6' in basedir) and ('2_4_ps_5_6' in defaults_file): test_obj.wipe_backup_prepare_copyback(basedir=basedir) elif ('5.6' in basedir) and ('2_3_ps_5_6' in defaults_file): test_obj.wipe_backup_prepare_copyback(basedir=basedir) elif ('5.5' in basedir) and ('2_3_ps_5_5' in defaults_file): test_obj.wipe_backup_prepare_copyback(basedir=basedir) elif ('5.5' in basedir) and ('2_4_ps_5_5' in defaults_file): test_obj.wipe_backup_prepare_copyback(basedir=basedir) else: logger.error("Please pass proper already generated config file!") logger.error("Please check also if you have run prepare_env.bats file") elif prepare and not test_mode: if not dry_run: if tag: a = Prepare(config=defaults_file, tag=tag) a.prepare_backup_and_copy_back() else: a = Prepare(config=defaults_file) a.prepare_backup_and_copy_back() else: logger.warning("Dry run enabled!") logger.warning("Do not recover/copy-back in this mode!") if tag: a = Prepare(config=defaults_file, dry_run=1, tag=tag) a.prepare_backup_and_copy_back() else: a = Prepare(config=defaults_file, dry_run=1) a.prepare_backup_and_copy_back() elif backup and not test_mode: if not dry_run: if tag: b = Backup(config=defaults_file, tag=tag) b.all_backup() else: b = Backup(config=defaults_file) b.all_backup() else: logger.warning("Dry run enabled!") if tag: b = Backup(config=defaults_file, dry_run=1, tag=tag) b.all_backup() else: b = Backup(config=defaults_file, dry_run=1) b.all_backup() elif partial: if not dry_run: c = PartialRecovery(config=defaults_file) c.final_actions() else: logger.critical("Dry run is not implemented for partial recovery!") except pid.PidFileAlreadyLockedError as error: if hasattr(config, 'pid_runtime_warning'): if time.time() - os.stat(pid_file.filename).st_ctime > config.pid_runtime_warning: pid.fh.seek(0) pid_str = pid.fh.read(16).split("\n", 1)[0].strip() logger.critical( "Backup (pid: " + pid_str + ") has been running for logger than: " + str( humanfriendly.format_timespan( config.pid_runtime_warning))) # logger.warn("Pid file already exists: " + str(error)) except pid.PidFileAlreadyRunningError as error: if hasattr(config, 'pid_runtime_warning'): if time.time() - os.stat(pid_file.filename).st_ctime > config.pid_runtime_warning: pid.fh.seek(0) pid_str = pid.fh.read(16).split("\n", 1)[0].strip() logger.critical( "Backup (pid: " + pid_str + ") has been running for logger than: " + str( humanfriendly.format_timespan( config.pid_runtime_warning))) # logger.warn("Pid already running: " + str(error)) except pid.PidFileUnreadableError as error: logger.warning("Pid file can not be read: " + str(error)) except pid.PidFileError as error: logger.warning("Generic error with pid file: " + str(error))
def __init__(self, config="/etc/bck.conf"): self.conf = config self.testpath = GeneralClass(self.conf).testpath self.basedir = CloneBuildStartServer(self.conf).get_basedir()