Last active
August 29, 2015 14:16
-
-
Save fliiiix/764dc878e2a0a590c58a to your computer and use it in GitHub Desktop.
FreeBSD with ZFS backup incremental
This file contains hidden or 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
| #!/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