Skip to content

Instantly share code, notes, and snippets.

@mhoran
Created September 23, 2011 02:06
Show Gist options
  • Save mhoran/1236591 to your computer and use it in GitHub Desktop.
Save mhoran/1236591 to your computer and use it in GitHub Desktop.
tarsnap script
#!/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