Results 1 to 7 of 7

Thread: backup cron job help

  1. #1
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    6

    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.

  2. #2
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    6

    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

  3. #3
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    6

    Default

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

    - Joe

  4. #4
    Join Date
    Nov 2008
    Location
    Montevideo, Uruguay
    Posts
    21
    Rep Power
    6

    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

  5. #5
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    6

    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

  6. #6
    Join Date
    Nov 2008
    Location
    Montevideo, Uruguay
    Posts
    21
    Rep Power
    6

    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

  7. #7
    Join Date
    Nov 2008
    Location
    Montevideo, Uruguay
    Posts
    21
    Rep Power
    6

    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

Similar Threads

  1. Replies: 658
    Last Post: 04-04-2014, 09:01 AM
  2. [SOLVED] Zimbra logwatch.
    By nishith in forum Administrators
    Replies: 5
    Last Post: 06-10-2009, 04:42 PM
  3. [SOLVED] Backups failing, "unable to read metadata for account"
    By smcgrath1111 in forum Administrators
    Replies: 10
    Last Post: 04-10-2008, 03:15 PM
  4. Cron Job
    By mikechansf in forum Administrators
    Replies: 5
    Last Post: 01-29-2007, 11:12 AM
  5. Spam training has no cron job
    By richard-hdd in forum Administrators
    Replies: 3
    Last Post: 09-13-2006, 11:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •