[ILUG] Script to move Maildir content
patrick.oconnor at sysadmin.ie
Sat Jul 11 14:25:52 IST 2009
Success! For the first batch of older mails already copied to the traget
machine anyway. I'm going to get to rsyncing the changes tomorrow.
Excuse the top posting but I thought it would be clearer to show the scripts
I already had a copy of old mails so I used Francis' script to move them
into the right place. tr is a great tool I'd never come across before and it
was the last piece of the puzzle.
Here's the script:
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
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/.*
I made some minor changes to Francis' script to include the domain name and
also to copy . folders (and then delete the .Trash folder). the chown
scripts had to be modified too. I actually created a second script for that
but I think its been reprodiced here properly so that everything can be run
from one script.
Next step is to modify the script to use rsync to copy changes since the
first batch was copied over. Now that the script is written it should be
pretty easy to do.
Thanks again for all your help :-)
2009/7/7 Francis Daly <francisdaly at gmail.com>
> On 07/07/2009, Patrick O'Connor <patrick.oconnor at sysadmin.ie> wrote:
> Hi there,
> > 1. Just rsync the lot and don't use the maildirs already copied to the
> > server.
> I'd use something like that one. If large data transfer is slow and
> already done, then you can try moving the data around so that the new
> rsync will find and use it.
> > Either way I still need a way to link the old usernames to the new and
> > looks like I'll need to use some sort of a table. How would I go about
> Do it one bit at a time, in a loop.
> As has been mentioned, use "rsync" to copy the data from "oldserver"
> to "newserver". Write it to a temporary location on the same volume as
> the final location, so that "mv" completes rapidly.
> You'll need the new and old directory names -- probably the usernames
> from your "users" file.
> You'll need the new user:group ownerships -- the new username, and
> maybe the groupname matches the username, or maybe the groupname is
> the same for everyone. Below, I assume group=user.
> The tr/read line below needs that no new or old username includes
> whitespace or colon. You can verify that in your "users" file before
> starting. If it is not the case, some modifications will be needed.
> src="temporary rsync Maildir location, absolute or relative to here"
> dst="final Maildir location, absolute or relative to $src"
> users="file containing olduser:newuser pairs, absolute or relative to $src"
> cd "$src"
> tr : ' ' < "$users" | while read old new; do
> mv $old "$dst"/$new && chown -R $new:$new "$dst"/$new
> Watch for any error output. If, at the end, anything remains in $src,
> then the $users file may not have been complete.
> You can pick your own level of testing and validating that you can
> access the new mailstore as the appropriate users. For the live
> cutover, have a recent rsync done; stop the
> normal-access-write-processes on the old server, do a fresh rsync
> (which should be fast), run the tested script on the new server and
> confirm that it worked, then start the normal-access-write-processes
> on the new server.
> Good luck,
More information about the ILUG