Export all users Address book to a CSV file.

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
Post Reply
laramarket
Posts: 1
Joined: Mon Oct 31, 2022 12:33 pm

Export all users Address book to a CSV file.

Post by laramarket »

Hello,
Is there is any bash script to export all users' contacts (Address book) in csv format? We have 500+ users on our server and I can export only one user contacts at the same time.

Any help is welcome.

Thanks
Juste
karl.b
Zimbra Employee
Zimbra Employee
Posts: 40
Joined: Tue Aug 02, 2022 3:31 pm

Re: Export all users Address book to a CSV file.

Post by karl.b »

You can do it through the REST API (https://wiki.zimbra.com/wiki/Zimbra_REST_API_Reference) and using Curl.

Practical examples...let's assume the admin account is admin@xyzcorp.com with a password of Abcd0000.

curl -k -vv -o /tmp/fred.jones.ics -u admin@xyzcorp.com:Abcd0000 https://somehost.somedomain.com:9071/ho ... ar?fmt=ics
curl -k -vv -o /tmp/mary.martin.ics -u admin@xyzcorp.com:Abcd0000 https://somehost.somedomain.com:9071/ho ... ar?fmt=ics
curl -k -vv -o /tmp/sara.davis.ics -u admin@xyzcorp.com:Abcd0000 https://somehost.somedomain.com:9071/ho ... ar?fmt=ics

So you can see if you iterate through a list of email accounts, your can store the account you are working on as a variable and pass it to the above command line, and you then build a set of .ics files that contains each users calendar data.

for k in `cat 500addresses.lst`; do curl -k -vv -o /tmp/$k.csv -u admin@xyzcorp.com:Abcd0000 https://somehost.somedomain.com:9071/ho ... ts?fmt=csv; done

Other examples for the other structures would be...

curl -k -vv -o /tmp/fred.jones.csv -u admin@xyzcorp.com:Abcd0000 https://somehost.somedomain.com:9071/ho ... ts?fmt=csv
curl -k -vv -o /tmp/fred.jones.xml-u admin@xyzcorp.com:Abcd0000 https://somehost.somedomain.com:9071/ho ... ks?fmt=xml

The -o options, really doesn't matter what you want to name the output file - just be wary that both tasks and calendar are often best exported in .ics format, if so your output file might be .icst for task and .icsc for calendar. The Wiki shows the formats supported for each structure.

If you want to chop into two lists of 250 each, and run two separate for loops in two separate SSH sessions, it's fine (works) - but your 500 won't take that long. Notice I'm using 9071 in the above which points the proxy service on Zimbra if configured as shown here (https://wiki.zimbra.com/wiki/Enabling_A ... sole_Proxy) - else if you have a single server or stand-alone mailstore, you can just point at it using 7071.
Post Reply