#!/usr/bin/env pthon#_*_coding=utf-8_*_#python version (Nginx log cut script) import osimport datetime# Access.log path accesslogs_path = "/usr/local/nginx/logs/" #昨天的日期lastDate = datetime.date.today () - datetime.timedelta (Days=1) #备份路径bak_path = "%s%s/%s/" % (Accesslogs_path, Lastdate.strftime ('%Y '), Lastdate.strftime ('%m ')) #nginx日志access_log = "%saccess.log" % ( Accesslogs_path) #备份后日志bak_log = "%s%s.log" % (bak_path,lastdate.strftime ('%y%m%d ')) def bakup (): if os.path.exists (Bak_path): print "Backup directory already exists. The " else: print " backup directory does not exist. " print " Create backup directory ... " os.makedirs (Bak_path) print "Start Backup Nginx log ..." Os.rename (Access_Log,bak_log) os.system (' kill -usr1 ' cat /usr/local/nginx/logs/nginx.pid ' ') if __name__ == ' __main__ ': bakup ()
This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1655182
The Nginx cut log script written by Python