Skip to content

Instantly share code, notes, and snippets.

@fliiiix
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save fliiiix/764dc878e2a0a590c58a to your computer and use it in GitHub Desktop.

Select an option

Save fliiiix/764dc878e2a0a590c58a to your computer and use it in GitHub Desktop.
FreeBSD with ZFS backup incremental
#!/usr/local/bin/zsh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
DATE=$(date "+%Y-%m-%d_%H-%M-%S")
SCRIPTNAME=$(basename $0)
PIDFILE=/var/run/${SCRIPTNAME}.pid
if [ -f ${PIDFILE} ]; then
#verify if the process is actually still running under this pid
OLDPID=$(cat ${PIDFILE})
RESULT=$(ps A | grep ${OLDPID} | grep ${SCRIPTNAME})
if [ -n "${RESULT}" ]; then
echo "${DATE}: Script already running (PID: ${OLDPID})! Exiting"
exit 255
fi
fi
#grab pid of this process and update the pid file with it
PID=$$
echo ${PID} > ${PIDFILE}
echo "${DATE}: start incremetal backup"
LASTSNAPSHOT=`ssh travos "zfs list -t snapshot -o name -s creation -r tank | awk 'END{print}'"`
echo "${DATE}: the last snapshot was: $LASTSNAPSHOT"
#snap teh shot .__.
zfs snapshot -r tank@$DATE
echo "${DATE}: the new snapshot is: tank@$DATE"
START=$(date +%s)
#send it
zfs send -R -i $LASTSNAPSHOT tank@$DATE | ssh -C -c blowfish-cbc,arcfour travos "zfs receive -F tank"
END=$(date +%s)
TIME=$(( $END - $START ))
echo "${DATE}: It took ${TIME} seconds to send the snapshot"
if [ -f ${PIDFILE} ]; then
rm ${PIDFILE}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment