1

I have logrotate set up to archive logs for 30 days; how do I set up my cron job to rotate them automatically from /var/log/net to the long-term storage I have mounted on /mnt/backup?

I do not need to mangle the name when I archive them.

EDIT:

Example of file naming... wireless.log-20120916.gz... there is no fixed log name to key from (which is the assumption in Nikolaidis Fotis' first answer)

1 Answer 1

2

You could create a second logrotate configuration and use as post script something like

#!/bin/bash
LogDate=$(date +"%s")
mv /var/log/messages.1 /data/logs/local_backup/var/log/messages/messages.$LogDate
gzip /data/logs/messages.$LogDate
exit

like here http://www.ashishnepal.com/logrotate-and-move-to-backup-directory/

EDIT

New approach ...

/bin/find $path -mtime 29 -exec cp -p {} /newPath/ \;

you can either execute it from cron job or post process in logrotate

4
  • i like this solution better as it does not use any further 3rd party languages or packages then what is already installed. i found another useful link here.
    – au_stan
    Oct 16, 2012 at 13:18
  • So ... you want to merge the loglines of the last 30 days into a single file called October_2012 (or similar name) ? Do you want to place them under a dir called october_2012/ ? What I understood is that you want to move files older than 30 days to another filesystem. (of course the above was just a sample, which you can modify based on your needs) Oct 16, 2012 at 16:37
  • @NikolaidisFotis, I think I understand where the disconnect is now... please see my edit Oct 16, 2012 at 16:54
  • find <path> -mtime +29 is not correct, that should be find <path> -mtime 29 (at least on my CentOS system) Oct 16, 2012 at 19:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .