Backing up ZFS snapshots
Posted by jpluimers on 2018/12/06
An interesting idea at [WayBack] I was getting concerned about a backup, which had exceeded 1GB, when the data was only about 400MB. Once the job finished, I realized: Ahh, ZFS compres… – Dan Langille – Google+:
Here’s that script I use for creating/destroy the snaphots for a particular long dataset name. Then I backup from /mnt
[WayBack] gist.github.com/dlangille/480dbca509562eb03e76c2e1b576c6d2 is in sh, not even bash.
–jeroen
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
| #!/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 |






Leave a comment