-
Notifications
You must be signed in to change notification settings - Fork 0
/
logrot
executable file
·46 lines (41 loc) · 1.33 KB
/
logrot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
""" Move big or overtimed logs to backup """
import os
import logging
import argparse
import yaml
from tplogtools.timetools import local_tz_now
from tplogtools.logrotlib import process_path, run_compressors
def main():
"""Argument parse and main loop over given paths"""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-c', '--conf', required=True, help='Path to config yml file')
parser_interval = parser.add_mutually_exclusive_group()
parser_interval.add_argument(
'--hourly',
action='store_true',
help='Use rules configured as "hourly"'
)
parser_interval.add_argument(
'--daily',
action='store_true',
help='Use rules configured as "daily"'
)
parser.add_argument(
'path',
nargs='+',
help='Path to folder with log'
)
args = parser.parse_args()
with open(args.conf) as conf_file:
conf = yaml.safe_load(conf_file)
interval = 'daily' if args.daily else 'hourly' if args.hourly else ''
compressors = []
now = local_tz_now()
for path in args.path:
compressors += process_path(now, conf, interval, os.path.abspath(path))
if compressors:
run_compressors(compressors)
if __name__ == '__main__':
logging.basicConfig(level=logging.ERROR)
main()