feat(script): Allow snapping only local datasets (#1)
This commit is contained in:
parent
673fb15b46
commit
60b3a92abb
@ -15,3 +15,13 @@ snaps_trivial_suffix='trv'
|
||||
snaps_important_suffix='imp'
|
||||
|
||||
pkgs_list_max_length='24'
|
||||
|
||||
# Hook will by default snapshot all datasets that have the property
|
||||
# 'space.quico:auto-snapshot=true' set, even the ones that are not currently
|
||||
# mounted and may belong to unrelated operating systems. Set
|
||||
# snap_only_local_datasets='true' to limit snapshots to only those datasets
|
||||
# that have aforementioned property and at the same time are currently
|
||||
# mounted in your running OS. Currently mounted is defined as:
|
||||
# findmnt --json --list --output 'fstype,source,target' | \
|
||||
# jq --raw-output '.[][] | select(.fstype=="zfs") | .source'
|
||||
snap_only_local_datasets='true'
|
||||
|
@ -23,6 +23,7 @@ if [[ ! "${snaps_important_keep}" ]]; then snaps_important_keep='5'; fi
|
||||
if [[ ! "${snaps_trivial_suffix}" ]]; then snaps_trivial_suffix='trv'; fi
|
||||
if [[ ! "${snaps_important_suffix}" ]]; then snaps_important_suffix='imp'; fi
|
||||
if [[ ! "${pkgs_list_max_length}" ]]; then pkgs_list_max_length='24'; fi
|
||||
if [[ ! "${snap_only_local_datasets}" ]]; then snap_only_local_datasets='true'; fi
|
||||
|
||||
function split_pkgs_by_importance () {
|
||||
local pkgs_in_transaction
|
||||
@ -58,6 +59,25 @@ function get_globally_snappable_datasets () {
|
||||
done <<<"${datasets_list}"
|
||||
}
|
||||
|
||||
function get_local_snappable_datasets () {
|
||||
local datasets_list
|
||||
datasets_list="$(findmnt --json --list --output 'fstype,source,target' | \
|
||||
jq --raw-output '.[][] | select(.fstype=="zfs") | .source')"
|
||||
while IFS= read -r dataset; do
|
||||
local_snappable_datasets+=("${dataset}")
|
||||
done <<<"${datasets_list}"
|
||||
}
|
||||
|
||||
function trim_globally_snappable_datasets () {
|
||||
for global_dataset in "${globally_snappable_datasets[@]}"; do
|
||||
for local_dataset in "${local_snappable_datasets[@]}"; do
|
||||
if grep -Piq -- '^'"${local_dataset}"'$' <<<"${global_dataset}"; then
|
||||
snappable_datasets+=("${global_dataset}")
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
function write_pkg_list_oneline () {
|
||||
local unabridged_pkg_list_oneline
|
||||
if [[ "${severity}" == 'imp' ]]; then
|
||||
@ -93,6 +113,15 @@ function main () {
|
||||
local -a globally_snappable_datasets
|
||||
get_globally_snappable_datasets
|
||||
|
||||
local -a snappable_datasets
|
||||
if [[ "${snap_only_local_datasets}" == 'true' ]]; then
|
||||
local local_snappable_datasets
|
||||
get_local_snappable_datasets
|
||||
trim_globally_snappable_datasets
|
||||
else
|
||||
snappable_datasets=("${globally_snappable_datasets}")
|
||||
fi
|
||||
|
||||
local pkg_list_oneline
|
||||
write_pkg_list_oneline
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user