$ rpm -qa | grep logrotate
logrotate-3.8.6-15.amzn2.x86_64
$ sudo vi /etc/logrotate.d/postgres
/data/postgres/data/log/postgresql.log{
daily
maxage 31
missingok
dateext
compress
delaycompress
copytruncate
}
$ sudo logrotate -d /etc/logrotate.d/postgres
reading config file /etc/logrotate.d/postgres
Allocating hash table for state file, size 15360 B
Handling 1 logs
rotating pattern: /data/postgres/data/log/*.log after 1 days (no old logs will be kept)
empty log files are rotated, old logs are removed
considering log /data/postgres/data/log/*.log
log /data/log/*.log does not exist -- skipping
$ sudo logrotate -fv /etc/logrotate.d/mongodb
$ sudo mkdir /data/script
$ sudo mv /etc/cron.daily/logrotate /data/script/logrotate.sh
$ sudo su
$ crontab -e
0 0 * * * /data/script/logrotate.sh
# crond 서비스 재부팅
$ systemctl restart crond
$ sudo vi /root/script/log_managed.sh
#!/bin/bash
# log dir 압축파일을 /data/postgres/data/log/old 디렉터리로 옮기는 명령
mv /data/postgres/data/log/postgresql.log-*.gz /data/postgres/data/log/old/
# ../old dir 폴더에 30일 이상 지난 파일을 삭제하는 명령
find /data/postgres/data/log/old/ -mindepth 1 -maxdepth 1 -mtime +30 -type f -exec rm -rf {} \;
$ sudo su
$ crontab -e
0 6 * * * /root/script/log_managed.sh