Implement even more accurate space calculation.
This commit is contained in:
parent
90c41c7186
commit
0dc9e6737a
71
beadm
71
beadm
|
|
@ -197,17 +197,18 @@ case ${1} in
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# get list of USEDBYDATASET and USED properties
|
# get list of USEDBYDATASET and USED properties
|
||||||
USED_ALL=$( zfs list -H -t all -o name,usedbydataset,used -r sys/ROOT \
|
USED_ALL=$( zfs list -H -t all -o name,usedbydataset,usedbysnapshots,used -r sys/ROOT \
|
||||||
| sed 1d \
|
| sed 1d \
|
||||||
| sed '/0$/d' \
|
| sed '/0$/d' \
|
||||||
| awk '{ gsub("-"," 0 0 ",$2); gsub("-"," 0 0 ",$3);
|
| sed '/-$/d' \
|
||||||
gsub("K"," 1 ",$2); gsub("K"," 1 ",$3);
|
| awk '{ gsub("-"," 0 0 ",$2); gsub("-"," 0 0 ",$3); gsub("-"," 0 0 ",$4);
|
||||||
gsub("M"," 1024 ",$2); gsub("M"," 1024 ",$3);
|
gsub("K"," 1 ",$2); gsub("K"," 1 ",$3); gsub("K"," 1 ",$4)
|
||||||
gsub("G"," 1048576 ",$2); gsub("G"," 1048576 ",$3);
|
gsub("M"," 1024 ",$2); gsub("M"," 1024 ",$3); gsub("M"," 1024 ",$4);
|
||||||
gsub("T"," 1073741824 ",$2); gsub("T"," 1073741824 ",$3);
|
gsub("G"," 1048576 ",$2); gsub("G"," 1048576 ",$3); gsub("G"," 1048576 ",$4);
|
||||||
gsub("P"," 1099511627776 ",$2); gsub("P"," 1099511627776 ",$3);
|
gsub("T"," 1073741824 ",$2); gsub("T"," 1073741824 ",$3); gsub("T"," 1073741824 ",$4);
|
||||||
gsub("E"," 1125899906842624 ",$2); gsub("E"," 1125899906842624 ",$3);
|
gsub("P"," 1099511627776 ",$2); gsub("P"," 1099511627776 ",$3); gsub("P"," 1099511627776 ",$4);
|
||||||
gsub("Z"," 1152921504606846976 ",$2); gsub("Z"," 1152921504606846976 ",$3);
|
gsub("E"," 1125899906842624 ",$2); gsub("E"," 1125899906842624 ",$3); gsub("E"," 1125899906842624 ",$4);
|
||||||
|
gsub("Z"," 1152921504606846976 ",$2); gsub("Z"," 1152921504606846976 ",$3); gsub("Z"," 1152921504606846976 ",$4);
|
||||||
print $0;
|
print $0;
|
||||||
}' )
|
}' )
|
||||||
# get the list of names and origins for all boot environments
|
# get the list of names and origins for all boot environments
|
||||||
|
|
@ -256,22 +257,42 @@ case ${1} in
|
||||||
# use the USED field from ZFS LIST
|
# use the USED field from ZFS LIST
|
||||||
TOTAL=${USED}
|
TOTAL=${USED}
|
||||||
else
|
else
|
||||||
# calculate space total usage for boot environment
|
# calculate overhead space usage for boot environment
|
||||||
TOTAL=$( echo "${USED_ALL}" \
|
OVERHEAD=$( echo "${USED_ALL}" \
|
||||||
| awk -v name="^${POOL}\/ROOT\/${NAME}" -v snapshot="@${SNAPSHOT}$" \
|
| grep "^${POOL}\/ROOT\/${NAME}" \
|
||||||
'BEGIN {total = 0}
|
| grep -v "@" \
|
||||||
($1 ~ name) {total += $2 * $3}
|
| awk \
|
||||||
($1 ~ snapshot) {total += $4 * $5}
|
'BEGIN {overhead = 0}
|
||||||
END {
|
{overhead += $4 * $5}
|
||||||
if (total <= 1024) { unit = "K"; }
|
END {print overhead}' )
|
||||||
else if (total <= 1048576) { total = total / 1024; unit = "M"; }
|
# calculate snapshots space usage for boot environment
|
||||||
else if (total <= 1073741824) { total = total / 1048576; unit = "G"; }
|
SNAPS=$( echo "${USED_ALL}" \
|
||||||
else if (total <= 1099511627776) { total = total / 1073741824; unit = "T"; }
|
| grep "^${POOL}\/ROOT\/${NAME}" \
|
||||||
else if (total <= 1125899906842624) { total = total / 1099511627776; unit = "P"; }
|
| grep "@" \
|
||||||
else if (total <= 1152921504606846976) { total = total / 1125899906842624; unit = "E"; }
|
| awk \
|
||||||
else { total = total / 1152921504606846976; unit = "Z"; }
|
'BEGIN {snaps = 0}
|
||||||
printf ("%.1f%s",total,unit);
|
{snaps += $6 * $7}
|
||||||
}' )
|
END {print snaps}' )
|
||||||
|
# calculate space usage for boot environment datasets
|
||||||
|
USED=$( echo "${USED_ALL}" \
|
||||||
|
| awk -v name="^${POOL}\/ROOT\/${NAME}" -v snapshot="@${SNAPSHOT}$" \
|
||||||
|
'BEGIN {used = 0}
|
||||||
|
($1 ~ name) {used += $2 * $3}
|
||||||
|
($1 ~ snapshot) {used += $6 * $7}
|
||||||
|
END {print used}' )
|
||||||
|
# calculate total space usage for boot environment
|
||||||
|
TOTAL=$( echo | awk -v used=${USED} -v snaps=${SNAPS} -v overhead=${OVERHEAD} \
|
||||||
|
'BEGIN {total = used + overhead - snaps}
|
||||||
|
END {
|
||||||
|
if (total <= 1024) { unit = "K"; }
|
||||||
|
else if (total <= 1048576) { total = total / 1024; unit = "M"; }
|
||||||
|
else if (total <= 1073741824) { total = total / 1048576; unit = "G"; }
|
||||||
|
else if (total <= 1099511627776) { total = total / 1073741824; unit = "T"; }
|
||||||
|
else if (total <= 1125899906842624) { total = total / 1099511627776; unit = "P"; }
|
||||||
|
else if (total <= 1152921504606846976) { total = total / 1125899906842624; unit = "E"; }
|
||||||
|
else { total = total / 1152921504606846976; unit = "Z"; }
|
||||||
|
printf ("%.1f%s",total,unit);
|
||||||
|
}' )
|
||||||
fi
|
fi
|
||||||
if [ "${2}" = "-a" ]
|
if [ "${2}" = "-a" ]
|
||||||
then
|
then
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue