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)

Mike Pennington
  • 8,305
  • 9
  • 44
  • 87

1 Answers1

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

Mike Pennington
  • 8,305
  • 9
  • 44
  • 87
Nikolaidis Fotis
  • 2,032
  • 11
  • 13
  • 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](http://www.thegeekstuff.com/2010/07/logrotate-examples/). – au_stan Oct 16 '12 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) – Nikolaidis Fotis Oct 16 '12 at 16:37
  • @NikolaidisFotis, I think I understand where the disconnect is now... please see my edit – Mike Pennington Oct 16 '12 at 16:54
  • `find -mtime +29` is not correct, that should be `find -mtime 29` (at least on my CentOS system) – Mike Pennington Oct 16 '12 at 19:25