Logrotate

From 탱이의 잡동사니
Jump to navigation Jump to search

Overview

Linux logrotate 내용 정리

About

Logrotate 는 로그를 관리하는 유틸리티이다. 기본적으로 <source lang=bash> $ ls -l /etc/cron.daily/logrotate -rwxr-xr-x 1 root root 372 Jan 22 2014 /etc/cron.daily/logrotate </source>

conf options

  • daily
로그를 일 단위로 백업한다.
  • weekly
로그를 주 단위로 백업한다. 마지막 백업을 실행한 실행할 날로 일주일이 넘었을 경우 백업을 한다.
  • monthly
로그를 월 단위로 백업한다. 보통은 달의 첫날에 백업을 한다.
  • rotate <count>
백업된 로그 파일을 몇개까지 보관할 것인지 결정한다. 설정된 갯수 이상의 로그 백업이 있을 경우, 오래된 것부터 삭제한다.
  • missingok
만약 해당 로그파일이 없더라도 별도의 에러 메시지 없이 그냥 넘어간다.
  • nomissingok
만약 해당 로그파일이 없다면 에러 메시지를 표시한다. (기본설정)
  • create <mode> <owner> <group>, create <onwer> <group>
백업파일을 생성한 후, 설정한 <mode>, <owner>, <group> 으로 변경한다. 만약 nocreate 옵션이 설정되어 있다면 적용되지 않는다.
  • compress
백업 파일 생성 후, gzip 으로 압축한다.
  • sharedscripts
...

Sample

mysql-server logrotate sample

$ cat /etc/logrotate.d/mysql-server

# - I put everything in one block and added sharedscripts, so that mysql gets 
#   flush-logs'd only once.
#   Else the binary logs would automatically increase by n times every day.
# - The error log is obsolete, messages go to syslog now.
/var/log/mysql.log /var/log/mysql/*log {
        daily
        rotate 7
        missingok
        create 640 mysql adm
        compress
        sharedscripts
        postrotate
                test -x /usr/bin/mysqladmin || exit 0
                # If this fails, check debian.conf! 
                MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
                if [ -z "`$MYADMIN ping 2>/dev/null`" ]; then
                  # Really no mysqld or rather a missing debian-sys-maint user?
                  # If this occurs and is not a error please report a bug.
                  #if ps cax | grep -q mysqld; then
                  if killall -q -s0 -umysql mysqld; then
                    exit 1
                  fi
                else
                  $MYADMIN flush-logs
                fi
        endscript
}