-
-
Save rwjblue/3790858 to your computer and use it in GitHub Desktop.
sudo su - zimbra | |
# list all accounts and print out account name and aliases | |
for i in `zmprov -l gaa` ; do zmprov ga $i zimbraMailAlias ; done | |
# list all distribution lists and any members and/or aliases | |
for i in `zmprov gadl` ; do zmprov gdl $i zimbraMailAlias zimbraMailForwardingAddress ; done |
It's an ugly solution to spawn a new zmprov instance for every account.
A better solution is to use the output from zmprov gaa to prepare a sequence of ga commands for zmprov and ingest it back into another zmprov process. The idea looks somewhat like this (it doesn't save the addresses themselves so you might want to run the gaa another time just to get the primary emails; or you might want to save them to a variable first, whatever):
zmprov -l gaa | sed 's/.*/ga & zimbraMailAlias/' | zmprov
The difference in running time is huge.
$ time (zmprov -l gaa | sed 's/.*/ga & zimbraMailAlias/' | zmprov > /dev/null)
real 0m6.570s
user 0m16.566s
sys 0m1.771s
$ time (for i in `zmprov -l gaa`; do zmprov ga $i zimbraMailAlias; done > /dev/null)
real 3m41.123s
user 8m2.881s
sys 0m47.298s
And I have only 47 accounts in my zimbra.
Hello, I am trying to migrate the aliases from an old server to a modern server, exporting the aliases has been easy, I have done it this way.
I create the entire mailing list of any zimbra domain
su zimbra
zmprov -l gaa >emails.txt
I get the list of the aliases of the email accounts this way
mkdir -p alias/
chown -R zimbra:zimbra alias/
su zimbra
for i in cat emails.txt
; do zmprov ga $i | grep zimbraMailAlias |awk '{print $2}' > alias/$i.txt ;echo $i ;done
Once I have the aliases for each email account, we proceed to delete the email files that do not have any aliases in this way from the list.
find alias/ -type f -empty | xargs -n1 rm -v
Now I upload the files obtained that are emails.txt and the directory of /alias to the destination server, and here is where I have the error, I have made a script to perform the upload but I think I'm doing it wrong, I do not know if it is for permissions or otherwise, the script is this.
#!/bin/bash
for i in cat /opt/zimbra/migracion/emails.txt
do
if [ -f "alias/$i.txt" ]; then
for j in grep '@' /opt/zimbra/migracion/alias/$i.txt
do
zmprov aaa $i $j
echo "$i HAS ALIAS $j --- Restored"
done
fi
done
Can you tell me what mistake I am making?
Greetings and thanks
the better syntax should be
for i in
zmprov -l gaa
; do zmprov -l gaa $i displayName description; done > /home/cobain-donk.txt