Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Administrators

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-24-2008, 05:32 AM
Junior Member
 
Posts: 8
Unhappy HELP! Backup cron job not working!

I have Zimbra ZCS 5.0.10 running in an Ubuntu 8.04 virtual machine on an older Windows 2000 server. In order to backup Zimbra each evening, I've setup a cron job to run a script called zimbraNightlyBackup.sh:

Code:
sudo -u zimbra /opt/zimbra/bin/zmcontrol stop
tar -czf /media/zimbraNightlyBackupCache/zimbraNightlyBackup.tar.gz /opt/zimbra
sudo -u zimbra /opt/zimbra/bin/zmcontrol start
zimbrNightlyBackup.sh is in /root/cronscripts/. "/media/zimbraNightlyBackupCache/" is a CIFS automounted samba volume on the W2K server. It works great when I run it from the console as root, but doesn't seem to work right when run as a cron job.

When I run the script from the console as root, the resulting tar.gz winds up being about ~800MB, and mail services shutdown and come back up properly.

When run as a cron job, it takes down mail services, creates a ~200MB tar.gz, and then never starts mail services again. I can't seem to find anything in my logs that's telling me what's going on.

Any ideas?

- Joe

Last edited by jsauve; 11-24-2008 at 08:23 AM..
Reply With Quote
  #2 (permalink)  
Old 11-24-2008, 09:16 AM
Junior Member
 
Posts: 8
Default

I think I figured it out...one of the most common n00b mistakes, I'm sure. I forgot "#!/bin/bash" at the top of my script. That would explain why it worked from from the console, but freaks running as a cron job...it's probably running in the cshell!!! DUH!!!

- Joe
Reply With Quote
  #3 (permalink)  
Old 11-24-2008, 09:14 PM
Junior Member
 
Posts: 8
Default

Hmmm...still not working. Any ideas, folks? I'm really struggling to understand what's going wrong.

- Joe
Reply With Quote
  #4 (permalink)  
Old 12-22-2008, 05:58 PM
Member
 
Posts: 14
Default

I'm having similar problems. It's seems to me that zmcontrol doesn't works well when run from cron or the screen command.
See this link http://www.zimbra.com/forums/adminis...tml#post119624

Hope we can help each other
__________________
A/P Andrés Tarallo
Montevideo, Uruguay
Reply With Quote
  #5 (permalink)  
Old 12-22-2008, 10:49 PM
Junior Member
 
Posts: 8
Default

Hi Andres,

I did indeed figure out my problems, and I perhaps I can help you.

To use zmcontrol within my cron-enabled bash script, I'm using
Code:
su - zimbra -c /opt/zimbra/bin/zmcontrol start
to start up the zimbra services using the "zimbra" user.

Since I never followed up when I figured it out (which was just a few days ago), I'll post my whole script here. Notice the two things that solved my problems:
  1. Explicitly set your environment variables in the head of the script
  2. rsync the zimbra folder BEFORE trying to tar it

(heinzg is credited for large portions of this script)
I'm using Ubuntu Server 8.04
Code:
#!/bin/bash

SHELL=/bin/bash
TERM=xterm
USER=root
USERNAME=root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
MAIL=/var/mail/joe
LANG=en_US.UTF-8
HOME=/root
LOGNAME=root

# the zimbra user
ZM_USER=zimbra
# the zimbra folder to be backed up
ZM_HOME=/opt/zimbra/
# a temporary directory rsyncing
BACKUP_CACHE=/root/zimbraNightlyBackupCache/
# the CIFS-mounted folder on out W2K server with tape backup
BACKUP_DEST=/media/zimbraNightlyBackupCache/
# just a folder for logging/troubleshooting the individual backup script actions
BACKUP_LOGS=/root/zimbrabackuplogs/

# Stopping Zimbra
        echo "Stopping the Zimbra server"
        echo

