How To Export/Import Filter on Zimbra Mail Server

Posted by

Filter is one of many attribute that should be migrate from old Zimbra to the new Zimbra. After previously success migrating Signature from old to the new Zimbra, this is what i do for migrating filter from old to the new Zimbra.

Export (on the old Zimbra)

cd /srv/
mkdir filter
vi export-filter.sh

Fill with the following line

#!/bin/bash

clear

echo "Retrieve zimbra user name..."

USERS=`su - zimbra -c 'zmprov -l gaa | sort'`;

for ACCOUNT in $USERS; do
NAME=`echo $ACCOUNT`;
filter=`su - zimbra -c "zmprov ga $NAME zimbraMailSieveScript" > /tmp/$NAME`

sed -i -e "1d" /tmp/$NAME
sed 's/zimbraMailSieveScript: //g' /tmp/$NAME > filter/$NAME
rm /tmp/$NAME
echo "Export filter for $NAME..."
done
echo "All filter has been export successfully"

Save and execute the script

chmod +x /srv/export-filter.sh
sh /srv/export-filter.sh

results of the above script are all file which is located in /srv/filter folder. Copy filter folder (and all files) to the new Zimbra

Import (on the new Zimbra)

Assuming filter folder (from old Zimbra) is placed in /srv/ folder. Make a script for import filter

cd /srv/
vi import-filter.sh

Fill with the following line

for file in /srv/filter/*
do
StrFilter=`cat "$file"`
Acc=`echo $file | cut -d "/" -f5`
su - zimbra -c "zmprov ma $Acc zimbraMailSieveScript '$StrFilter'"
echo "Process filter $Acc"
done
echo "All filter has been import successfully"

Please wait script until done and check either account who has filter.

Good luck and hopefully useful 😀

7 comments

  1. Hello Immanudin,

    I receive following error while importing the filter.

    Proses filter
    usage: modifyAccount(ma) {name@domain|id} [attr1 value1 [attr2 value2…]]
    For general help, type : zmprov –help
    Proses filter
    usage: modifyAccount(ma) {name@domain|id} [attr1 value1 [attr2 value2…]]
    For general help, type : zmprov –help

  2. same.
    Process filter
    usage: modifyAccount(ma) {name@domain|id} [attr1 value1 [attr2 value2…]]
    For general help, type : zmprov –help
    Process filter
    usage: modifyAccount(ma) {name@domain|id} [attr1 value1 [attr2 value2…]]
    For general help, type : zmprov –help
    Process filter
    usage: modifyAccount(ma) {name@domain|id} [attr1 value1 [attr2 value2…]]
    For general help, type : zmprov –help

  3. sample of export file

    require [“fileinto”, “reject”, “tag”, “flag”];
    # sales
    if anyof (address :all :is :comparator “i;ascii-casemap” [“from”] “sales@xyz.com”) {
    fileinto “/sales/sales”;
    stop;
    }

    # hod
    if anyof (address :all :is :comparator “i;ascii-casemap” [“from”] “hod@xyx.com”) {
    fileinto “SACHIN”;
    stop;
    }

  4. my sample export
    # nagios1
    if allof (address :all :contains :comparator “i;ascii-casemap” [“from”] “nagios@dms.kenic.or.ke”) {
    fileinto “Inbox/nagios”;
    stop;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.