3 # Report on project disk use.
4 # Output can be sent as email to admin with -m
5 # Automatically runs with nice and ionice (if available)
7 # Usage: project-disk-use [-m] [top-n-only]
9 # With -m mail the report to $cfg_admin instead of sending it to stdout
11 # Shows total disk usage in K bytes for $cfg_reporoot
12 # The top-n-only (all if not given) repos are then listed by
13 # decreasing order of disk space.
15 # Note that any *.git directories that are found in $cfg_reporoot that are
16 # not listed in $cfg_chroot/etc/group ARE included and have a '!' suffix added.
20 datefmt
='%Y-%m-%d %H:%M:%S %z'
21 startdate
="$(date "+$datefmt")"
26 if [ "$1" = "-m" ]; then
32 command -v nice
> /dev
/null
&& hasnice
=1
34 command -v ionice
> /dev
/null
&& hasionice
=1
37 _cmd
="du -k -s \"$1\" 2>/dev/null | cut -f 1"
38 [ -n "$hasionice" ] && _cmd
="ionice -c 3 $_cmd"
39 [ -n "$hasnice" ] && _cmd
="nice -n 19 $_cmd"
43 projlist
="$(cut -d : -f 1 < "$cfg_chroot/etc
/group
")"
46 echo "$projlist" |
grep -q -e "^$1$"
49 inuse
="$(get_use_k "$cfg_reporoot")"
50 binned
="$(get_use_k "$cfg_reporoot-recyclebin")"
57 while IFS
='' read -r proj
; do
61 is_listed_proj
"$proj" ||
{ x
='!'; orphans
="$(( $orphans + 1 ))"; }
63 [ -e "$proj.git/.nofetch" ] || mirror
=m
64 usek
="$(get_use_k "$proj.git
")"
65 total
="$(( $total + $usek ))"
66 howmany
="$(( $howmany + 1 ))"
67 line
="$(printf '%8d %s %s%s\n*' "$usek" "$mirror" "$proj" "$x")"
69 results
="$results$line"
71 $(find . -type d -name '*.git' -print -prune 2>/dev/null)
74 enddate
="$(date "+$datefmt")"
76 [ -n "$mailresult" ] && domail
='mail -s "[$cfg_name] Project Disk Use Report" "$cfg_admin"'
79 Project Disk Use Report
80 =======================
82 Start Time: $startdate
85 Repository Root: $cfg_reporoot
86 Disk Use: $inuse (1024-byte blocks)
88 Recycle Bin Root: $cfg_reporoot-recyclebin
89 Disk Use: $binned (1024-byte blocks)
91 Total Disk Use: $(( $inuse + $binned )) (1024-byte blocks)
93 Repository Count: $howmany
95 Repository Total: $total (1024-byte blocks)
97 $(df -h "$cfg_reporoot")
100 if [ $# -lt 1 ] ||
[ $1 != "0" ]; then
102 message
="Individual Repository Use"
103 case "${1%%[!0-9]*}" in ?
*)
104 message
="Individual Repository Use (Top $1)"
105 topn
="head -n ${1%%[!0-9]*}"
110 echo "$message" |
tr -c '\n' -
112 printf '%s' "$results" |
sort -k1,1nr
-k3,3 | \
113 sed -e 's/ M / /' |
$topn