Guide updated on 29th of February 2016

Update from an old qmailrocks.org installation


Following instructions supposes you want to migrate your data from a server installed with original qmailrocks.org guide into a server freshly installed following this updated guide

This how to 'll refer to OLD_SERVER (server installed with old qmailrocks guide) and NEW_SERVER (server installed with updated qmailrocks guide)

1 Install synchronisation tool on BOTH servers

aptitude install rsync ssh

2 On OLD_SERVER server : stop apache service (needed for administration tools), backup and copy the vpopmail database

/etc/init.d/apache2 stop
mkdir /backups/
/usr/bin/mysqldump -c -C -e -Q --add-drop-table -uroot -pMySQL_root_password vpopmail | gzip>/backups/vpopmail.sql.gz
scp /backups/vpopmail.sql.gz root@NEW_SERVER:
qmailctl stop

If your installation from original qmailrocks.org was done without MySQL support, you should first convert your installation on OLD_SERVER into a MySQL installation. You can do this with the script vconvert-cdb-sql-big.pl

aptitude install mysql-common mysql-server mysql-client (remember MySQL_root_password)

mysql -pMySQL_root_password

CREATE DATABASE vpopmail;
GRANT select,insert,update,delete,create,drop ON vpopmail.* TO vpopmailuser@localhost IDENTIFIED BY 'VPOPMAIL_PASSWORD';
FLUSH PRIVILEGES;
quit;

chmod +x /downloads/scripts/vconvert-cdb-sql-big (then edit the file and execute it for each of your domains)

2 On OLD_SERVER server : copy config files to NEW_SERVER

cd /var/qmail/control
scp morercpthosts rcpthosts virtualdomains root@NEW_SERVER:/var/qmail/control
cd /var/qmail/users
scp assign root@NEW_SERVER:/var/qmail/users/

3 On OLD_SERVER server : determine UID/GID for some users

grep vpopmail /etc/passwd | cut -d: -f3
We 'll refer this value as VPOPMAILUID later

grep vpopmail /etc/passwd | cut -d: -f4
We 'll refer this value as VCHKPWGID later

This second value should be the same as the result of the command
grep vchkpw /etc/group | cut -d: -f3

4 On NEW_SERVER server : stop mail services and synchronise e-mails

qmailctl stop
gunzip /root/vpopmail.sql.gz
mysql -Dvpopmail -pMySQL_root_password < /root/vpopmail.sql
sed "s/VPOPMAILUID:VCHKPWGID/89:89/g" /var/qmail/users/assign > /var/qmail/users/assign.new
mv /var/qmail/users/assign /var/qmail/users/assign.old
mv /var/qmail/users/assign.new /var/qmail/users/assign
/var/qmail/bin/qmail-newu
/var/qmail/bin/qmail-newmrh
rsync -avz --delete root@OLD_SERVER:/home/vpopmail/domains/ /home/vpopmail/domains/
find /home/vpopmail -uid VPOPMAILUID -exec chown vpopmail {} \;
find /home/vpopmail -gid VCHKPWGID -exec chgrp vchkpw {} \;

5 Edit the file /downloads/scripts/migrate-vpopmail-many-domains (View the script migrate-vpopmail-many-domains) on NEW_SERVER:

DATABASE_ROOT_PASSWORD=MySQL_root_password

Adapt database structure

chmod +x /downloads/scripts/migrate-vpopmail-many-domains
/downloads/scripts/migrate-vpopmail-many-domains

6 Adapt your MX setting in your DNS configuration. Then, execute following command on NEW_SERVER

qmailctl start

That's all folks !

If you need more info or if you need to migrate only some domains, take a look to http://qmail.jms1.net/scripts/migrate-domain.shtml

List of optional features


Users comments
Peter smith - 28/07/2014 03:20

Dear All,

Thanks great. It is my mistake to overall the option of vpopmail-many-domains

Peter smith - 24/06/2014 10:52

Thanks great for your detailed guide. It works.

Due to the other developed programs on the concept of one domain one table, I would like to retain this topology instead of many domains on one table.

I could not locate on the courier section to make this possible.

Please give the hints or any advice.

 

Thank you in advance.

 

Thibs - 05/06/2014 21:42

@BSTD : It was mainly due to the fact my own previous installation was with MySQL ;-)

Bstd - 09/04/2014 03:45

Ooops, it seems an important part of the insert statement below went missing, which leads to a syntax error. The correct script is:

for D in `find /home/vpopmail/domains/ -maxdepth 1 -type d`;

do

  awk -F':' '{split($6, dom,"/"); printf "INSERT INTO vpopmail VALUES ('\'%s\'', '\'%s\'', '\'%s\'', 0, 0, '\'%s\'', '\'%s\'', '\'%s\'', '\'%s\'');\n", $1, dom[5], $2, $5, $6, $7, $8 >> "ALLUSERS.sql";}' < $D/vpasswd;

done;

 

Sorry for any inconvenience...

 

Greets

Bstd - 08/04/2014 06:10

First of all, thank you, Thibs, for this wonderful guide.

Now, I have stumbled across a migration between an old vpopmail version with vpasswd and a new vpopmail with mysql. Personally, I find it useless and inefficient to convert from vpasswd to mysql on the OLD server and then dump the database and transfer it to the new one. So I wrote a cool script to make things a lot simpler. Basically, it creates a list of all the INSERT statements needed to add all users from the OLD server to the new. It also preserves the clear password field, if available. Here it is:

for D in `find /home/vpopmail/domains/ -maxdepth 1 -type d`;

do

  awk -F':' '{split($6, dom,"/"); printf "INSERT INTO vpopmail ('\'%s\'', '\'%s\'', '\'%s\'', 0, 0, '\'%s\'', '\'%s\'', '\'%s\'', '\'%s\'');\n", $1, dom[5], $2, $5, $6, $7, $8 >> "ALLUSERS.sql";}' < $D/vpasswd;

done;

 

So, after executing this code, you have an ALLUSERS.sql file in your current directory. Transfer this file to the NEW server and import it in the vpopmail database. Of course, the other steps described on this page are still required.

 

Greets

Thibs - 16/01/2012 22:19

Jevgenijus : Thanks for the info ! To be honnest I never had the opportunity to test it because my installation was with MySQL

 

 

Jevgenijus - 15/01/2012 14:01

This migration doesn't work correctly from original qmailrocks.org guide without mysql db.

The problem is in vconvert-cdb-sql-big.pl script which create vpopmail table without one field pw_clear_passwd, but migrate-vpopmail-many-domains script use this field in import.

My temp solution was to delete this field and rerun migrate-vpopmail-many-domains script. After that I've added this pw_clear_passwd field.

 


Color Coded Qmail Installation Key
  Regular Black Text     Qmail installation notes and summaries by the author.
  Bold Black Text     Commands to be run by you, the installer.
  Bold/Regular Red Text    Vital and/or critical information.
  Regular Blue text     Denotes helpful tips and hints or hyperlinks.
  Regular Orange Text     Command line output.
  Bold/Regular green text     Denotes the contents of a file or script.