I have a folder with log-files each ~10 minutes:
alfred_140810-190001.json
alfred_140810-191001.json
alfred_140810-192002.json
alfred_140810-193001.json
alfred_140810-194001.json
alfred_140810-195001.json
alfred_140810-200002.json
alfred_140810-201119.json
alfred_140810-202002.json
...
How do I achieve this?
- delete all files older than a week but keep one per week
- delete all files older than a month but keep one per month
- delete all files older than a year but keep one per year
So I want one file for the last four weeks (4 files) one file per month (12 Files) and one per year (the same system like rsnapshot
is sorting his backups).
Best Answer
You want logrotate http://linuxcommand.org/man_pages/logrotate8.html.
It is probably already on your system. You just need to configure it. However it is mainly for the purpose of purging old log files and I don't know if you can configure it to keep one file.
What you can do
create several directories
log
,log.weekly
,log.monthly
, andlog.yearly
log
being where all the log files go. Createlog
tolog.weekly
,log
tolog.monthly
, andlog
tolog.yearly
.Then configure logrotate appropriately for the different directories.