iredmail-migration-from-qmail-with-emails-and-mail-box

  1. Log on to qmail server and export user account to csv and copy that file to new iredmail server.
    #mysql -uvpopmail vpopmail -pPassW0rd -e ” select pw_name,pw_gecos,pw_clear_passwd from test_com ” | sed ‘s/\t/”,”/g;s/^/”/;s/$/”/’ > migration_list.csv
    #cat migration_list.csv
    raja.kc,raja ram kc (mc),1raja23
  2. login to iredmail server iRed source file to tools
    #cd /root/iRedMail-0.9.5-1/tools
    #cat >create_mail_user_sql_migration.sh
  3. [[email protected] tools]# cat >create_mail_user_sql_gen.sh

    #!/usr/bin/env bash

USERS_FILE=”/home/satya/migration_list.csv”

###

STORAGE_BASE_DIRECTORY=”/home/vmail/vmail1″

###########

# Password

#

# Password scheme. Available schemes: BCRYPT, SSHA512, SSHA, MD5, NTLM, PLAIN.

# Check file Available

PASSWORD_SCHEME=’SSHA’

# Default mail quota.

DEFAULT_QUOTA=’1024′ # 1024 = 1024M

# hashed -> domain.ltd/u/us/use/username/

# normal -> domain.ltd/username/

# Default hash level is 3.

MAILDIR_STYLE=’hashed’ # hashed, normal.

#MAILDIR_STYLE=’normal’ # hashed, normal.

# Time stamp, will be appended in maildir.

DATE=”$(date +%Y.%m.%d.%H.%M.%S)”

STORAGE_BASE=”$(dirname ${STORAGE_BASE_DIRECTORY})”

STORAGE_NODE=”$(basename ${STORAGE_BASE_DIRECTORY})”

# Path to SQL template file.

SQL=”output.sql”

echo ” > ${SQL}

while read line

do

username=$(echo $line | awk -F ‘,’ ‘{print $1}’)

fullname=$(echo $line | awk -F ‘,’ ‘{print $2}’)

DEFAULT_PASSWD=$(echo $line | awk -F ‘,’ ‘{print $3}’)

# Get domain name.

DOMAIN=”mawnepal.com”

mail=”${username}@${DOMAIN}”

# Cyrpt default password.

export CRYPT_PASSWD=”$(python ./generate_password_hash.py ${PASSWORD_SCHEME} ${DEFAULT_PASSWD})”

# Different maildir style: hashed, normal.

if [ X”${MAILDIR_STYLE}” == X”hashed” ]; then

length=”$(echo ${username} | wc -L)”

str1=”$(echo ${username} | cut -c1)”

str2=”$(echo ${username} | cut -c2)”

str3=”$(echo ${username} | cut -c3)”

if [ X”${length}” == X”1″ ]; then

str2=”${str1}”

str3=”${str1}”

elif [ X”${length}” == X”2″ ]; then

str3=”${str2}”

else

:

fi

# Use mbox, will be changed later.

maildir=”${DOMAIN}/${str1}/${str2}/${str3}/${username}-${DATE}/”

else

# Use mbox, will be changed later.

maildir=”${DOMAIN}/${username}-${DATE}/”

fi

cat >> ${SQL} <<EOF

INSERT INTO mailbox (username, password, name,

storagebasedirectory,storagenode, maildir,

quota, domain, active, local_part, created)

VALUES (‘${mail}’, ‘${CRYPT_PASSWD}’, ‘${fullname}’,

‘${STORAGE_BASE}’,’${STORAGE_NODE}’, ‘${maildir}’,

‘${DEFAULT_QUOTA}’, ‘${DOMAIN}’, ‘1’,’${username}’, NOW());

INSERT INTO alias (address, goto, domain, created, active)

VALUES (‘${mail}’, ‘${mail}’,’${DOMAIN}’, NOW(), 1);

EOF

done <$USERS_FILE

cat <<EOF

EOF

4. SQL output.sql will be generated

#cat output.sql

INSERT INTO mailbox (username, password, name,

storagebasedirectory,storagenode, maildir,

quota, domain, active, local_part, created)

VALUES (‘[email protected]’, ‘{SSHA}VA2gTXTO74rwD4xJMcRbrAkHmSGuB8wUE0m+0w==’, ‘raja ram kc (mc)’,

‘/home/vmail’,’vmail1′, ‘test.com/r/a/j/raja.kc-2016.08.29.22.59.38/’,

‘1024’, ‘test.com’, ‘1’,’raja.kc’, NOW());

INSERT INTO alias (address, goto, domain, created, active)

VALUES (‘[email protected]’, ‘[email protected]’,’test.com’, NOW(), 1);

5.import sql file to your iredmail db

#mysql -u root [email protected] vmail < output.sql

All the user’s have been imgrated with their old credicitails test in iredmail.

Leave a Reply

Your email address will not be published.