Hello Sandip,

I've attached a shell script I wrote for my company that can
automatically migrate a single domain from one qmail toaster server to
another using SCP (you need to create an RSA key for the root user on
the source server, and then add it to the /root/.ssh/authorized_keys
file on the destination server in order to not have to keep re-entering
your root password/passphrase for every SCP operation).

One warning is that if you decided to compile vpopmail-toaster using one
table for all domains rather than one table per domain, this script wont
work for you.

Another issue has to do with the pathnames of directories on toasters
with lots of domain names.  After so many domains are added, instead of
customer's e-mail being setup inside of
/home/vpopmail/domains/example.com it shifts to a subdirectory in
/home/vpopmail/domains/1/example.com with 1 becoming 2, 2 becoming 3
(etc, etc.) as more and more domains are added.  When my script
re-creates the account being migrated on the new server, it then gets
from vpopmail on the destination server the new pathname as it exists on
that server, and then tries to go through and update a bunch of things.
Things like the dump file of that domain's mysql table and various
.qmail* files.

Unfortunately, I couldn't come up with a way of doing this to the
individual ".qmail" files that can appear in some user directories where
things like forward+save a local copy have been enabled using
qmailadmin.  Therefore, my script simply deletes these files, because if
they exist but use the wrong directory, extremely strange behavior
results (no mail showing up, duplicates of mail showing up, etc).

You can comment out that part of the script which does delete user's
.qmail files, but you'll need to remember to change those files by hand
post-migration so that the /home/vpopmail/domains directory referenced
matches the pathname of the domain you're currently working with.

If anyone would like to improve my script, I would love to know about
it.


regards,
~ Dairenn Lombard
Systems Administration Department, Los Angeles
BroadSpire, Inc.



