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.

 

Tóg – Meaning To Build. A hackerspace for Dublin

April 10th, 2009

  Over the past few months a group of technology enthusiasts have been working hard on creating a hackerspace for Dublin. The group, initially consisting of local 2600 members has grown to include other interested technology enthusiasts. They are planning to have a bootup space opened by May with expe [ ... ]

Doing Business with Free Software

April 8th, 2009

  Check out my page here which has video and slides from a talk I gave with some colleagues discussing how to use Free Software in business. Click here. [ ... ]

Openmoko FreeRunner – Limited Release

July 1st, 2008

  The good people at Openmoko are drumming up interest for the 2nd revision of their mobile phone called the FreeRunner. They’ve set up a wiki page for group purchases where people from different regions can club together in groups of 10 for a discounted price. If you want to be included post a  [ ... ]

Stephen Fry advocates F/OSS

February 4th, 2008

  Stephen Fry has long been one of my favourite comedians so I was delighted to read about his propensity black jack downloadt?l?charger un poker gratuitesacheter jeu pokerregle du poker texas holdempoker online francaisjeux casino poker gratuitesjeux poker omaha gratuitespoker en ligne sans argentles [ ... ]

All-Island Conference on F/OSS

January 21st, 2008

  Belfast is hosting the Inaugural all-Island Conference on Free and Open Source Software this February 1st. The event will feature a key note from Bruce Perens, author of the Open Source Definition, as well as addresses by senior representatives from large public and private sector organisations such [ ... ]

Qualipso Conference Lowdown

January 18th, 2008

  Had a thoroughly enjoyable time in Rome at the Qualipso conference over the past 2 days. Thanks to Roberto Galoppini for the heads up via his blog. Qualipso is a global consortium established to bridge business and public administrations to the Open Source world. It was established in 2006 and has m [ ... ]

Qualipso 2008

January 16th, 2008

  I’m attending the Qualipso Conference for the next few days. Interesting to see the EU massive starting to put some mass in Open Source and Free Software. Hopefully there’s a lot more to come! [ ... ]

Who said sequels were rubbish? (Dissertation 2.0)

January 16th, 2008

  Hopefully this will be the exception to the rule… I’ve finally made the changes to the dissertation that I didn’t have time for by the submission deadline. This is a true Version 2.0 as a lot of glaring errors were corrected and “features” were added in including more g [ ... ]

Dissertation… The End of the Beginning

November 29th, 2007

  Here’s a link to my “completed” dissertation. Its the culmination of several years of interest in Open Source and Small Businesses and aims to add to research into the competitiveness of small and micro enterprises through collaboration and integration of small and micro enterprise [ ... ]