Skip to content

Instantly share code, notes, and snippets.

@rsdy
Last active December 14, 2015 04:19
Show Gist options
  • Save rsdy/5027329 to your computer and use it in GitHub Desktop.
Save rsdy/5027329 to your computer and use it in GitHub Desktop.
simple backup script wrapping tarsnap
#!/bin/ksh
#
# compile tarsnap, and install it to $BASEDIR
#
# put the files/dirs to be included into $BASEDIR/includes
# specify exclude patterns in $BASEDIR/excludes
# both files should contain either space or newline-separated items
#
# tweak $DELETE_ARCH to specify the retention time after which the
# archives will be deleted
#
# deletion of archives is lazy, only one at a time. i do consider
# this a feature
#
PATH="${BASEDIR}/bin:${PATH}"
HOST="$(hostname)"
BASEDIR="/root/tarsnap"
EXCLUDE_FILE="excludes"
INCLUDE_FILE="includes"
DATE_TEMPLATE='date +%Y%m%d'
ARCH_NAME="${HOST}-$(${DATE_TEMPLATE})"
DELETE_ARCH="${HOST}-$(${DATE_TEMPLATE} --date='5 days ago')"
tarsnap --configfile ${BASEDIR}/etc/tarsnap.conf -cf "$ARCH_NAME" \
--one-file-system \
$(sed 's/\(^\| \)/ --exclude /g' ${BASEDIR}/${EXCLUDE_FILE}) \
$(cat ${BASEDIR}/${INCLUDE_FILE}) \
&>${BASEDIR}/log/${ARCH_NAME}
tarsnap --configfile ${BASEDIR}/etc/tarsnap.conf -df $DELETE_ARCH \
&>>${BASEDIR}/log/${ARCH_NAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment