Thanks Micheal for your script and off-list help with my tweaks to it.
My final version follows. It runs for a single user and produces a set
of stats on each mailbox, such as:
- - - -
Mailbox: .Lists.Linux-security-CERT
Number of files: 47
Total size of all files: 542.458 kB
Disk space used: 684k
Approx tar.gz size kbytes: 134k
Mailbox: .Lists.Mail-Courier-users
Number of files: 5693
Total size of all files: 21.7073 MB
Disk space used: 30M
Approx tar.gz size kbytes: 3.8M
Mailbox: .Lists.Mail-Postfix
Number of files: 4856
Total size of all files: 14.698 MB
Disk space used: 23M
Approx tar.gz size kbytes: 3.3M
- - - -
The reason I want to tar-gzip the mailbox is to find, approximately, how
much each mailbox contributes to the bloat of the nightly tar-gz backup
so I can prune wisely.
I was planning to make this run as part of a mailfilter action so I
could generate a message in my inbox with the report, by sending myself
a message with a distinctive subject line. But I am not going to use it
very often, so I will keep it as a command line script. Also, if it ran
as a mailfilter command, some work would be required to fork it off it
as a separate process so as not to tie up message delivery in the
minutes it takes to do all this tar-gzipping. But then that would
require a different way of getting the result into a message in my
Inbox, such as mailing it to me.
I always thought there was no simple way to find out the total size of
files under a directory. Now I know for sure:
Michael Carmack wrote:
> This will tell you exactly how many bytes are being used in all the
> files beneath <directory>:
>
> find <directory> -type f -printf '%s\n' | awk '{ t+=$1 } END
> { print t }'
>
> To follow symlinks, throw a '-follow' after the '-type f' in the
> above. With find, you can also specify things like '-mount' to avoid
> traversing other filesystems, and '-maxdepth' to restrict directory
> descension. Try 'man find'.
Then Thomas Lamy wrote:
> find <dir> -type f -ls | xargs awk 'BEGIN { s=0; } { s += $7; }
> END { prints; }'
>
> It sums up the size of all files (-type f) in directory <dir> and all
> it's subdirectories. If you want symlinks counted, add "-follow" to
> the find statement.
But sometime in the mid 90s, Bill Gates wrote:
> Alt-F R
Thanks again Michael! I am a beginner with shell scripts.
- Robin
http://www.firstpr.com.au http://fondlyandfirmly.com
- - - - -
#!/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
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
courier-users mailing list
[EMAIL PROTECTED]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users