#!/bin/bash # # Report statistics for each Maildir mailbox: # # Total files (messages). # # Disk space used. # # Size after being tar-gzipped. # # Robin Whittle http://www.firstpr.com.au 24 September 2002 # # My reason for such a report is to help me understand the # contribution of each mailbox to my nightly tar.gzip backup # so I can prune intelligently and keep it smaller than # a CDR. The tar.gz size statistics are not an absolutely # accurate representation of the mailbox's contribution to # the final tar.gz file, since that will involve longer # pathnames and other finer points, but it is plenty good # enough to help me prune. # # This script works on the mailbox files found in one user's # /home/user/Maildir. Run it from the user's home directory # as either the user or root. This is intended to work with # the Courier IMAPD arrangement where the Inbox is the files # found in ~/Maildir/new and ~/Maildir/cur, and where # all other mailboxes are subdirectories, of ~/Maildir/ with # each sub-directory starting with a ".". From the IMAP # client's point of view, mailboxes can contain mailboxes, # but Courier IMAPD makes all levels of mailbox appear as # subdirectories in ~/Maildir/ . For instance: # # ~/Maildir/.Lists.Mail-Courier-users # # is the mailbox "Mail-Courier-users" in the Lists mailbox. # # # Based on a script Michael Carmack (http://www.karmak.org) # contributed to the Courier Users list 23 September 2002. # His script worked on the total contents of each "Maildir" # directory and all its subdirectories for each user: # # /home/*/Maildir. # # So it had to be run as root and gives a single set of # statistics for each user. # # This is modified with double quotes as per Michael's # suggestion to cope with filenames with spaces in them. # # Thanks Michael for cooking up the original script! # # Make sure /tmp is big enough to handle the largest tar-gz file! tmpfile=/tmp/compressedmaildir.${RANDOM}.tgz # Was: # for maildir in /home/*/Maildir; do #### I want it to find only those directories starting with a dot! #### Thanks Michael for ".[^.]*". # for maildir in Maildir/.[^.]*; do # I will cd to ~/Maildir" first and work from there: cd Maildir for maildir in .[^.]*; do echo echo "Mailbox: "${maildir}"" echo -n "Number of files: " find "${maildir}" -type f | wc -l echo -n "Total size of all files: " find "${maildir}" -type f -printf '%s\n' | \ awk 'BEGIN { t=0 } { t+=$1 } END { if (t<1024) print t,"bytes"; else if (t<1048576) print t/1024,"kB"; else if (t<1073741824) print t/1048576,"MB"; else print t/1073741824,"GB"; }' echo -n "Disk space used: " du -sh "${maildir}" | cut -f1 echo -n "Approx tar.gz size: " tar -czf ${tmpfile} "${maildir}" 2>/dev/null ls -lh ${tmpfile} | awk '{ print $5 }' echo done rm -f ${tmpfile} cd .. exit 0