Skip to content

Instantly share code, notes, and snippets.

@johanmeiring
Created October 25, 2012 12:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanmeiring/3952290 to your computer and use it in GitHub Desktop.
Save johanmeiring/3952290 to your computer and use it in GitHub Desktop.
Backup file rotation
#!/bin/bash
DEST=/root/BACKUPS
# Code to actually create backup files goes here...
# Check if we need to rotate the backup files.
FC=`ls ${DEST}/*.tar | wc -l`
if [[ $FC -gt 6 ]]; then
echo "Too many backup files. Deleting oldest one..."
DELETE_FILE=`ls -tr ${DEST}/*.tar | head -1`
rm $DELETE_FILE
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment