滚动备份日志
import time
import os
from datetime import datetime
def formatSize(bytes):
try:
bytes = float(bytes)
kb = bytes / 1024
except:
print("传入的字节格式不对")
return "Error"
return kb
def check(path, cnt):
try:
size = os.path.getsize(path)
kb_size = formatSize(size)
if kb_size > 50*1024:
os.system('cp ' + path + ' ' + path.split('.')[0] + "_history_" + str(cnt) +'.txt' )
print "Copy at " + time.strftime("%Y %m %d %H:%M:%S", time.localtime())
os.system('rm ' + path):
return
except Exception as err:
print(err)
pass
if __name__ == '__main__':
cnt = 1
while True:
path = "filepath"
check(path, cnt)
time.sleep(60*30)
cnt += 1