Monday, January 7, 2008

Logging

Logging is a way to keep track of events on the server.

A lot of daemons generate their own logs. Look in /var/log.

I have a backup route that uses cron to run rsync once a week. I have it output the changed files and errors to a log file. The cron entry to do this is:

0 1 * * 0 rsync -av --delete /home/documents/ /home/backup/ > rsynclog.$(date +%Y%m%d).txt

lets break that down. The first section (0 1 * * 0) tells cron when to do it. In this case every Sunday at 1:00 am. See the cron entry for more info.

Next is the command (rsync..../backup/) see the NAS backup section for more info on this.

The final section creates the log. The v in -av will output which files are changed added or deleted to the backup set. If you do no more, this will be output to the terminal on the screen and will be gone when you close the terminal. To save it to a file we use the >. > redirects the output to the file specified. In our case this is rsynclog.(todays date).txt. Todays date is generated by $(date) and is formatted by +%Y%m%d. See the man page for the date command for more options.

http://www.unixgeeks.org/security/newbie/unix/cron-1.html
http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/
http://www.cyberciti.biz/faq/linux-log-files-location-and-how-do-i-view-logs-files/

No comments: