Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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>​
  

QR Code
QR Code tech:linux:rotate_logs (generated for current page)