Kamis, November 17, 2011

Bash : Auto Delete Old Backup Files

Based on my experience on maintenance project.
It's about to create auto delete old backup files on Mandriva 2005 (Linux) server.

This article is related with this article

After create backup file there will be alot of files created in our backup folder.
So we need an auto delete old backup files.

1. Create recycle.sh
$ mcedit /recycle.sh

File content :

#! /bin/sh
find /backup | grep `date -d '1 week ago' +%Y-%m-%d` | xargs --no-run-if-empty rm

2. Edit crontab

$ mcedit /etc/crontab

File Content :

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
00 15 * * 1-6 root /bin/sh /recycle.sh

3. Reconfigure your crontab

$ crontab -u[username] /etc/crontab
$ crontab -l

Auto delete scheduled every Monday through Friday 2 pm :)

Modified from : http://unix.stackexchange.com

0 comments: