Skip to content

Commit f2d3336

Browse files
committed
Add a contrib script to snapshot the BE prior to boot
1 parent fb98c59 commit f2d3336

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

contrib/snapshot-teardown.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
## A simple teardown hook to take a clean snapshot of the boot environment
4+
## prior to launching the new kernel. This requires that your pool be read-write
5+
## and will always export it.
6+
##
7+
## To use, put this script somewhere, make sure it is executable, and add the
8+
## path to the `zfsbootmenu_teardown` space-separated list with, e.g.,
9+
##
10+
## zfsbootmenu_teardown+=" <path to script> "
11+
##
12+
## in a dracut.conf(5) file inside the directory specified for the option
13+
## `Global.DracutConfDir` in the ZFSBootMenu `config.yaml`.
14+
15+
# exit early if we're missing our env var
16+
[ -n "${ZBM_SELECTED_BE}" ] || exit
17+
18+
for src in /lib/zfsbootmenu-core.sh /lib/kmsg-log-lib.sh ; do
19+
# shellcheck disable=SC1090
20+
source "${src}" || exit
21+
done
22+
23+
zpool="${ZBM_SELECTED_BE%%/*}"
24+
25+
if ! zpool list -H -o name "${zpool}" >/dev/null 2>&1 ; then
26+
read_write=true import_pool "${zpool}"
27+
else
28+
set_rw_pool "${zpool}"
29+
fi
30+
31+
printf -v snapshot "${ZBM_SELECTED_BE}@preboot-%(%Y-%m-%d-%H%M%S)T"
32+
zfs snapshot "${snapshot}"
33+
export_pool "${zpool}"

0 commit comments

Comments
 (0)