Zimbra Archive Server: Difference between revisions
No edit summary |
No edit summary |
||
| Line 56: | Line 56: | ||
# IP of the archive server (archive.example.com) | # IP of the archive server (archive.example.com) | ||
ARCHIP=172.16.1.17 | ARCHIP=172.16.1.17 | ||
# File names of example.com and archive.example.com users | # File names of example.com and archive.example.com users | ||
# MAINLST is the userlist from the main server (example.com) | # MAINLST is the userlist from the main server (example.com) | ||
| Line 62: | Line 61: | ||
MAINLST=mainserverlist | MAINLST=mainserverlist | ||
ARLST=archiveuserlist | ARLST=archiveuserlist | ||
# Emptying out the input file for zmprov | # Emptying out the input file for zmprov | ||
echo "" > /tmp/zmprovarchiv | echo "" > /tmp/zmprovarchiv | ||
# Getting userlist from the archive server | # Getting userlist from the archive server | ||
ssh $ARCHIP 'su -c "zmprov -l gaa | cut -d\@ -f1 > /tmp/archiveuserlist" -l zimbra' | ssh $ARCHIP 'su -c "zmprov -l gaa | cut -d\@ -f1 > /tmp/archiveuserlist" -l zimbra' | ||
rsync -Pa $ARCHIP:/tmp/archiveuserlist /tmp/$ARLIST | rsync -Pa $ARCHIP:/tmp/archiveuserlist /tmp/$ARLIST | ||
# Getting userlist from local (main) server | # Getting userlist from local (main) server | ||
su -c "zmprov -l gaa | cut -d\@ -f1 > /tmp/$MAINLST" -l zimbra | su -c "zmprov -l gaa | cut -d\@ -f1 > /tmp/$MAINLST" -l zimbra | ||
# Sorting the files for comparison | # Sorting the files for comparison | ||
sort /tmp/$MAINLST > /tmp/sorted$MAINLST | sort /tmp/$MAINLST > /tmp/sorted$MAINLST | ||
sort /tmp/$ARLST > /tmp/sorted$ARLST | sort /tmp/$ARLST > /tmp/sorted$ARLST | ||
# Comparing the files, and getting the unique users of the example.com domain | # Comparing the files, and getting the unique users of the example.com domain | ||
# This will get the new users created on example.com, but not present on the archive server | # This will get the new users created on example.com, but not present on the archive server | ||
comm -23 /tmp/sorted$MAINLST /tmp/sorted$ARLST > /tmp/newusers | comm -23 /tmp/sorted$MAINLST /tmp/sorted$ARLST > /tmp/newusers | ||
echo "Checking if there are new users" | echo "Checking if there are new users" | ||
if [ -s /tmp/newusers ]; then | if [ -s /tmp/newusers ]; then | ||
# Loop to read users one by one | # Loop to read users one by one | ||
| Line 92: | Line 85: | ||
# Creates the file for postfix mapping. This file contains users in the form of 'from' and 'to' | # Creates the file for postfix mapping. This file contains users in the form of 'from' and 'to' | ||
awk '{print $1"@triburg.co.in","\t",$1"@archive.triburg.co.in"}' /tmp/newusers >> /opt/zimbra/postfix/conf/archivelist | awk '{print $1"@triburg.co.in","\t",$1"@archive.triburg.co.in"}' /tmp/newusers >> /opt/zimbra/postfix/conf/archivelist | ||
# rsync the zmprov file to the archive server | # rsync the zmprov file to the archive server | ||
rsync -Pa /tmp/zmprovarchiv $ARCHIP:/tmp | rsync -Pa /tmp/zmprovarchiv $ARCHIP:/tmp | ||
# Runs the zmprov command to add users on the archive server | # Runs the zmprov command to add users on the archive server | ||
ssh $ARCHIP 'su -l zimbra -c zmprov < /tmp/zmprovarchiv' | ssh $ARCHIP 'su -l zimbra -c zmprov < /tmp/zmprovarchiv' | ||
# Postmapping on the servers | # Postmapping on the servers | ||
su -c "postmap /opt/zimbra/postfix/conf/archivelist" -l zimbra | su -c "postmap /opt/zimbra/postfix/conf/archivelist" -l zimbra | ||
su -c "postfix reload" -l zimbra | su -c "postfix reload" -l zimbra | ||
else | else | ||
exit | exit | ||
Revision as of 13:53, 22 November 2013
Simple archival server for Zimbra OSE
Introduction
This document shows how to create a simple archiving server. If you have a user 'keyur@example.com', all mails sent to and from this email ID will be forwarded to 'keyur@archive.example.com'. We will need two servers for this. Both will be installed with Zimbra, one being the live mail server 'example.com', and the other the archiving server, 'archive.example.com'. The archiving server should have a much larger HDD drive than the mail server, preferably formatted using LVM, to allow for expansion later.
The installation on each server will be independent, ie, this isn't a multi-server setup. Each server will be a single-server, with the only difference being the domain names.
In this example, let's assume the live server's domain is 'example.com', with IP 192.168.1.5, and the archiving server is 'archive.example.com', with IP 192.168.1.18. Install Zimbra on both as usual.
DNS
The servers will require a local DNS, as we use this to forward the mails. In this example, I will assume that we have set up a caching name server using bind on the live server. Typical entries would be something like this:
example.com. IN A 192.0.43.10 mail.example.com. IN A 192.168.1.5 example.com. IN MX 10 mail.example.com. Along with this, we need to add an A and MX record for archive.example.com as well. archive.example.com. IN A 192.168.1.18 archive.example.com. IN MX 10 archive.example.com. Now all mails addressed to 'archive.example.com' will be forwarded to the archive server.
Postfix
In postfix, we can specify an email address to which all incoming and outgoing mails from a particular email ID will be forwarded to. This is done using 'sender_bcc_maps' and 'recipient_bcc_maps'. All these changes are done only on the main server. We make the following entries at the end of /opt/zimbra/postfix/conf/main.cf
sender_bcc_maps = hash:/opt/zimbra/postfix/conf/archivelist recipient_bcc_maps = hash:/opt/zimbra/postfix/conf/archivelist
The file '/opt/zimbra/postfix/conf/archivelist' will have users in the following format: keyur@example.com keyur@archive.example.com All mails to and from keyur@example.com will be forwarded to keyur@archive.example.com.
Manual addition
Create a user on the main server, and then the corresponding user on the archive server. Then add the users in the format as show above to the file '/opt/zimbra/postfix/conf/archivelist', and then run the postmap command as the zimbra user:
$ postmap /opt/zimbra/postfix/conf/archivelist $ postfix reload
Script
The following script to add users automatically on the archive server, and also to the 'archivelist' file. Run this on the main server, and all users will be automatically added. You can place it in the crontab for every half an hour, so that when a new user is created on the main server, he/she will be automatically added to the archive server. SSH using keys (password-less ssh) between the main and archive server is necessary for the script to function.
#!/bin/bash
# ENSURE ALL THE SERVERS HAVE PASSWORDLESS SSH AUTHENTICATON (Login using keys),
# OR THE SCRIPT WILL FAIL
# -----------------------------------------------------------------------------
# Zimbra Archiving
#
# This script will add users that are present on the main Zimbra server, but not
# on the archival server. It will also make the appropriate changes in postfix.
# ------------------------------------------------------------------------------
# IP of the archive server (archive.example.com)
ARCHIP=172.16.1.17
# File names of example.com and archive.example.com users
# MAINLST is the userlist from the main server (example.com)
# ARLST is the userlist from the archive server (archive.example.com)
MAINLST=mainserverlist
ARLST=archiveuserlist
# Emptying out the input file for zmprov
echo "" > /tmp/zmprovarchiv
# Getting userlist from the archive server
ssh $ARCHIP 'su -c "zmprov -l gaa | cut -d\@ -f1 > /tmp/archiveuserlist" -l zimbra'
rsync -Pa $ARCHIP:/tmp/archiveuserlist /tmp/$ARLIST
# Getting userlist from local (main) server
su -c "zmprov -l gaa | cut -d\@ -f1 > /tmp/$MAINLST" -l zimbra
# Sorting the files for comparison
sort /tmp/$MAINLST > /tmp/sorted$MAINLST
sort /tmp/$ARLST > /tmp/sorted$ARLST
# Comparing the files, and getting the unique users of the example.com domain
# This will get the new users created on example.com, but not present on the archive server
comm -23 /tmp/sorted$MAINLST /tmp/sorted$ARLST > /tmp/newusers
echo "Checking if there are new users"
if [ -s /tmp/newusers ]; then
# Loop to read users one by one
for newuser in `cat /tmp/newusers`; do
# Creating a file that will be the input for zmprov.
# This will create the new user accounts on the archive server.
# The user's passwords have been set to 'very_secure_PW_31812'
echo "ca $newuser@archive.triburg.co.in very_secure_PW_31812" >> /tmp/zmprovarchiv
done
# Creates the file for postfix mapping. This file contains users in the form of 'from' and 'to'
awk '{print $1"@triburg.co.in","\t",$1"@archive.triburg.co.in"}' /tmp/newusers >> /opt/zimbra/postfix/conf/archivelist
# rsync the zmprov file to the archive server
rsync -Pa /tmp/zmprovarchiv $ARCHIP:/tmp
# Runs the zmprov command to add users on the archive server
ssh $ARCHIP 'su -l zimbra -c zmprov < /tmp/zmprovarchiv'
# Postmapping on the servers
su -c "postmap /opt/zimbra/postfix/conf/archivelist" -l zimbra
su -c "postfix reload" -l zimbra
else
exit
fi
Made By
Abhinav Sharma