home_server:home_server_setup:other_services:logrotate

Differences

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

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
home_server:home_server_setup:other_services:logrotate [2022-09-05 Mon wk36 15:39] – created baumkphome_server:home_server_setup:other_services:logrotate [2023-04-30 Sun wk17 17:43] – external edit 127.0.0.1
Line 1: Line 1:
 +{{tag>linux debian log rotate logrotate cron crontab}}
 +======logrotate======
 +There are a number of ways to rotate logs.
 +  -Using a script and cron (or systemd.timer)
 +  -Using ''logrotate''
 +
 +====Logrotate using script====
 +
 +edit the sudo crontab ''sudo crontab -e'':
 +<code>
 +Example of job definition:
 +# .---------------- minute (0 - 59)
 +# |  .------------- hour (0 - 23)
 +# |  |  .---------- day of month (1 - 31)
 +# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
 +# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat,sun
 +# |  |  |  |  |
 +# *  *  *  *  *   user-name command to be executed
 +# 0  0  1  *  * /home/shared/Myscripts/rotatelog.sh /var/log/UPS/UPSLog.Log #Rotate NUT UPS log file
 +</code>
 +
 +where ''/home/shared/Myscripts/rotatelog.sh'' is:
 +<code>#!/bin/bash
 +logfile=$1
 +if [ ! -f $logfile ]; then
 +  echo "log file not found $logfile"
 +  exit 1
 +fi
 +timestamp=`date +%Y%m%d`
 +newlogfile=$logfile.$timestamp
 +cp $logfile $newlogfile
 +cat /dev/null > $logfile
 +gzip -f -9 $newlogfile
 +</code>
 +Remember to make executable (''sudo chmod +x /home/shared/Myscripts/rotatelog.sh'')
 +
 +====logrotate====
 +  -Install logrotate
 +    - debian: ''sudo apt install logrotate''
 +    - Arch: ''sudo pacman -S logrotate''
 +  *The main logrotate configuration file is here: ''/etc/logrotate.conf''
 +  *
 +
 +====Links====
 +[[https://www.linuxshelltips.com/rotate-logs-with-logrotate-linux/|How to Rotate Logs With Logrotate in Linux]]
 +
  
 <- home_server:home_server_setup:other_services:samba|Prev ^ home_server:home_server_setup:other_services:index|Start page ^ home_server:home_server_setup:other_services:misc|Next -> <- home_server:home_server_setup:other_services:samba|Prev ^ home_server:home_server_setup:other_services:index|Start page ^ home_server:home_server_setup:other_services:misc|Next ->
  • /app/www/public/data/pages/home_server/home_server_setup/other_services/logrotate.txt
  • Last modified: 2023-12-26 Tue wk52 11:30
  • by baumkp