Logfilemanagement with Logrotate (Ubuntu)
This article has not been completed yet. However, it may already contain helpful information and therefore it has been published at this stage.
# Verify that logrotate is installed
logrotate --version
# Check Loglocations, that have to be rotated
ls /var/log/remotelogs/
# Create a new Logrotate-Configuration File
sudo nano /etc/logrotate.d/rsyslog-remote
/var/log/remotelogs/**/*.log {
daily
su root adm
maxsize 30G
missingok
create
rotate 1
compress
sharedscripts
prerotate
invoke-rc.d rsyslog stop > /dev/null
endscript
postrotate
invoke-rc.d rsyslog start > /dev/null
endscript
}
/var/log/remotelogs/**/
: these two stars will match zero or more (sub-) directories/*.log
: all files, that ends with ".log", will be processeddaily
: daily rotation. This overrides theweekly
defaultsu root adm
: use the adm group to execute the rotationmaxsize
: once this file size has been reached, the rotation is initiatedmissingok
: don’t write an error message if the log file is missingcreate
: this creates a new empty log file after rotationrotate 1
: keep one old log files. This overrides therotate 4
defaultcompress
: compress the rotated files. this usesgzip
by default and results in files ending in.gz
sharedscripts
: the prerotate or postrotate script are only executet for one timeprerotate
: executed before the log file is rotatedendscript
: this marks the end of the script areapostrotate
: executed after the log file is rotatedendscript
: this marks the end of the script area
# Run Default Logrotate-Config
sudo logrotate /etc/logrotate.conf
# Run Default Logrotate-Config in Debug Mode (without any changes)
sudo logrotate /etc/logrotate.conf --debug
# Run Default Logrotate-Config in Verbose Mode (files, where no adjustment are necessary are skipped)
sudo logrotate /etc/logrotate.conf --verbose
# Run Default Logrotate-Config in Verbose \ Enforced Mode (all files are processed)
sudo logrotate /etc/logrotate.conf --verbose --force
References:
How To Manage Logfiles with Logrotate on Ubuntu 20.04 | DigitalOcean
Logrotate is a system utility that manages the automatic rotation and compression of log files. If log files were not rotated, compressed, and periodically pruned, they would eventually consume all available disk space on a system. In this article, we will explore the default Logrotate configuration…
logrotating files in a directories and its subdirectories
Is it possible to get logrotate to consider logfiles in a directory and all its subdirectories? (i.e. without explicitly listing the subdirectories.)
logrotate(8) - Linux man page
logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and ...