Created
September 23, 2011 02:06
-
-
Save mhoran/1236591 to your computer and use it in GitHub Desktop.
tarsnap script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PATH=/usr/local/bin:$PATH | |
PREFIX=`hostname -s` | |
format=%Y%m%d | |
DATE=`date +$format` | |
echo "Creating ${PREFIX}_$DATE" | |
tarsnap -cf ${PREFIX}_$DATE --quiet -X `dirname $0`/tarsnap-exclude / | |
# Delete old archives | |
ARCHIVES=`sudo tarsnap --list-archives | grep $PREFIX | awk 'BEGIN { FS="_" }; {print $2}' | sort` | |
OLDEST=`date -jf $format -v-7d $DATE +$format` | |
for archive in $ARCHIVES | |
do | |
if [ $archive -lt $OLDEST ] && [ $archive -ne `date -jf $format -v1d $archive +$format` ] | |
then | |
echo "Deleting ${PREFIX}_$archive" | |
tarsnap -df ${PREFIX}_$archive | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment