copying and renaming mailboxes to clean up directories

Bron Gondwana brong at fastmail.fm
Wed May 2 20:21:55 EDT 2007


On Wed, May 02, 2007 at 03:11:03PM +0200, Thorsten B?ker wrote:
> Dear all,
> But wondering about the heavily increased amount of partition in use, I
> noticed that my call of rsync lacked of the "--delete" attribute. In 
> consequence the restored mailbox directories include not only the 
> messages, which should be in the inbox, but all files beeing in the 
> directories during the backup cronjobs. (My mailbox sizes ~700 MB 
> instead of ~100 MB.)
> 
> With regard to backup performance I'd like to clean up the relevant
> directories by ensuring uniformity of the inbox according to the Cyrus
> mailbox database and the files in the mailbox directory.
> 
> In the wiki I found Andrew's collection of scripts [2] and had a try. My 
> intention is/was to firstly manually select mailbox directories, which 
> contain much too much unneeded files -- mainly mailboxes used via imap. 
> After temporarily stopping mail delivery and mailbox access, each chosen 
> mailbox might be renamed and its contents copied to a new mailbox of its 
> initial name. After starting mail delivery and access again, the 
> mailboxes and directories containing wrong fails might be deleted at all.
> 
> But, as usual, the idea doesn't work yet. A first try to copy the
> existing mailbox "thorsten" to "thorsten_neu" leads to the following:

I think I've posted my "Cyrus::IndexFile" perl module to the list
before, but I'll attach it here as well.  This allows you to parse
through indexes a lot more efficiently, and 'cyr_dbtool' (see the
patches at http://cyrus.brong.fastmail.fm/) is great for seeing the
contents of mailboxes.db.  Unfortunately, most of our tools are only
for cyrus 2.3+.  We were running a fairly recent CVS even back when I
started work on dbtool, and that was one of my first projects at
FastMail.

I've had to do the same job, and I did it by reading the directory
contents and listing UIDs via IMAP, then removing any that didn't
match.  There's no need to move anything.

$imap->select("INBOX.Trash");
ls /var/spool/imap/b/user/brong/Trash/

You'll need some logic to map from mailbox names to on-disk paths of
course, but I think this is a cleaner solution than the copying one, and
as other people have noted, this doesn't break flags (including \Sent)

Bron.


More information about the Info-cyrus mailing list