Copying Maildir Contents

July 6th, 2009

I’ve got a bunch of mails (in Maildir format) to move from one server to another. Only problem is that there’s lots of them (60 accounts in 5 different domains, 70GB total). I’m trying to dip my toe in the waters of shell scripting but am a bit lost. If anyone can help out I’d be glad to provide suitable beverages at the next potd!

I’ve written a “pseudo script” which just outlines how I think the job could be done but is lacking in some minor details like proper commands, array setup and generally anything to make the script usable! It should help to describe the task though….

—Start “Pseudo Script”—
# text file containing table mapping old usernames to new usernames
$users = /location/users

#$archivelocation has a bunch of folders named oldusername1, oldusername2 etc each containing the Maildir directory plus other files/directories.
#The Maildir directory contains miscellaneous courier mail files and “new” and “tmp” directories as well as the “cur” directory.
$archivelocation = /location/of/maildir/archives

#$newlocation has a bunch of folders named newusername1, newusername2 etc containing the Maildir directory. They’re all empty so overwriting is not a problem.
$newlocation = /location/of/new/maildirs

#Needed to set permissions on copied content.
$domainusername = somedomain

#All I want to move is partial contents of the Maildir folder i.e. the “cur” folder and all .folders (except .Trash).
#I need to copy the only the required contents from the old Maildir to the new and change ownership/group
#of the copied files to “newusername*.domainusername:$domainusername”

#With my (very basic) knowledge of commands I would do this…

cp -frv $archivelocation/$oldusername1fromusersfile/Maildir/cur /$newlocation/$newusername1fromusersfile/Maildir/
cp -frv $archivelocation/$oldusername1fromusersfile/Maildir/./* /$newlocation/$newusername1fromusersfile/Maildir/
rm -fr /$newlocation/$newusername1fromusersfile/Maildir/.Trash
chown -R $newusername1fromusersfile:$domainusername /$newlocation/$newusername1fromusersfile/Maildir/

Repeat for each username combo….

—End “Pseudo Script :-)

Contents of “users”
oldusername1:newusername1
oldusername2:newusername2

UPDATE:

Thanks to the resident geniuses on the ILUG mailing list they have provided me with the script to complete this task. Here’s the script (1st part anyway)

Here’s the script:
====
#!/bin/sh
src=”00migrate” # a folder in the accounts home direcotry storing the accounts to be migrated
dst=”../”  # accounts home directory relative to $src
users=”../userlist.db” # flat file containing maps of old users to new in the form olduser:newuser
dom=”somedomain” # master account for the domain used to complete the username and group ownership

cd “$src”
tr : ‘ ‘ < “$users” | while read old new; do

mv $old/Maildir/cur “$dst”$new/Maildir/ && mv $old/Maildir/.* “$dst”$new/Maildir/ && rm -frv “$dst”$new/Maildir/.Trash/ && chown -R $new.”$dom”:”$dom” “$dst”$new/ && chown -R $new.”$dom”:”$dom” “$dst”$new/.*
done
===

Next I just need to edit the script to use rsync to copy the changes from the still running (but to be retired) mail server to the new one and then finally kill off the old server.

 

The Party

April 12th, 2008

  Here’s a link to google maps showing how to find Rebecca’s apartment. We’re not theming the party but we will be serving some rather Cuban inspired cocktails so feel free to adorn yourself in Cubanesque attire and dash mobile ringtones t | alltel free phone ringtones | motorola rin [ ... ]

Journalist Sentenced to Death – Please Sign Petition

February 2nd, 2008

  Reporters sans frontières - Sayed Perwiz Kambakhsh, a 23-year-old journalist, was arrested in Mazar-i-Sharif, the capital of the northern province of Balkh, on 27 October 2007 on charges of blasphemy and “disseminating defamatory comments about Islam.” Under repeated pressure from the Council of Mul [ ... ]

Eircom SSID thinger … Massive Security Vulnerability

September 30th, 2007

  Eircom SSID thinger This page shows how netopia broadband routers  supplied by eircom are inherently flawed by their out of the box wep settings. When a user sets the router up as per the instructions an ssid is generated, directly relating to the wep key used to encrypt the traffic. This site allow [ ... ]

Useful Joomla Training Videos

September 21st, 2007

  Here’s a playlist I compiled on youtube which contains videos showing the basics of using the Joomla CMS and also for one of its more useful plugins for image intensive sites. [ ... ]

Electric Picnic Videos

September 16th, 2007

  Some videos I took at the Electric Picnic earlier in the month. Not great quality, partly due to my lack of video shooting skills and mostly due to my level of inebriation… [youtube VeV9qi4aqWA] [youtube FmmPdlZz_WY] [youtube AaK3w1PyOMQ] [ ... ]

Crazy P Videos

September 16th, 2007

  Here’s a couple of videos I shot on Friday night when Crazy P hit the stage. Didn’t have a chance to take any more because I was too busy dancing )) [youtube i8i96wPLDJM] [youtube X1J2UfDRhKc] [ ... ]

The Return of Crazy P

September 6th, 2007

  Crazy P, the doyenne of live house music are returning to Dublin to help Remedy Ireland celebrate their fourth birthday. As usual the birthday party is on in the Spiegel Tent being hosted by the Dublin Fringe Festival. The remedy gigs are always top notch nights out but the birthday parties are alwa [ ... ]

Electric Picnic

August 28th, 2007

  Off to The Electric Picnic this weekend )) Thanks to Dara for sorting out a ticket Here’s the line-up and running order that festival goers have to look forward to…. Electric Picnic 2007 Lineup [ ... ]

Chicken and Egg

July 11th, 2007

  Do communities exist because of our needs or do our needs exist to create communities? [ ... ]