Instantly share code, notes, and snippets.

Embed
What would you like to do?
FreshPorts archive-snapshots-for-backup.sh
#!/bin/sh
ACTION=$1
BASENAME="/usr/bin/basename"
MOUNT="/sbin/mount"
UMOUNT="/sbin/umount"
ZFS="/sbin/zfs"
DATASETROOT="main_tank/data/freshports/backend/queues"
DATASETS="${ZFS} list -r -H -o name ${DATASETROOT}"
SNAPSHOTDIRECTORY='/.zfs/snapshot/'
SNAPNAME="bu"
TMP_MNT_POINT="/mnt/freshports-queues"
case ${ACTION} in
"create")
${ZFS} snapshot -r "${DATASETROOT}@${SNAPNAME}"
for dataset in `${DATASETS}`
do
echo mkdir -p ${TMP_MNT_POINT}/${dataset}
mkdir -p ${TMP_MNT_POINT}/${dataset}
done
for dataset in `${DATASETS}`
do
if [ ${dataset} != ${DATASETROOT} ]
then
echo ${MOUNT} -t zfs -o ro ${dataset}@${SNAPNAME} ${TMP_MNT_POINT}/${dataset}
${MOUNT} -t zfs -o ro ${dataset}@${SNAPNAME} ${TMP_MNT_POINT}/${dataset}
fi
done
;;
"destroy")
for dataset in `${DATASETS}`
do
# Ignore the jail root. Nothing in there to backup.
if [ "${dataset}" = "${DATASETROOT}" ]
then
continue
fi
echo ${UMOUNT} ${TMP_MNT_POINT}/${dataset}
done
${ZFS} destroy -r "${DATASETROOT}@${SNAPNAME}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment