forked from markmcb/storage-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
btrfs_filesystem_report
executable file
·31 lines (26 loc) · 1.29 KB
/
btrfs_filesystem_report
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
: '
Author: Mark McBride <[email protected]>
Description: This script provides a way to view basic disk size and usage information
alongside BTRFS scrub information. While it should generally be portable on Linux machines
it has not been extensively tested, so some hacking may be required.
IMPORTANT: This script does require root priviledges as they are required by the btrfs
command to access scrub information. You can run without root priviledges,
but will see "[sudo]" in the output where priviledges are required.
'
# get paths
paths=( `df -T | grep btrfs | grep -v "/var/lib" | sed -E "s/.*% //" | tr '\n' ' '` )
scrub_report="BTRFS_PATH SIZE AVAIL USE% SCB ERR"$'\n'
for path in "${paths[@]}"
do
if [[ $EUID -ne 0 ]]; then
last_scrub_days="[sudo]"
summary="[sudo]"
else
last_scrub_days="$(( ($(date +%s) - $(date --date="$(btrfs scrub status ${path} | grep "started" | sed -E "s/Scrub started: *//")" +%s) )/(60*60*24) ))"
summary="$([[ $(btrfs scrub status ${path} | grep "summary") == *"no errors found"* ]] && echo -n "." || echo -n "x" )"
fi
df="$(\df -h -t btrfs --output=size,avail,pcent ${path} | tail -n1)"
scrub_report="${scrub_report}${path} ${df} ${last_scrub_days} ${summary}"$'\n'
done
printf "%s" "${scrub_report}" | sed -E "s/[[:space:]]+/ /g" | column -t -s' '