欢迎吐槽!
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os,time,shutil
path = os.getcwd()
target_dir = []
cal = []
target_dir.append('/var/lib/mysql/log/')
target_dir.append('/newlogs/')
target_dir.append('/oldlogs/')
#初始化删除文件名
del_ext = ['frm','MYD','MYI']
#你要保留几天
days_before = 5
#初始化删除日期
for x in xrange(days_before+1,days_before+30):
cal.append(time.strftime('%Y_%m_%d',time.localtime(time.time() - x*24*3600)))
#初始化删除文件名,使用笛卡尔积!
fl = map('.'.join, [[x,y] for x in cal for y in del_ext])
#以日期命名的文件夹
cal = []
for x in xrange(days_before+1,days_before+30):
cal.append(time.strftime('%Y-%m-%d',time.localtime(time.time() - x*24*3600)))
fl += cal
#获取文件扩展名
def get_ext(filename):
return filename....