Zimbra: backup mailboxes script

Zimbra: backup mailboxes script

Zimbra: backup mailboxes script 150 150 Roderick Derks

Works on ZCS 7. Only active mailboxes from real active user accounts are backed up. Very simple, works great.

 

Create a cert file so scp can login to your backup server without asking the password. For instructions click here. Run the script as root, if you want to run it as zimbra remove the su – zimbra code including the ” that go with that.

#!/bin/bash
#################################
# Zimbra Mailbox Backup         #
# By: Roderick Derks            #
# Date: 01-02-2012              #
#################################

export dir=/tmp/zimbra_mailbox_backup

if [ ! -d $dir ] ; then
   mkdir $dir
   chmod 777 $dir
fi

rm -rf $dir/*

su – zimbra -c “zmaccts | grep “@” | grep -v never|grep -i active | awk ‘{print $1}’ > $dir/user.txt”
user=( `cat $dir/user.txt | awk ‘{print $1}’ ` )
date=`date -I`

for i in “${user[@]}”
do
    echo mailbox currently being exported: $i
    eval “su – zimbra -c “zmmailbox -z -m $i getRestURL “//?fmt=tgz” > $dir/$date.$i.tgz””
    wait
done

#echo remove empty files
#find $dir/ -type f -size 0 | xargs rm

echo
echo scp files to freenas
scp $dir/* root@freenas:/mnt/DATA/Backup/Zimbra/

echo setting rights
ssh root@freenas ‘chmod 777 /mnt/DATA/Backup/Zimbra/*’
ssh root@freenas ‘chown root:wheel /mnt/DATA/Backup/Zimbra/*’

echo done

Roderick Derks

Liefhebber van fietsen, van het oplossen van IT puzzels, en van het delen van informatie om anderen te helpen.

All stories by:Roderick Derks

Leave a Reply

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

    Your Name (required)

    Your Email (required)

    Subject

    Your Message

      Your Name (required)

      Your Email (required)

      Subject

      Your Message