-----Original Message-----
From: Sandip Kumar Das, RDG Systems [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, December 05, 2007 4:47 AM
To: qmailtoaster-list@qmailtoaster.com
Subject: [qmailtoaster] Migration


Dear all,


How do i copy vpopmail domains & mailboxes of all users manually from
one server to another ? In old server domains uids are 7797 (  checking
/var/qmail/users/assign ) but in new server domains uids are 89. If I
manually created all old domains in new server , the uids will be 89.
and then how do i copy all the users and their maildirectories from old
server to new server ? pl suggest. Am I to copy vpopmail database from
old to new ? 

Thanks in advance,

Sandip
#!/bin/sh
# /usr/local/sbin/toastercp.sh
# Copy qmail toaster domains onto another qmail toaster.
#
# Usage: /usr/local/sbin/toastercp.sh domain.com remote.mail.server.hostname
#
# CAUTION - this is only going to work if BOTH vpopmail-toaster installs were
# compiled with --disable-many-domains, otherwise, there will be a MySQL table
# mismatch and IMAP/POP authencation will fail.  It's Okay to enable many
# domains, but again, BOTH servers must have already had vpopmail-toaster
# installed that way, otherwise you need to manually convert the vpopmail
# tables from one format to the other - which this script does not do.
#
#
# Change Log:
# Version       - Feature
# -----------------------------------------------------------------------------
# 1.01          - Patches .qmail-default for the Unix pathname on the new mail
#                 server if catchall is set to another local e-mail address
#                 rather than catchall-to-bounce, catchall-to-delete, or
#                 catchall-forward.  Not doing this results in maildrop
#                 creating duplicate messages in users' inboxes.
#                 Removes individual user .qmail files to cause qmail to
#                 re-create the file (sometimes, these files, when copied
#                 causes unwanted behavior when using webmail other other
#                 system features).
# 1.00          - Initial Release

echo ; echo "toastercp.sh v1.01"
echo "Copyright (c) 2007 BroadSpire, Inc."
echo ; echo "Report bugs!!  E-Mail them to [EMAIL PROTECTED]" ; echo
echo "This script PUSHES existing domains from the origin mail server onto a 
NEW"
echo "mail server, and requires this server's id_rsa.pub file in /root/.ssh to 
be"
echo "copied into the authorized_keys2 file in the remote server's /root/.ssh"
echo "directory.  It is also necessary to have this server's hostname in the"
echo "/etc/hosts.allow file on the remote mail server for sshd." ; echo

SSH=`which ssh`
GREP=`which grep`
AWK=`which awk`
TAIL=`which tail`
CAT=`which cat`
RM=`which rm`
SED=`which sed`
DUMP=`which mysqldump`
CPIO=`which cpio`
CP=`which cp`
SCP=`which scp`
CUT=`which cut`
HEAD=`which head`
FIND=`which find`

# Get domain name from the command line syntax used...
domain=$1
rhost=$2

# If operator entered no name at the shell prompt, ask for it.
if [ -z "$domain" ] ; then
        echo -n "Enter the domain name to copy: "
        read domain
fi

# If operator entered no name at the shell prompt, ask for it.
if [ -z "$rhost" ] ; then
        echo -n "Enter the destination mail server hostname: "
        read rhost
fi

# Make new account
echo "Adding $domain to $rhost..."
$SSH [EMAIL PROTECTED] "/home/vpopmail/bin/vadddomain -r $domain"
if [ "$?" -ne "0" ] ; then
        echo "Uh oh, that didn't work; aborting."
        exit 1
fi

echo "Determining local Unix pathname of $domain..."

# I know this is ugly as sin, but I couldn't figure out a better way to get
# the pathname into a variable and using awk failed due to a variable conflict.

echo -n "/" > /var/tmp/.localunixpath.txt
/home/vpopmail/bin/vdominfo $domain | $GREP "dir:" | $CUT -d "/" -f 2- | $HEAD 
-1 >> /var/tmp/.localunixpath.txt
localdir=`$CAT /var/tmp/.localunixpath.txt`
grep $domain /var/tmp/.localunixpath.txt > /dev/null
if [ "$?" -ne "0" ] ; then
        echo "Could not determine local pathname for $domain.  You sure $domain 
"
        echo "is on this server?"
        echo ; echo "Exiting" ; echo
        exit 1
fi
$RM -f /var/tmp/.localunixpath.txt
echo "Got it."

echo ; echo "Determining remote Unix pathname of $domain..."
echo -n "/" > /var/tmp/.remoteunixpath.txt
$SSH [EMAIL PROTECTED] /home/vpopmail/bin/vdominfo $domain | $GREP "dir:" | 
$CUT -d "/" -f 2- | $HEAD -1 >> /var/tmp/.remoteunixpath.txt
remotedir=`$CAT /var/tmp/.remoteunixpath.txt`
grep $domain /var/tmp/.remoteunixpath.txt > /dev/null
if [ "$?" -ne "0" ] ; then
        echo "Could not determine $domain Unix pathname on $rhost.  Exiting."
        exit 1
fi
$RM -f /var/tmp/.remoteunixpath.txt
echo "Got it."

echo ; echo "Exporting $domain MySQL vpopmail database table..."
echo "$domain" > /var/tmp/.vpopmail-mysql-table.txt
$SED -i s/\\./_/ /var/tmp/.vpopmail-mysql-table.txt
mysqltable=`$CAT /var/tmp/.vpopmail-mysql-table.txt`
$RM -f /var/tmp/.vpopmail-mysql-table.txt
mysqlfile="/var/tmp/$domain.vpopmail.sql"
$DUMP vpopmail $mysqltable > $mysqlfile

echo ; echo "Changing $localdir to $remotedir in $mysqlfile..."
$SED -i s:"$localdir":"$remotedir":g $mysqlfile

echo ; echo "Changing the same thing in .qmail-default..."
$CP $localdir/.qmail-toaster /var/tmp/.qmail-toaster
$SED -i s:"$localdir":"$remotedir":g /var/tmp/.qmail-toaster 

echo ; echo "Building list of Maildir directories and files..."
cd $localdir
$FIND ./ $domain ! -name '*bspmail*' | $CPIO -o > /var/tmp/$domain.maildir.cpio

echo ; echo "Sending file list and SQL dump to $rhost..."
$SCP /var/tmp/$domain.maildir.cpio [EMAIL PROTECTED]:/var/tmp
# Only delete the temp files if SCP exits successfully
if [ "$?" -eq "0" ] ; then
        $RM -f /var/tmp/$domain.maildir.cpio
fi
$SCP $mysqlfile [EMAIL PROTECTED]:/var/tmp
if [ "$?" -eq "0" ] ; then
        $RM -f $mysqlfile
fi

echo ; echo "Remotely building Maildir skeleton and send .qmail-default file..."
$SSH [EMAIL PROTECTED] "cd $remotedir && cat /var/tmp/$domain.maildir.cpio | 
cpio -idmuR vpopmail:vchkpw"
# Don't delete anything if something went wrong.
if [ "$?" -eq "0" ] ; then
        $SSH [EMAIL PROTECTED] "rm -f /var/tmp/$domain.maildir.cpio"
fi

$SCP -p /var/tmp/.qmail-default [EMAIL PROTECTED]:$remotedir
if [ "$?" -eq "0" ] ; then 
        $RM -f /var/tmp/.qmail-default
fi

echo ; echo "Remotely importing vpopmail MySQL database table for $domain"
# mysqldump files already instruct MySQL server to drop tables if they already
# exist before trying to create them again.
$SSH [EMAIL PROTECTED] "mysql vpopmail < /var/tmp/$domain.vpopmail.sql"
if [ "$?" -eq "0" ] ; then
        $SSH [EMAIL PROTECTED] "rm -f /var/tmp/$domain.vpopmail.sql"
fi

# Message migration...

echo ; echo "Backing up existing e-mail messages..."
$CP -a --target-directory=/var/tmp $localdir
cd /var/tmp/$domain
$FIND ./ -name '*bspmail*' | $CPIO -o > /var/tmp/$domain.messages.cpio
cd /var/tmp
$RM -rf $domain

echo ; echo "Copying mail messages onto $rhost"
echo "This could take a while if this domain is using lots of disk space."

# Since huge amounts of text compresses very easily, and will improve transfer
# speed.
$SCP -C /var/tmp/$domain.messages.cpio [EMAIL PROTECTED]:/var/tmp
# Don't delete unless SSH was successful.
if [ "$?" -eq "0" ] ; then
        $RM -f /var/tmp/$domain.messages.cpio
fi

echo ; echo "Removing individual user .qmail files to prevent random unwanted 
behavior."
$SSH [EMAIL PROTECTED] "find $remotedir -name .qmail -exec rm -f {} \;"

$SSH [EMAIL PROTECTED] "cd $remotedir && cat /var/tmp/$domain.messages.cpio | 
cpio -idmuR vpopmail:vchkpw"
if [ "$?" -eq "0" ] ; then
        $SSH [EMAIL PROTECTED] "rm -f /var/tmp/$domain.messages.cpio"
fi

echo ; echo "$domain copied to $rhost." ; echo
---------------------------------------------------------------------
     QmailToaster hosted by: VR Hosted <http://www.vr.org>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to