Log备份日志
滚动备份日志#encoding:utf-8#usr/bin/ pythonimport timeimport osfrom datetime import datetime# 字节bytes转化kbdef formatSize(bytes):try:bytes = float(bytes)kb = bytes / 1024except
·
滚动备份日志
#encoding:utf-8
#usr/bin/ python
import time
import os
from datetime import datetime
# 字节bytes转化kb
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
更多推荐
已为社区贡献1条内容
所有评论(0)