# Disable zimbra user's crontab, we don't want it starting any jobs while we backup
        crontab -u $ZM_USER -l > "$ZM_HOME"crontab.org
        if [ "$?" -ne "0" ]
        then
            echo "could not backup "$ZM_USER"'s crontab..."
            echo "continuing without changing users crontab!"
            # cat $LOG | mail -c $EMAILCC -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
            exit 1
        else
            touch "$ZM_HOME"crontab.blank
            crontab -u $ZM_USER "$ZM_HOME"crontab.blank
            rm "$ZM_HOME"crontab.blank
        echo "Deactivated "$ZM_USER"'s cronjobs"
            echo
        fi

# Stop Zimbra services
su - $ZM_USER -c $ZM_HOME"bin/zmcontrol stop"
        if [ "$?" -eq "1" ]
        then
            echo "zmcontrol shutdown had an error!"
            # cat $LOG | mail -c $EMAILCC -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
            exit 1
        else
            echo
            echo "Zimbra server has stopped "
        fi
        echo

# Find any leftover Zimbra processes and kill them
        sleep 5
        echo "kill any left over $ZM_USER procs"
        PROX=(`ps -u $ZM_USER | awk '{print $1}' | grep -v PID`)
        if [ "$PROX" ]
        then
            ps -u $ZM_USER | awk '{print $1}' | grep -v PID | xargs kill -s 15
            echo "assassinated some left over procs..."
            echo
        else
            echo "Nothing to kill"
            echo
        fi

/bin/sleep 2

# rsync the zimbra directory to a temporary location
/usr/bin/nice -19 /usr/bin/rsync -avHK "$ZM_HOME" "$BACKUP_CACHE"zimbra > "$BACKUP_LOGS"rsync.log 2>&1

/bin/sleep 2

# Reinstate zimbra user's crontab
        crontab -u $ZM_USER "$ZM_HOME"crontab.org
        if [ "$?" -ne "0" ]
        then
            echo "!!Could not reinstate "$ZM_USER"'s crontab!!"
            echo "Please do this manually!"
            # cat $LOG | mail -c $EMAILCC -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
            exit 1
        else
            echo "Reinstated "$ZM_USER"'s cronjobs"
            echo
        fi

# Start Zimbra services back up
        su - "$ZM_USER" -c $ZM_HOME"bin/zmcontrol start"
        if [ "$?" -ne "0" ]
        then
            echo "There was an error starting Zimbra!"
            # cat $LOG | mail -c $EMAILCC -s "Zimbra backup error on `hostname --fqdn`" $EMAIL
            exit 1
        else
            echo
            echo "Zimbra has started"
        fi

/bin/sleep 2

# tar and gzip the zimbra copy
/bin/tar -zcvf "$BACKUP_CACHE"zimbraNightlyBackup_$(date +%F).tgz "$BACKUP_CACHE"zimbra > "$BACKUP_LOGS"tgz.log 2>&1

/bin/sleep 2

# obliterate yesterday's backup file from remote folder because it is now on yesterday's backup tape (or at least it SHOULD be)
/bin/rm -f "$BACKUP_DEST"zimbraNightlyBackup*

/bin/sleep 2

# move our gzipped backup to the w2kserver so that it may be picked up by the tape drive
/bin/mv -v "$BACKUP_CACHE"zimbraNightlyBackup_$(date +%F).tgz "$BACKUP_DEST"zimbraNightlyBackup_$(date +%F).tgz  > "$BACKUP_LOGS"mv.log 2>&1

# remove temporary rsync directory
/bin/rm -fr "$BACKUP_CACHE"zimbra
Reply With Quote
  #6 (permalink)  
Old 01-06-2009, 05:14 AM
Member
 
Posts: 14
Default Issues in the backup script

I've tested this backup script. It runs flawlesly from the command line.

At least in Ubunto 8.04.1 it crashes when runned from cron, in root crontab.

So we're running it from a remote machine as an interactive session. Since we're in a Windows 200x environment we run the script with plink, part of the Putty suite.
__________________
A/P Andrés Tarallo
Montevideo, Uruguay
Reply With Quote
  #7 (permalink)  
Old 01-23-2009, 07:10 AM
Member
 
Posts: 14
Default Backups running

Running from the schedulled tasks of windows 2000 with plink works. We've been backuping fine for about two weeks
__________________
A/P Andrés Tarallo
Montevideo, Uruguay
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.