Created
December 23, 2017 20:15
-
-
Save dlangille/480dbca509562eb03e76c2e1b576c6d2 to your computer and use it in GitHub Desktop.
FreshPorts archive-snapshots-for-backup.sh
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 | |
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