We have rsyslog that save logs based on requirement to various directories:
/opt/logs/stats/dc1/stats_YYYY-MM-DD_%somename%.log
/opt/logs/stats/dc2/stats_YYYY-MM-DD_%somename%.log
/opt/logs/events/dc1/events_YYYY-MM-DD_%somename%.log
/opt/logs/events/dc2/events_YYYY-MM-DD_%somename%.log
/opt/logs/security/dc1/security_YYYY-MM-DD_%somename%.log
/opt/logs/security/dc2/security_YYYY-MM-DD_%somename%.log
How to archive these logs weekly ?
I would like them compressed and moved to a different folder:
/mnt/logs_archive/stats/dc1/stats_<YYYY-MM-DD>.tar.gz
/mnt/logs_archive/events/dc1/events_<YYYY-MM-DD>.tar.gz
/mnt/logs_archive/security/dc1/security_<YYYY-MM-DD>.tar.gz
/mnt/logs_archive/stats/dc2/stats_<YYYY-MM-DD>.tar.gz
/mnt/logs_archive/events/dc2/events_<YYYY-MM-DD>.tar.gz
/mnt/logs_archive/security/dc2/security_<YYYY-MM-DD>.tar.gz
Where YYYY-MM-DD is the date of the move that way we know that it shall include last 7 days of logs from the date.
Question:
- Is there a way to achieve this in a single/simple config
- Will I have to create a new one for log path?
- For Certain folders (security events) we are not interested in archiving logs for more than 120 days. can this be achieved too?
My current copy:
copytruncate
compress
dateformat _%Y-%m-%d.
dateext
extension log
olddir /mnt/archive_logs/
/opt/logs/stats/gw_stats*.log {
rotate 48
hourly
}
This gives me multiple compressed files
ll /mnt/archive_logs/
stats_YYYY-MM-DD_f2._2021-04-02.log.gz
stats_YYYY-MM-DD_asdas3._2021-04-02.log.gz
can I merge this into one stats_YYYY-MM-DD.gz ?
Also how do i use tar.gz ?