Skip to content

Instantly share code, notes, and snippets.

@dlangille
Last active February 28, 2021 23:45
Show Gist options
  • Save dlangille/dac3b6d138bb12874f9a to your computer and use it in GitHub Desktop.
Save dlangille/dac3b6d138bb12874f9a to your computer and use it in GitHub Desktop.
Each jail is in its own fileset. Snapshot each fileset, back it up. Destroy the filesets.
# the filesets will be different on each jail, thus, we'll always be doing a full unless
# we define this for each jail server
#
FileSet {
Name = "zuul jail snapshots"
Include {
Options {
signature = MD5
Exclude = yes
}
Exclude Dir Containing = .NOBACKUP
File = "\\|/usr/home/dan/bin/jail-snapshots-for-backup.sh list"
}
}
Job {
Name = "zuul jail snapshots"
JobDefs = "DefaultJob"
Client = zuul-fd
FileSet = "zuul jail snapshots"
Write Bootstrap = "/usr/local/bacula/bsr/zuul-fd-jail-snapshots.bsr"
RunScript {
RunsWhen = Before
FailJobOnError = Yes
Command = "/usr/home/dan/bin/jail-snapshots-for-backup.sh create"
}
RunScript {
RunsWhen = After
FailJobOnError = No
Command = "/usr/home/dan/bin/jail-snapshots-for-backup.sh destroy"
}
}
#!/bin/sh
ACTION=$1
JLS=/usr/sbin/jls
JAILS=`${JLS} -h path`
SNAPSHOTDIRECTORY='/.zfs/snapshot/'
SNAPNAME="snapshot-for-backup"
for jail in ${JAILS}
do
# ignore the one value of path, usually the first, because that's the header line.
if [ ${jail} = 'path' ]
then
continue
fi
DATASETNAME=`/sbin/zfs get -H -o name mountpoint ${jail}`
# the snapshot name is of the form: system/usr/local/jails/fedex@snapshot-for-backup
SNAPSHOTFORBACKUP="${DATASETNAME}@${SNAPNAME}"
# the backup dir is of the form: /usr/local/jails/fedex/.zfs/snapshot/snapshot-for-backup
BACKUPDIR="${jail}${SNAPSHOTDIRECTORY}${SNAPNAME}"
case ${ACTION} in
"create")
zfs snapshot ${SNAPSHOTFORBACKUP}
;;
"list")
# echo back out the directory for backup...
echo ${BACKUPDIR}
;;
"destroy")
zfs destroy ${SNAPSHOTFORBACKUP}
;;
esac
done
#!/bin/sh
# this script caters for multiple jail locations
ACTION=$1
SNAPSHOTDIRECTORY='/.zfs/snapshot/'
SNAPNAME="snapshot-for-backup"
ZFSJAILROOTS="system/iocage/jails system/jails"
for ZFSJAILROOT in $ZFSJAILROOTS
do
DATASETS="/sbin/zfs get -r -H -o name -t filesystem name ${ZFSJAILROOT}"
for dataset in `${DATASETS}`
do
# Ignore the jail root. Nothing in there to backup.
if [ "${dataset}" = "${ZFSJAILROOT}" ]
then
continue
fi
MOUNTPOINT=`/sbin/zfs get -H -o value mountpoint ${dataset}`
# the snapshot name is of the form: main_tank/iocage/jails/fedex@snapshot-for-backup
SNAPSHOTFORBACKUP="${dataset}@${SNAPNAME}"
# the backup dir is of the form: /usr/local/jails/fedex/.zfs/snapshot/snapshot-for-backup
BACKUPDIR="${MOUNTPOINT}${SNAPSHOTDIRECTORY}${SNAPNAME}"
case ${ACTION} in
"create")
zfs snapshot ${SNAPSHOTFORBACKUP}
;;
"list")
# echo back out the directory for backup...
echo ${BACKUPDIR}
;;
"destroy")
zfs destroy ${SNAPSHOTFORBACKUP}
;;
esac
done
done
@dlangille
Copy link
Author

Today I amended the script to cater for multiple jail locations.

Both the original and the new script are listed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment