diff options
author | Michael Biebl <biebl@debian.org> | 2008-11-20 13:30:15 +0100 |
---|---|---|
committer | Michael Biebl <biebl@debian.org> | 2008-11-20 13:30:15 +0100 |
commit | 6881502bbb8d33b6c5e41c6d109f8c6968d27bd6 (patch) | |
tree | 4f350b2a6dc6386b8ba2d766bf4f70056e0bc4f4 /debian/rsyslog.postinst | |
parent | 6b2c976d7dde9f8bca24a755a2f324207724e51e (diff) | |
download | rsyslog-6881502bbb8d33b6c5e41c6d109f8c6968d27bd6.tar.gz |
Rotate old .0 log files when migrating from sysklogd. Closes: #491672
Diffstat (limited to 'debian/rsyslog.postinst')
-rw-r--r-- | debian/rsyslog.postinst | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/debian/rsyslog.postinst b/debian/rsyslog.postinst index 1df6726..8d93582 100644 --- a/debian/rsyslog.postinst +++ b/debian/rsyslog.postinst @@ -14,8 +14,50 @@ set -e # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package +rotate_old_log_files() +{ + log_files="syslog mail.info mail.warn mail.err mail.log daemon.log \ + kern.log auth.log user.log lpr.log cron.log debug messages" + skipped_files="" + dir=/var/log + + for f in $log_files; do + if [ -e $dir/$f.0 ]; then + rotate="yes" + if [ -e $dir/$f.1.gz ]; then + date0=$(stat --format=%Y $dir/$f.0) + date1=$(stat --format=%Y $dir/$f.1.gz) + if [ $date0 -lt $date1 ] ; then + # .0 log file is older than .1 + skipped_files="$dir/$f.0\n$skipped_files" + rotate="no" + fi + fi + if [ "$rotate" = "yes" ] ; then + for s in $(seq 9 -1 1) ; do + if [ -e $dir/$f.$s.gz ]; then + mv $dir/$f.$s.gz $dir/$f.$((s+1)).gz + fi + done + mv $dir/$f.0 $dir/$f.1 + fi + fi + done + if [ -n "$skipped_files" ]; then + printf "The following old log files were found which could not be rotated safely.\n" + printf "\n$skipped_files\n" + printf "Please inspect them manually and delete them, if no longer required.\n" + fi +} + + case "$1" in configure) + # Rotate .0 log files when migrating from sysklogd + if dpkg --compare-versions "$2" lt "3.18.5-1"; then + rotate_old_log_files + fi + # Stop the service on upgrades before it is started again. # dh_installinit -r will create the start code. if [ -n "$2" ]; then |