Easy backup and cleanup for logfiles

Geschrieben von Jens am 03. Dezember 2008

For your applications in production you should keep some logfiles but delete the older ones to save files space.

The following bash script will do the job.

It will zip all files older than 7 days.
Delete all files older than 30 days.
Folders will be ignored.

  1. #!/bin/bash
  2.  
  3. directory="/application/log"
  4. old="7"
  5. older="30"
  6. find $directory -mtime +$old -exec gzip {} \;
  7. find $directory -mtime +$older -exec rm {} \;

I call the script in the crontab like this:

  1. /usr/sbin/clean-log.sh > /dev/null 2>&1
Trackbacks

Benutze diesen Link um diesen Artikel zu verlinken.

Kommentare

Schreibe einen Kommentar

Kommentare