refactor(script): List snapshots (#1)
This commit is contained in:
parent
ba8b561e80
commit
d9b1ae5905
@ -245,6 +245,7 @@ function get_snaps_in_cur_sev () {
|
|||||||
|
|
||||||
function do_retention () {
|
function do_retention () {
|
||||||
local snap_list snaps_done_by_us snaps_in_cur_sev snaps_limit oldest_snap snap_return_code
|
local snap_list snaps_done_by_us snaps_in_cur_sev snaps_limit oldest_snap snap_return_code
|
||||||
|
local -a destroyed_snaps failed_to_destroy_snaps
|
||||||
if [[ "${do_dry_run}" == 'true' ]]; then
|
if [[ "${do_dry_run}" == 'true' ]]; then
|
||||||
pprint 'info' 'Dry-run, skipping potential zfs destroy operations ...'
|
pprint 'info' 'Dry-run, skipping potential zfs destroy operations ...'
|
||||||
else
|
else
|
||||||
@ -260,11 +261,23 @@ function do_retention () {
|
|||||||
zfs destroy "${oldest_snap}"
|
zfs destroy "${oldest_snap}"
|
||||||
snap_return_code="${?}"
|
snap_return_code="${?}"
|
||||||
if [[ "${snap_return_code}" -eq '0' ]]; then
|
if [[ "${snap_return_code}" -eq '0' ]]; then
|
||||||
pprint 'info' 'Oldest in chain '"'"'sev:'"${severity}"''"'"' destroyed: '"${oldest_snap}"
|
destroyed_snaps+=("${oldest_snap}")
|
||||||
else
|
else
|
||||||
pprint 'warn' 'Snapshot destruction failed: '"${oldest_snap}"
|
failed_to_destroy_snaps+=("${oldest_snap}")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
if [[ "${#destroyed_snaps[@]}" -gt '0' ]]; then
|
||||||
|
pprint 'info' 'Oldest ZFS snapshot'"$([[ "${#failed_to_destroy_snaps[@]}" -gt '1' ]] && printf -- '%s' 's')"' in chain '"'"'sev:'"${severity}"''"'"' destroyed:'
|
||||||
|
for destroyed_snap in "${destroyed_snaps[@]}"; do
|
||||||
|
pprint 'info' ' '"${destroyed_snap}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if [[ "${#failed_to_destroy_snaps[@]}" -gt '0' ]]; then
|
||||||
|
pprint 'warn' 'Failed to prune ZFS snapshot'"$([[ "${#failed_to_destroy_snaps[@]}" -gt '1' ]] && printf -- '%s' 's')"' in chain '"'"'sev:'"${severity}"''"'"':'
|
||||||
|
for failed_to_destroy_snap in "${failed_to_destroy_snaps[@]}"; do
|
||||||
|
pprint 'warn' ' '"${failed_to_destroy_snap}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user