Using CRON to save logs?

Using CRON to save logs?

Posted by: finisterre
Posted on: 2009-05-27 18:07:00

Hi,

Can anybody tell me how I can get CRON to (ideally) email me my Dreamhost logs before they get deleted? Failing that to get it to save them somwhere.

I recently had my site hacked and I reckon it happened weeks ago, and of course the logs have expired and been deleted.

Hope someone can help?

Thanks.

Re: Using CRON to save logs?

Posted by: sdayman
Posted on: 2009-05-27 20:44:00

Emailing them on a daily basis is a bit overkill, but you can do this in the Panel under Goodies -> Cron Jobs:
Select your user
Give it a title
Email out to your email address
Command will be: /bin/cat ~/logs/EXAMPLE.COM/http/access.log
When to run: Custom
Selected minutes: 45
Selected hours: 23
Every Day, Every Month, Every Day of Week

The emailing out of the job will include its output, so you don't need to redirect the cat command.

If you want to just keep a giant logfile, make the command:
/bin/cat ~/logs/EXAMPLE.COM/http/access.log >> ~/biglog.txt

This will just grow the biglog by appending each day's log onto the end. You'll need to manually delete or rename it as it gets to big to comfortably browse through it.

-Scott

Re: Using CRON to save logs?

Posted by: habilis
Posted on: 2009-05-28 07:03:00

To archive my logs, I use a daily rsync cron job:

rsync --include='*/' --include='*.gz' --exclude='*' -avl logs/ logs_archive/

That command recursively copies all the gzipped files from logs to logs_archive. The nice thing about this setup is that the files stay as daily compressed files -- small and easy to incrementally backup offsite.

To protect against cracking (or LA sliding into the sea), I remotely mirror (via rsync over ssh) my DH user's home directories to my laptop. After that my regular backup software (TimeMachine) takes over and incrementally backs up to an external hard drive.

Even if a cracker deleted all my DH files a month ago, I will still have a copy of them in an incremental snapsot on my backup drive. The important thing for recovering from vandalism is to have good offsite/offline snapshots. Cautionary tale from Slashdot:

http://hardware.slashdot.org/story/09/01/02/1546214/Why-Mirroring-Is-Not-a-Backup-Solution



Tags: cronlogs