Differences
This shows you the differences between two versions of the page.
tech:linux:rotate_logs [2015/08/03 06:46] |
tech:linux:rotate_logs [2015/08/03 06:46] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Log Rotation script ====== | ||
+ | Short of using logrotate, below is a quick and simple script to do the same. | ||
+ | |||
+ | ===== Script ===== | ||
+ | Example of haproxy log rotation | ||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | # | ||
+ | LOGDIR=/var/log | ||
+ | LOGFILE=haproxy.log | ||
+ | TARDIR=/data/log | ||
+ | # | ||
+ | LOGDIRFILE=${LOGDIR}/${LOGFILE} | ||
+ | cp $LOGDIRFILE ${TARDIR}/${LOGFILE}.`date +%Y%m%d_%H%M%S` | ||
+ | cat /dev/null > $LOGDIRFILE | ||
+ | exit | ||
+ | </code> | ||
+ | |||
+ | ===== crontab entry ===== | ||
+ | Include this /etc/crontab | ||
+ | <code> | ||
+ | 00 00 * * * root /var/log/logroll | ||
+ | </code> | ||