[ILUG] Script to move Maildir content

Thomas Pedoussaut thomas at staffeurs.org
Tue Jul 7 16:33:29 IST 2009


As some mentioned already rsync is your friend.

then a simple loop through accounts like

while read oldusr newusr
do
rsync -a --exclude=dovecot /home/${oldusr}/Maildir TARGET:/home/${newusr}
done < /tmp/accounts.txt

with accounts.txt being simply
oldusr1 newusrA
oldusr2 newusrB



Adapt to whatever is your situation (especially the exclude if yu have
courrier or another imap server != dovecot).

I also found way easier to seperate tasks. If you need to fiddle with
rights on the target, do it once the data is transferred, in another
loop run on that machine, rather than trying to do everything in one go.

something like: find /wherever -type f -exec chmod XYZ {} \+
will do the job nicely.

A good resource for this kind of jobs is the Advance Bash Scritping from
TLDP.org
http://tldp.org/LDP/abs/html/index.html

-- 
Thomas



More information about the ILUG mailing list