Zimbra Distribution Lists Disappearing Issue
Welcome! In this post, I’m once again going to discuss about Zimbra Collaboration Suite. This is about an incident that I recently came across, in which some of the mail distribution lists of one of our clients got automatically removed from the system. On doing some research, I learned that this type of issue was faced in past versions of ZCS, and had been resolved long ago. However, in this case, our client had the latest ZCS version of the date i.e. ZCS 8.6 with patch 6. I asked about this issue in the forums but it seemed no one else was facing this issue in the similar version. So, couldn’t find any help there. But I faced the same issue on the similar setup (ZCS 8.6 on CentOS 7 Minimal) in my own lab environment as well.
Keeping the critical nature of this problem in mind, I had to come up with at least a curative measure, if preventive solution not available, for this issue. Therefore, I got an idea and created a script that will monitor the status of all of the distribution lists in Zimbra server. Doing this will regularly check if any distribution list was missing from the system by comparing it with the previous backup and then will restore any missing distribution list to the server.
This idea was executed in following steps:
- Backing up previous list of distribution lists if available
- Taking backup of the current list of distribution lists
- Comparing previous list and current list of distribution lists
- If the comparison returns non-empty result, it’ll consider that some distribution lists have been missing
- If distribution lists are missing, those distribution lists are restored
- After restoring distribution lists, their corresponding member accounts will also be restored based on previous backup
- After completing restoration, the script will again backup the list
- The script written for this purpose was then set to run in every 4 hours using Cronjob
Here’s a script I wrote to solve this issue:
#!/bin/bash # Name: monitor_dls.sh # Author: Sajjan Bhattarai # Date: 5th August 2016 # Description: Script to monitor and restore the missing Distribution lists and their members from Zimbra server. # Checking if a backup folder is provided. If not, it is set to /tmp/Backup. if [ $# -gt 0 ]; then DIR="$1" else DIR="/tmp/Backup" fi LOGFILE="$DIR"/logfile # Function to restore account to a Distribution List function add_to_dl { dl=$1 account=$2 if [[ ${account} == *"@"* ]]; then echo "Adding member $account..." add=$(su - zimbra -c "zmprov adlm $dl $account") if [ $? -eq 0 ] then echo "$(date): $account added to $dl" >> "$LOGFILE" else echo "$(date): $account failed to add to $dl: $add" >> "$LOGFILE" fi fi } # Function to restore distribution list function restore_dl { mdl=$1 output=$(su - zimbra -c "zmprov cdl $mdl") if [ $? -eq 0 ] then echo "Success!" echo "$(date): $mdl restored" >> "$LOGFILE" echo "Restoring members of DL: $mdl..." while IFS='' read -r mem || [[ -n "$mem" ]]; do add_to_dl $mdl $mem done < "$DIR"/dls/"$mdl" else echo "Failed!" echo "$(date): Failed to restore $mdl: $output" >> "$LOGFILE" fi } # Check if the backup folder exists. If not, create one if [ ! -d "$DIR" ]; then mkdir "$DIR" fi if [ ! -d "$DIR"/dls ]; then mkdir -p "$DIR"/dls chown -R zimbra:zimbra "$DIR" fi if [ ! -d "$DIR"/dls.old ]; then mkdir -p "$DIR"/dls.old chown -R zimbra:zimbra "$DIR" fi # Backing up Distribution Lists echo "Creating backup of older list..." mv "$DIR"/dl.list "$DIR"/dl.list.old echo "Getting current list of distribution list..." su - zimbra -c "zmprov gadl > "$DIR"/dl.list" if [ $? -eq 0 ] then echo "Successful!" else echo "Failed!" fi # Check for missing DLs output=$(awk 'NR==FNR{a[$0]=1;next}!a[$0]' "$DIR"/dl.list "$DIR"/dl.list.old) echo $output > "$DIR"/missing_dls missing_dls_count=$(tr -d "\r\n" < "$DIR"/missing_dls | wc -c) if [ $missing_dls_count -gt 0 ] then echo "$missing_dls_count distribution list missing!" while IFS='' read -r mdl || [[ -n "$mdl" ]]; do echo "Restoring missing DL: $mdl..." restore_dl $mdl done < "$DIR"/missing_dls else echo "Distribution lists ok." fi
I made it executable as follows:
[root@mail ~]# chmod +x monitor_dls.sh
Then, I added it to run as cronjob after every 4 hours.
[root@mail ~]# crontab -e 0 0,4,8,12,16,20 * * * /root/monitor_dls.sh
In this way, I got around the problem I was facing. I hope it was informative and helpful for you. Please let me know of your query or suggestion in the Comments section below. Thank you!