December 3, 2008

Easy backup and cleanup for logfiles


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.


find $directory -mtime +$old -exec gzip {} \;
find $directory -mtime +$older -exec rm {} \;

I call the script in the crontab like this:

/usr/sbin/ > /dev/null 2>&1


backup, bash, Linux, logfiles, Snippets

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked

Information about Data protection

This site uses Akismet to reduce spam. Learn how your comment data is processed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}