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
41 _y
="${1%%[1-9]*}"; _x="${1#$_y}"; _x="${_x:-0}"
42 # add commas after each group of 3
44 while [ $_x -gt 999 ]; do
45 _y
="$(printf '%03d' $(($_x - $_x / 1000 * 1000)))${_y:+,$_y}"
48 [ $_x -eq 0 ] || _y
="$_x${_y:+,$_y}"
53 _cmd
="du -k -s \"$1\" 2>/dev/null | cut -f 1"
54 [ -n "$hasionice" ] && _cmd
="ionice -c 3 $_cmd"
55 [ -n "$hasnice" ] && _cmd
="nice -n 19 $_cmd"
59 projlist
="$(cut -d : -f 1 < "$cfg_chroot/etc
/group
")"
62 echo "$projlist" |
grep -q -e "^$1$"
65 inuse
="$(get_use_k "$cfg_reporoot")"
66 binned
="$(get_use_k "$cfg_reporoot-recyclebin")"
74 while IFS
='' read -r proj
; do
78 is_listed_proj
"$proj" ||
{ x
='!'; orphans
="$(( $orphans + 1 ))"; }
79 mirror
="$(get_mirror_type "$proj.git
" 2>/dev/null || :)"
81 usek
="$(get_use_k "$proj.git
")"
82 repok
="$(git --git-dir="$cfg_reporoot/$proj.git
" config --get girocco.reposizek 2>/dev/null || :)"
86 repok
="${repok%%[!0-9]*}"
87 repokpct
=$
(( ( $repok * 100 + $usek / 2 ) / $usek ))
88 if [ $repokpct -le 100 ]; then
97 ktotal
=$
(( $ktotal + $repok ))
98 total
="$(( $total + $usek ))"
99 howmany
="$(( $howmany + 1 ))"
100 line
="$usek $repokpct $mirror $proj$x$nl"
101 results
="$results$line"
103 $(find . -type d -name '*.git' -print -prune 2>/dev/null)
106 kpct
=$
(( ( $ktotal * 100 + $inuse / 2 ) / $inuse ))
107 enddate
="$(date "+$datefmt")"
109 [ -n "$mailresult" ] && domail
='mail -s "[$cfg_name] Project Disk Use Report" "$cfg_admin"'
112 Project Disk Use Report
113 =======================
115 Start Time: $startdate
118 Repository Root: $cfg_reporoot
119 Disk Use: $(fmtcomma "$inuse") (1024-byte blocks)
120 reposizek Total: $(fmtcomma "$ktotal") ($kpct%)
122 Recycle Bin Root: $cfg_reporoot-recyclebin
123 Disk Use: $(fmtcomma "$binned") (1024-byte blocks)
125 Total Disk Use: $(fmtcomma "$(( $inuse + $binned ))") (1024-byte blocks)
127 Repository Count: $(fmtcomma "$howmany")
128 Orphaned: $(fmtcomma "$orphans")
129 Repository Total: $(fmtcomma "$total") (1024-byte blocks)
131 $(df -h "$cfg_reporoot")
134 if [ $# -lt 1 ] ||
[ $1 != "0" ]; then
136 message
="Individual Repository Use"
137 case "${1%%[!0-9]*}" in ?
*)
138 message
="Individual Repository Use (Top $1)"
139 topn
="head -n ${1%%[!0-9]*}"
144 echo "$message" |
tr -c '\n' -
146 printf '%s' "$results" |
sort -k1,1nr
-k4,4 | \
147 while read -r a b c d
; do
148 printf "%10s %4s %s %s\n" "$(fmtcomma "$a")" "$b" "$c" "$d"
150 sed -e 's/ [M-] / /g' |
$topn