Skip to content

Instantly share code, notes, and snippets.

@mick-shaw
Last active December 1, 2015 02:17
Show Gist options
  • Select an option

  • Save mick-shaw/8aebb6ec102bdf0941b5 to your computer and use it in GitHub Desktop.

Select an option

Save mick-shaw/8aebb6ec102bdf0941b5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This backup script will delete files in a directory defined as $bkupdir.
# It will only delete files if there is a minimum number off files defined as $filecounter
# If there are at least the minimum number of files in the defined backup directory,
# it will check the age of files defined as $daycounter. Any files with a timestamp
# that is X days old will be deleted.
# Set the minimum number of backups that should remain
filecounter=10
# Set the backup directory to check
bkupdir='/home/sftpadmin/backups/cm/'
# Set how many days old backups must be for deletion
daycounter=9
# This variable should not have to change
bkup=$(/bin/find "$bkupdir" -type f | wc -l)
if [ $bkup -ge $filecounter ]; then
/bin/find "$bkupdir" -type f -mtime +$daycounter -exec rm -rf {} \;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment