Computer
Back Ups
Page

Revised
March 07, 2015

Clean
Backup Script

To use this script:

1: Create empty file , such as /usr/local/bin/BU_Cleanup.sh /opt/local/bin/BU_Cleanup.sh or to place the script into.

2: Set permissions.   Make sure that it is executable.   Mine is set to 770 / rwxrwx---

3: Open the empty file in text editor.   Copy script text below, then paste into file.

4: Configure script under the "CONFIGURE SECTION".

6: Run the script in a terminal to check for errors.

    # cd /usr/local/bin

    # BU_Cleanup.sh

7: Set CRON to run script as needed.



#! /bin/bash
# See http://www.jperkins.us/computer/home_network/
# Author: Jerry Perkins, Nashville, Tennessee
# Last revision September 23, 2006
#
# Purpose: To remove daily and hourly backups that are
# no longer needed.
#
# --------- USER NOTES ----------
#
# Example:
# Path to this script:
# /usr/local/bin/BU_Cleanup.sh
# Delete hourly files older than three days.
# Delete daily files older than two weeks.
# Run every day at 11:55 PM
#
# --------- CONFIGURE SECTION ----------
#
# For each directory to be cleaned,
# copy the Example Script to below and paste it
# into the Program section.
#
# Then uncomment each line.
#
# Set 'STORAGE' to the path of the directory to be cleaned.
#
# Set 'DURATION', to the number of days to retain the backups,
# with a leading plus sign.
#
# Set up CRON to run the script.
#
# --------- EXAMPLE SCRIPT ----------
#
#STORAGE="/mnt/backups/Running/Daily"
#DURATION="+14"
#if [ -e $STORAGE ]; then
#   cd $STORAGE
#   find $STORAGE -mtime $DURATION -type f -exec rm -f {} \;
#fi
#
# --------- PROGRAM SECTION ----------
STORAGE="/mnt/backups/Running/Daily"
DURATION="+21"
if [ -e $STORAGE ]; then
  cd $STORAGE
  find $STORAGE -mtime $DURATION -type f -exec rm -f {} \;
fi

STORAGE="/mnt/backups/Running/Hourly"
DURATION="+5"
if [ -e $STORAGE ]; then
  cd $STORAGE
  find $STORAGE -mtime $DURATION -type f -exec rm -f {} \;
fi
# END


If you have any comments, problems, questions or suggestions, please send me an e-mail at

Updated;   This page was last updated on Mar 07 , 2015 .

Any Browser        Gates Free        Valid XHTML 1.0! Valid CSS!

Linux Logo