# 从配置文件读取 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")