Created
May 1, 2017 20:21
-
-
Save optiz0r/68cb93172d72d2f8db48f7ab7b67c28e to your computer and use it in GitHub Desktop.
Simple bacula ZFS/bpipe fileset and wrapper scripts
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 | |
# | |
# A script which does everything bacula bpipe needs ie: | |
# - create a snapshot with the current date / time | |
# - do a zfs send out of that snapshot | |
# - clean up snapshot when complete | |
# | |
FILESYSTEM=$1 | |
if [ -z $FILESYSTEM ]; then | |
exit 1 | |
fi | |
TIME_NOW=`date +%Y%m%d%H%M%S` | |
TIMESTAMP_NOW=`date -u +%s` | |
SNAP_NAME=backup_$TIME_NOW | |
SNAP_OBJ=$FILESYSTEM@$SNAP_NAME | |
# Go ahead and snap what we need | |
# snapshot the filesystem | |
zfs snapshot $FILESYSTEM@$SNAP_NAME | |
if [ $? -ne 0 ]; then | |
exit 2 | |
fi | |
# do the sending | |
zfs send $FILESYSTEM@$SNAP_NAME | |
if [ $? -ne 0 ]; then | |
exit 3 | |
fi | |
# clean up | |
zfs destroy $FILESYSTEM@$SNAP_NAME | |
if [ $? -ne 0 ]; then | |
exit 4 | |
fi | |
# mark as backed up | |
zfs set myco:last_backup="$TIMESTAMP_NOW|$TIME_NOW" $FILESYSTEM | |
if [ $? -ne 0 ]; then | |
exit 5 | |
fi | |
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 | |
# | |
# A script which handes restorals of backups which | |
# were taken with bacula bpipe or originaly backed | |
# up from a FIFO | |
# - given as an output argument to bpipe | |
# - creates a fifo (in location specified by arg1) | |
# - redirects output of bacula restore to this fifo | |
# - its left up to you to either: | |
# - cat fifo | zfs recv path/to/filesystem | |
# - cat fifo > /path/to/filename.zfsdump | |
# | |
RESTOREFIFO=$1 | |
if [ -z $RESTOREFIFO ]; then | |
# no input argument given | |
exit 1 | |
fi | |
if [ -e $RESTOREFIFO ]; then | |
# if the $RESTOREFIFO path exists already | |
exit 2 | |
fi | |
# create a fifo at the correct path to restore into | |
mkfifo $RESTOREFIFO | |
if [ $? -ne 0 ]; then | |
# creation of the restore fifo failed | |
exit 3 | |
fi | |
# redirect the filestream which bacula provides over stdin | |
# into the $RESTOREFIFO | |
cat < /dev/stdin > $RESTOREFIFO | |
RESTOREOK=$? | |
# Clean up fifo whether or not the restore failed | |
rm $RESTOREFIFO | |
CLEANUPOK=$? | |
if [ $RESTOREOK -ne 0 ]; then | |
# looks like the restore failed | |
exit 4 | |
fi | |
if [ $CLEANUPOK -ne 0 ]; then | |
# couldnt clean up the $RESTOREFIFO, otherwise good | |
exit 5 | |
fi |
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
FileSet { | |
Name = "test-fileset" | |
Include { | |
Options { | |
signature = MD5 | |
readfifo = yes | |
} | |
Plugin = "bpipe:/zfsdump/server/pool_filesystem:/usr/local/sbin/bacula-zfs-send 'pool/filesystem':/usr/local/sbin/bacula-zfs-restore /tmp/pool_filesystem.fifo" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment