2007年5月21日 星期一

log 檔案rotate 備份

Blog主機

/var/log 下的httpd-access.log 檔案太大 讓 /var 爆掉

將 /var/log  移到 /home/下

# cd /var

# mv /var/log  /home/



再做 ln

#ln -s /home/log  log

然後安裝 logrotate

#cd /usr/ports/sysutils/logrotate

#make install

執行檔在/usr/local/sbin/logrotate

1.在/usr/local/etc/下編輯  logrotate.conf檔內容為

errors root

compress

/var/log/httpd-access.log {

copytruncate

create 644 root wheel

weekly

rotate 7

uncompress

size=10000k }

/var/log/httpd-access.log {......}

{..}之外的為預設值..{.....}之內的為指定的值

size=10000k 表示超過10000k才會執行

在 /var/lib/logrotate/下  執行

#logrotate -s /var/lib/logrotate.status /usr/local/etc/logrotate.conf

會在 /var/lib/logrotate 下建立一個 logrotate.status檔案

2.定時啟動

#cd /etc/periodic/daily

#ee 101.logrotate

內容為

/usr/local/sbin/logrotate /usr/local/etc/logrotate.conf

#chmod +x 101.logrotate

開機後會定時執行