Esempio n. 1
0
def is_success_mysql_xtrabackup(extra_keys, str_auth, backup_full_path, gzip, job_name):
    date_now = general_function.get_time_now('backup')
    tmp_status_file = f'/tmp/xtrabackup_status/{date_now}.log'

    dom = int(general_function.get_time_now('dom'))
    if dom == 1:
        dir_for_status_file = os.path.dirname(tmp_status_file)
        if os.path.isdir(dir_for_status_file):
            listing = glob.glob(dir_for_status_file)
            periodic_backup.delete_oldest_files(listing, 31, job_name)

    general_function.create_files(job_name, tmp_status_file)

    if gzip:
        dump_cmd = f"innobackupex {str_auth} {extra_keys} 2>{tmp_status_file} | gzip > {backup_full_path}"
    else:
        dump_cmd = f"innobackupex {str_auth} {extra_keys} > {backup_full_path} 2>{tmp_status_file} "

    command = general_function.exec_cmd(dump_cmd)
    code = command['code']

    if not is_success_status_xtrabackup(tmp_status_file, job_name):
        log_and_mail.writelog(
            'ERROR', f"Can't create xtrabackup in tmp directory! More information in status file {tmp_status_file}.",
            config.filelog_fd, job_name)
        return False
    elif code != 0:
        log_and_mail.writelog('ERROR', f"Bad result code external process '{dump_cmd}':'{code}'",
                              config.filelog_fd, job_name)
        return False
    else:
        log_and_mail.writelog('INFO', "Successfully created xtrabackup in tmp directory.",
                              config.filelog_fd, job_name)
        return True
def is_success_mysql_xtrabackup(extra_keys, str_auth, backup_full_path, gzip,
                                job_name):

    date_now = general_function.get_time_now('backup')
    tmp_status_file = '/tmp/xtrabackup_status/%s.log' % (date_now)

    dom = int(general_function.get_time_now('dom'))
    if dom == 1:
        dir_for_status_file = os.path.dirname(tmp_status_file)
        if os.path.isdir(dir_for_status_file):
            listing = glob.glob(dir_for_status_file)
            periodic_backup.delete_oldest_files(listing, 31, job_name)

    general_function.create_files(job_name, tmp_status_file)

    if gzip:
        dump_cmd = "innobackupex %s %s 2>%s | gzip > %s" % (
            str_auth, extra_keys, tmp_status_file, backup_full_path)
    else:
        dump_cmd = "innobackupex %s %s > %s 2>%s " % (
            str_auth, extra_keys, backup_full_path, tmp_status_file)

    command = general_function.exec_cmd(dump_cmd)
    code = command['code']

    if code != 0:
        log_and_mail.writelog(
            'ERROR',
            "Bad result code external process '%s':'%s'" % (dump_cmd, code),
            config.filelog_fd, job_name)
        return False

    if not is_success_status_xtrabackup(tmp_status_file, job_name):
        log_and_mail.writelog(
            'ERROR',
            "Can't create xtrabackup in tmp directory! More information in status file %s."
            % (tmp_status_file), config.filelog_fd, job_name)
        return False
    elif code != 0:
        log_and_mail.writelog(
            'ERROR',
            "Bad result code external process '%s':'%s'" % (dump_cmd, code),
            config.filelog_fd, job_name)
        return False
    else:
        log_and_mail.writelog(
            'INFO', "Successfully created xtrabackup in tmp directory.",
            config.filelog_fd, job_name)
        return True