bsp; value =line.split("=")[1].strip()
return value
def stop_mysql_service():
print("################stop mysql service###################")
print("systemctl stop {}".format(instance_name))
def start_mysql_service():
print("################stop mysql service###################")
print("systemctl start {0}".format(instance_name))
#返回备份日志中的最新的一个早于stop_at时间的完整备份,以及其后面的增量备份
def get_restorefile_list():
list_backup = []
list_restore_file = []
if os.path.exists(backupfilelist):
with open(backupfilelist, 'r') as f:
lines = f.readlines()
for line in lines:
list_backup.append(line.replace("\n",""))
if (list_backup):
for i in range(len(list_backup) - 1, -1, -1):
list_restore_file.append(list_backup[i])
backup_name = list_backup[i].split("|")[2]
if "full" in backup_name:
full_backup_time = list_backup[i].split("|")[1]
if(stop_at<full_backup_time):
break
else:
list_restore_file = None
#restore file in the list_restore_log
list_restore_file.reverse()
return list_restore_file
#解压缩需要还原的备份文件,包括一个完整备份以及N个增量备份(N>=0)
def uncompress_backup_file():
print("################uncompress backup file###################")
list_restore_backup = get_restorefile_list()
#如果没有生成时间早于stop_at的完整备份,无法恢复,退出
if not list_restore_backup:
raise("There is no backup that can be restored")
exit(1)
for restore_log in list_restore_backup:
#解压备份文件
backup_name = restore_log.split("|")[2]
backup_path = restore_log.split("|")[2]
backup_full_name = os.path.join(backup_dir,backup_path,backup_name)
backup_path = os.path.join(backup_dir,restore_log.split("|")[-1])
#print('''[ ! -d {0} ] && mkdir -p {0}'''.format(os.path.join(dest_dir,backup_name)))
os.system('''[ ! -d {0} ] && mkdir -p {0}'''.format(os.path.join(dest_dir,backup_name)))
#print("xbstream -x < {0}.xbstream -C {1}".format(backup_full_name,os.path.join(dest_dir,backup_name)))
os.system("xbstream -x < {0}.xbstream -C {1}".format(backup_full_name,os.path.join(dest_dir,b