[ILUG] Script to move Maildir content
francisdaly at gmail.com
Tue Jul 7 13:44:20 IST 2009
On 07/07/2009, Patrick O'Connor <patrick.oconnor at sysadmin.ie> wrote:
> 1. Just rsync the lot and don't use the maildirs already copied to the new
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 that
> looks like I'll need to use some sort of a table. How would I go about that?
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"
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.
More information about the ILUG