使用python3.8+定时任务来实现备份
# -*- coding: UTF-8 -*-
import os
import re
import shutil
import time
res = os.listdir("D:")
pattern = re.compile("^[M, m]irserver.*")
mir_list = {}
backuptime = time.strftime("%Y-%m-%d_%H_%M_%S")
for mydir in res:
mir_str = pattern.search(mydir)
if mir_str and os.path.isdir("d:/" + mir_str.group()):
mir_list[mydir] = "d:/" + mir_str.group()+"/mir200/"+"GlobalVal.ini"
for mir_dir, global_file in mir_list.items():
dst_dir = "E:/backup/GlobalVal/" + mir_dir
if not os.path.isdir(dst_dir):
os.makedirs(dst_dir)
if os.path.isfile(global_file):
shutil.copy(global_file, dst_dir+"/GlobalVal_" + backuptime + ".ini")