Created
December 8, 2013 13:05
-
-
Save hideshi/7857158 to your computer and use it in GitHub Desktop.
Log rotation script.
This script would be called by cron at fixed intervals.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os.path import getsize | |
from os import rename | |
from datetime import datetime | |
srcnames = ['./logfile1', './logfile2'] | |
kb = 1024 | |
mb = kb * 1024 | |
def log_rotate(): | |
for srcname in srcnames: | |
size = getsize(srcname) | |
if size > 10 * mb : | |
dstname = srcname + "." + datetime.now().strftime('%Y%m%d%H%M%S') | |
rename(srcname, dstname) | |
if __name__ == '__main__': | |
log_rotate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment