Friday, 4 October 2013

Scripts Used for Mail Migration from Qmail to Sendmail

Please follow My blog for Sendmail Installation and then follow these scripts to migrate Qmail Users on Sendmail. Here i used Mailbox format Maildir in migration.


The Mail User Credentials file for Qmail domain users resides into /home/vpopmail/domains/<domain name>/vpasswd file. Here I will migrate test user of Qmail to Sendmail server.

Example:
[root@qmail ~]# cat /home/vpopmail/domains/example.com/vpasswd

test:$1$r8OZxMDG$uqwnzkwkLaUQR2hWHeldK.:1:1:TEST:/home/vpopmail/domains/example.com/0/test:NOQUOTA:ComplexPassword

Description:-

Username: test
Encrypted Password: $1$r8OZxMDG$uqwnzkwkLaUQR2hWHeldK
Description: TEST
Home directory: :/home/vpopmail/domains/example.com/0/test
Quota: NOQUOTA
Clear Password: ComplexPassword


1.       I saved all Qmail accounts into userlist file on Sendmail server and create a script to create all users on sendmail server.

[root@mail01 scripts]# vi user_create

#/bin/bash

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

for i in `cat userlist`
 do
   echo $i > 4
   cat 4

   mailid=$(awk -F":" '{print $1}' 4)
   username=$(awk -F":" '{print $5}' 4)
   password=$(awk -F":" '{print $4}' 8)

 # User Creation on Mail Server

useradd -c "$username" -m -d /home/$mailid -s /sbin/nologin $mailid ; echo $password | passwd --stdin $mailid

done
IFS=$SAVEIFS


2.       Run rsync command on Qmail Server to sync all data from Qmail Server to Sendmail Server.

# rsync –avz  /home/vpopmail/domains/<DomainName>/      <Sendmail IP>:/home/


3.       Change permission on Sendmail Server.

[root@mail01 scripts]#  chown  root.root  /home
[root@mail01 scripts]#  chmod 755 /home

4.       To change Permission of Users home directory on Sendmail server,  Create a list of users into accounts file.

On Qmail:

[root@qmail ~]# cat /home/vpopmail/domains/example.com/vpasswd | cut –d: -f1 > acccounts
[root@qmail ~]#scp accounts  <sendmail IP>:/scripts/accounts

On Sendmail:

[root@mail01 scripts]# vi /scripts/accounts
test
jitendrakumar
.
.
.

5.       Create Script to change Permission of users on their home directories.

[root@mail01 scripts]# vi perm_change

#!/bin/bash

for i in `cat accounts`
do
 id $i
 if [ $? == 0 ]
   then
      chown -R $i.$i /home/$i
   else
     echo " User *****$i***** doesn't exist"
     echo $i >> /scripts/noid
fi

done

No comments:

Post a Comment