I've seen a lot of questions about Community version backups. Here's a routine I worked out, perhaps it can help someone or at least give some ideas.
I had the problem of backing up (daily) a group of 50 users' mailboxes and taking the server down by doing a cold backup is not really an option. I am using the community version. I am not a Linux guru by any means, however was able to fashion the following scripts that function just fine for my needs, and perhaps can help someone else looking for a similar functionality. I am also up for any "professionalization" that can be done by the real Linux guys seemingly abundant in the Zimbra cosmos.
I am using several steps here. First, a script to export a single user account using zmmailbox. This is used by the next script.
Scripts assume the presence of a /backup/ directory and sub directory /backup/accounts. These could be variables I guess if someone wanted to make a generic version.
Code:
#!/bin/bash
# baccount.sh -- Script to export select Zimbra accounts
USERNAME=$1
TODAY=`date`
LOGFILE="/backup/log/backuplog.txt"
echo $TODAY >> $LOGFILE
echo $USERNAME >> $LOGFILE
/opt/zimbra/bin/zmmailbox -z -m $USERNAME gms >> $LOGFILE
/opt/zimbra/bin/zmmailbox -z -m $USERNAME getRestURL "//?fmt=tgz" > /backup/accounts/$USERNAME.tgz
echo --------------------- >> $LOGFILE
The above is called using ./baccount.sh
username@zimbradomain.com and outputs a file
username@zimbradomain.com.tgz to the directory specified. You could use the TODAY variable to prefix the filename if you wanted unique file names (no overwrite).
The script to put this together is as follows.
Code:
#!/bin/bash
# get a list of all the accounts and create a script to
# execute the baccount.sh script with the email address
# of the user as a command line variable
#use zmaccts and extract only the email address from the result
#then concatenate the "/backup/./baccount.sh <emailaddress>" string for each account and write it to the file
/opt/zimbra/bin/./zmaccts | grep "@" | awk '{print "/backup/./baccount.sh " $1}' > /backup/accountbackup.sh
# change permissions on the newly created script
chmod 755 /backup/accountbackup.sh
# Execute the newly created script - this creates a tgz file for each account
/backup/./accountbackup.sh
# this mounts an SMB drive of a neighboring win machine and copies the backups over - could be anything
# mount -t smbfs -o username=username,password=password //windowsMachineName/windowsShare /data
# cp /backup/accounts/*.tgz /data The above script queries Zimbra for a list of users and generates a shell script called /backup/accountbackup.sh,
changes permissions on the newly created shell script and executes it, calling the baccount.sh script for each email address in the system and subsequently generating a complete mailbox export for each account.
In my example, it then mounts a remote smb volume and copies the backups off-server.
To restore one of these accounts, I use the command:
Code:
/opt/zimbra/bin/zmmailbox -z -m UserEmailAddress postRestURL "//?fmt=tgz&resolve=reset" /backup/accounts/UserEmailAddress.tgz
I am sure this can all be made more generic and probably simplified, but I have found the flexibility of having these individual mailbox backups to be very very handy when coupled with a weekly full system backup. This procedure is run nightly.
The restore functions best when restored to an empty, newly created account.
Perhaps this can help someone.
Cheers