Chinaunix首页 | 论坛 | 博客
  • 博客访问: 25881497
  • 博文数量: 271
  • 博客积分: 10025
  • 博客等级: 上将
  • 技术积分: 3358
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-12 15:28
文章分类

全部博文(271)

文章存档

2010年(71)

2009年(164)

2008年(36)

我的朋友

分类:

2010-05-17 09:39:47

Migrating from Postfix and MySQL with bash

From Zimbra :: Wiki

Jump to: ,

This script will help you to migrate your Postfix+MySQL (and optionally Postfixadmin) installation to Zimbra.

It reads the "mailbox" and "aliases" table used by Postfix with MySQL backend and generates a bash script that will re-create the same email accounts and aliases/forwards on your zimbra server.

Check php.ini in CLI version (not CGI) for: safe_mode = Off

#!/usr/bin/php

// Postfixadmin () to Zimbra
// () migration script
//
// History:
// Based on work from: Jaros�[34m~Baw Czarniak
// Enhanced by NERvOus () on 1-12-2009

 1) {
                // distribution list
                $data_list .= "zmprov cdl $row[0]\n";
                foreach ($dest_r as $dest) {
                        $data_list .= "zmprov adlm $row[0] $dest\n";
                }
        }
        if (count($dest_r) == 1) {
                preg_match('/@(.*)$/', $row[0], $matches);
                $acct_domain = $matches[0];
                preg_match('/@(.*)$/', $dest_r[0], $matches);
                $alias_domain = $matches[0];
                if ($acct_domain == $alias_domain) {
                        // we are adding an alias, not a forward
                        // try to create alias both for a normal
                        // account and for a distribution list. One of the
                        // commands will fail, pity.
                        $data_alias .= "zmprov aaa $dest_r[0] $row[0]\n";
                        $data_alias .= "zmprov adla $dest_r[0] $row[0]\n";
                } else {
                        // we are adding a forward
                        $data_alias .= "zmprov ca $row[0] " . rand_str(11) . "\n";
                        $data_alias .= "zmprov ma $row[0] zimbraprefmailforwardingaddress $dest_r[0]\n";
                }
        }
}

// first create all distribution lists, last all aliases
// We cannot create aliases for distribution lists that do not
// exist yet
fwrite($fh, $data_list . $data_alias);
fclose($fh);


echo "Done.

Now copy exported.sh to zimbra server and run:
# su - zimbra
$ sh ./$file
";


function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')
{
    // Length of character list
    $chars_length = (strlen($chars) - 1);

    // Start our string
    $string = $chars{rand(0, $chars_length)};

    // Generate random string
    for ($i = 1; $i < $length; $i = strlen($string))
    {
        // Grab a random character from our list
        $r = $chars{rand(0, $chars_length)};

        // Make sure the same two characters don't appear next to each
        // other
        if ($r != $string{$i - 1}) $string .=  $r;
    }

    // Return the string
    return $string;
}
?>


Verified Against: unknown Date Created: 12/1/2009
Article ID: Date Modified: 4/2/2010
阅读(1348) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~