MySQL备份工具mydumper备份(3)


    # 从配置文件读取 ip, 名称, 端口, 并拼凑备份语句
    #f = open('/data2/backup/cnf/other_list.cnf', 'r')
    f = open('/data/other_list.cnf', 'r')
    for lines in f.readlines():
        if (not lines.startswith('#') and len(lines.strip()) > 0):
            str = lines.split()
            host, businessName, port, isMaster = str[0], str[1], str[2], str[3]
            # 业务文件夹不存在则创建
            dir = baseDir + '/' + businessName;
            if (not os.path.exists(dir)):
                os.makedirs(dir)


            dir += "/%s%s" % (businessName, backup_date)
            # 业务目录: dir , 备份目录: dir/name+备份日期
            strcmd  = cmd % (host, port, zip, dir)


            th = threading.Thread(target = mydumper, args =(strcmd, dir, businessName, host, port, is_errRetryBackup, int(isMaster)))
            thread_pool.append(th)


    if (thread_pool):
        for t in thread_pool:
            t.daemon = True
            t.start()
        for t in thread_pool:
            t.join()


def mydumper(sCmd, backupDir, businessName, host, port, is_Retry, isMaster):
    master_host = ""; backup_host = host; name = businessName; port = port; backup_type = 1; file = "";
    start_time = ""; stop_time = ""; returncode = 0; file_size = 0; slave_statement = ""; std_err = "";


    start_time = time.strftime("%Y%m%d%H%M%S")


    # 清除可能遗留的备份
    if (os.path.exists(backupDir)):
        shutil.rmtree(backupDir)


    # 执行备份
    returncode, std_err = execute(sCmd)


    stop_time = time.strftime("%Y%m%d%H%M%S")

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a7be4259ac917cee0291a58e54b38052.html