Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
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. –  austin 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 <path> -mtime +29 is not correct, that should be find <path> -mtime 29 (at least on my CentOS system) –  Mike Pennington Oct 16 '12 at 19:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.