Cleaning up files – Clean up shell script

Few days back I wrote a post about, how to use shell script to backup mysql database. Using this shell script you will have lot of data files which will be created every day. You can not just keep all these files as backup because generally you need DB backup of previous day or few days. You need to run another script to clean all those files which are not useful for you and for which you have latest backup files.

Following is the cleanup script you can use for removing all unnecessary files in your backup directory:

#!/bin/bash
# Clean up script for db backup files

DB_BACKUP_DIR="/opt/backup/mysql"

FIND="$(which find)"

$FIND $DB_BACKUP_DIR -type f -mtime +3 | xargs rm -f

Modify the -mtime parameter value accordingly. Above script will remove all files having modification time older than 3 days from DB backup directory.

Most Commented Posts

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)