On a UFS or ZFS filesystem, create a snapshot, dump it to a file, and restore it as a new filesystem.

Variable definition
1
2
timestamp=`date +%Y-%m-%d`
dumpfile=/data/archive/dump-${timestamp}
UFS
1
2
3
4
5
6
7
8
9
# Create filesystem snapshot
cd ${src} && mksnap_ffs .snap/${timestamp}
# Dump snapshot to file
dump -0 -a -f ${dumpfile} ${src}/.snap/${timestamp}
# Create
newfs -n /dev/da0s1a
mount /dev/da0s1a ${src}
# Restore filesystem from file
cd ${src} && restore rf ${dumpfile}
ZFS
1
2
3
4
5
6
7
8
9
# Create filesystem snapshot
zfs snapshot -r ${src}@${timestamp}
# Dump snapshot to file
zfs send -R ${src}@${timestamp} > ${dumpfile}
# Create
zpool create ${src} /dev/da0 ...

# Restore filesystem from file
zfs recv -F -d ${src} < ${dumpfile}

During the creation and restoration stage, it may be necessary to temporary choose another name for the partition where the pool is to be restored so that there is no conflict with the running system. This is, for example, typically the case of the root partition /.