show snapshot size and number of snapshots processed
This commit is contained in:
parent
68e65a66a3
commit
6e3891ddd1
|
@ -4,7 +4,7 @@ ZFS Prune Snapshots Changes
|
||||||
Not Yet Released
|
Not Yet Released
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
- (nothing)
|
- Show snapshot size (used) and number of snapshots processed
|
||||||
|
|
||||||
`v1.3.0`
|
`v1.3.0`
|
||||||
--------
|
--------
|
||||||
|
|
|
@ -71,7 +71,7 @@ debug() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# given a time in seconds, return the "human readable" string
|
# given a time in seconds, return the "human readable" string
|
||||||
human() {
|
human-time() {
|
||||||
local seconds=$1
|
local seconds=$1
|
||||||
if ((seconds < 0)); then
|
if ((seconds < 0)); then
|
||||||
((seconds *= -1))
|
((seconds *= -1))
|
||||||
|
@ -101,6 +101,27 @@ human() {
|
||||||
echo '0 seconds'
|
echo '0 seconds'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
human-size() {
|
||||||
|
local bytes=$1
|
||||||
|
|
||||||
|
local times=(
|
||||||
|
$((bytes / 1024 / 1024 / 1024)) # gb
|
||||||
|
$((bytes / 1024 / 1024)) # mb
|
||||||
|
$((bytes / 1024)) # kb
|
||||||
|
$((bytes)) # b
|
||||||
|
)
|
||||||
|
local names=(GB MB KB B)
|
||||||
|
|
||||||
|
local i
|
||||||
|
for ((i = 0; i < ${#names[@]}; i++)); do
|
||||||
|
if ((${times[$i]} >= 1)); then
|
||||||
|
echo "${times[$i]} ${names[$i]}"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo '0 B'
|
||||||
|
}
|
||||||
|
|
||||||
if ! type -P zfs &>/dev/null; then
|
if ! type -P zfs &>/dev/null; then
|
||||||
echo "Error! zfs command not found. Are you on the right machine?"
|
echo "Error! zfs command not found. Are you on the right machine?"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -166,7 +187,9 @@ if $recursive; then
|
||||||
fi
|
fi
|
||||||
now=$(date +%s)
|
now=$(date +%s)
|
||||||
code=0
|
code=0
|
||||||
while read -r creation snapshot; do
|
totalused=0
|
||||||
|
count=0
|
||||||
|
while read -r creation snapshot used _; do
|
||||||
# ensure optional prefix matches
|
# ensure optional prefix matches
|
||||||
snapname=${snapshot#*@}
|
snapname=${snapshot#*@}
|
||||||
if $invert; then
|
if $invert; then
|
||||||
|
@ -196,15 +219,17 @@ while read -r creation snapshot; do
|
||||||
|
|
||||||
# ensure snapshot is older than the cutoff time
|
# ensure snapshot is older than the cutoff time
|
||||||
delta=$((now - creation))
|
delta=$((now - creation))
|
||||||
human=$(human "$delta")
|
human=$(human-time "$delta")
|
||||||
if ((delta <= seconds)); then
|
if ((delta <= seconds)); then
|
||||||
debug "skipping $snapshot: $human old"
|
debug "skipping $snapshot: $human old"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# remove the snapshot
|
# remove the snapshot
|
||||||
|
humanused=$(human-size "$used")
|
||||||
|
|
||||||
if ! $quiet || $dryrun; then
|
if ! $quiet || $dryrun; then
|
||||||
echo -n "removing $snapshot: $human old"
|
echo -n "removing $snapshot: $human old ($humanused)"
|
||||||
fi
|
fi
|
||||||
if $dryrun; then
|
if $dryrun; then
|
||||||
echo ' <dry-run: no action taken>'
|
echo ' <dry-run: no action taken>'
|
||||||
|
@ -214,5 +239,11 @@ while read -r creation snapshot; do
|
||||||
fi
|
fi
|
||||||
zfs destroy "${destroyargs[@]}" "$snapshot" || code=1
|
zfs destroy "${destroyargs[@]}" "$snapshot" || code=1
|
||||||
fi
|
fi
|
||||||
done < <(zfs list -Hpo creation,name -t snapshot -r "${pools[@]}")
|
|
||||||
|
((total += used))
|
||||||
|
((count++))
|
||||||
|
done < <(zfs list -Hpo creation,name,used -t snapshot -r "${pools[@]}")
|
||||||
|
|
||||||
|
echo "processed $count snapshots ($(human-size "$total"))"
|
||||||
|
|
||||||
exit "$code"
|
exit "$code"
|
||||||
|
|
Loading…
Reference in New Issue