[ 来源: | 作者: | 时间:2007-07-21 | 收藏 | 推荐 ] 【大 中 小】
单位的email服务器老的不行了,头头拿了一台稍好一点的机器来代替。 都是sun sparc.
原来sendmail是系统用户,大概在2000左右,现在要转到mysql里面,有关qmail + mysql +vpopmail安装可以去参照本版 peijun.jiang 和 gadfly 的相关文章。
转换工作分成两步:用户迁移 和 mailbox转换
1.用户迁移
我没有在网上找到现成的脚本,就自己写了一个,用perl
#passwd2mysql
#begin
#!/usr/bin/perl
# author: xmubeta <www.chinaunix.net>
# This program convert passwd to mysql vpopmail table. Because i am updating
# mailserver from sendmail to qmail with mysql, i need to retain old user
# information include password and username.
#
#
# it requires DBI,DBD for mysql.
use DBI;
# setup for mysql username and password
http://www.it55.com/
my $MYSQL_VPOPMAIL_SERVER = "localhost";
my $MYSQL_VPOPMAIL_USER = "vpopmail";
my $MYSQL_VPOPMAIL_PASSWD = "passwd";
# end setup for mysql
# setup for vpopmail
my $PW_DOMAIN = "mail.test.com"; # default domain
my $PW_UID = 0;
my $PW_GID = 0;
my $PW_DIR = "/var/vpopmail/domains/${PW_DOMAIN}/"; # MailDir
my $PW_SHELL = "10485760s"; #mail quota
# end setup for vpopmail
#--connect to mysql server
$datasrc = 'DBI:mysql:database=vpopmail;host= ${MYSQL_VPOPMAIL_SERVER}';
$dbh = DBI->connect($datasrc,$MYSQL_VPOPMAIL_USER,$MYSQL_VPOPMAIL_PASSWD,{'Raise
Error' => 1});
$sth = $dbh->prepare("insert into vpopmail (pw_name,pw_domain,pw_passwd,pw_uid,p
vd;k;l www.it55.com rdfg
w_gid,pw_gecos,pw_dir,pw_shell) values (?,'$PW_DOMAIN',?,$PW_UID,$PW_GID,?,?,'$P
W_SHELL')");
#query username,password from /etc/passwd and insert into mysql
while(($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) = getpwent()){
if ($uid < 100) {
print "${name} is system retain user, it will be not converted!\n";
next;
}
if (! $shell) {
print "${name} 's shell is not valid, it will be not converted!\n";
next;
}
(编辑:IT资讯之家 www.it55.com)