Results 1 to 4 of 4

Thread: Backup help needed. Using "Simple Shell Script Method"

  1. #1
    physikal is offline Loyal Member
    Join Date
    Apr 2009
    Posts
    90
    Rep Power
    5

    Default Backup help needed. Using "Simple Shell Script Method"

    So currently my script looks like:

    Code:
     #!/bin/bash
     
     # Zimbra Backup Script
     # Requires ncftp to run
     # This script is intended to run from the crontab as root
     # Date outputs and su vs sudo corrections by other contributors, thanks, sorry I don't have names to attribute!
     # Free to use and free of any warranty!  Daniel W. Martin, 5 Dec 2008
    
     
     # Outputs the time the backup started, for log/tracking purposes
     echo Time backup started = $(date +%T)
     before="$(date +%s)"
    
     # Live sync before stopping Zimbra to minimize sync time with the services down
     # Comment out the following line if you want to try single cold-sync only
     rsync -avHK --delete /opt/zimbra/ /backup/zimbra
    
     # which is the same as: /opt/zimbra /backup 
     # Including --delete option gets rid of files in the dest folder that don't exist at the src 
     # this prevents logfile/extraneous bloat from building up overtime.
    
     # Now we need to shut down Zimbra to rsync any files that were/are locked
     # whilst backing up when the server was up and running.
     before2="$(date +%s)"
     backupdate="$(date +%F)"
    
     # Stop Zimbra Services
     su - zimbra -c"/opt/zimbra/bin/zmcontrol stop"
     sleep 15
    
     # Kill any orphaned Zimbra processes
     kill -9 `ps -u zimbra -o "pid="`
    
     # Only enable the following command if you need all Zimbra user owned
     # processes to be killed before syncing
     ps auxww | awk '{print $1" "$2}' | grep zimbra | kill -9 `awk '{print $2}'`
     
     # Sync to backup directory
     rsync -avHK --delete /opt/zimbra/ /backup/zimbra
    
     # Restart Zimbra Services
     su - zimbra -c "/opt/zimbra/bin/zmcontrol start"
    
     # Calculates and outputs amount of time the server was down for
     after="$(date +%s)"
     elapsed="$(expr $after - $before2)"
     hours=$(($elapsed / 3600))
     elapsed=$(($elapsed - $hours * 3600))
     minutes=$(($elapsed / 60))
     seconds=$(($elapsed - $minutes * 60))
     echo Server was down for: "$hours hours $minutes minutes $seconds seconds"
    
     # Create a txt file in the backup directory that'll contains the current Zimbra
     # server version. Handy for knowing what version of Zimbra a backup can be restored to.
     su - zimbra -c "zmcontrol -v > /backup/zimbra/conf/zimbra_version.txt"
     # or examine your /opt/zimbra/.install_history
    
     # Display Zimbra services status
     echo Displaying Zimbra services status...
     su - zimbra -c "/opt/zimbra/bin/zmcontrol status"
     
     # Create archive of backed-up directory for offsite transfer
     # cd /backup/zimbra
     tar -zcvf /tmp/mail.backup.$backupdate.tgz -C /backup/zimbra .
     
     # Transfer file to backup server
     ncftpput -u -p  xxx.xxx.xxx.xxx /zimbra /tmp/mail.backup.$backupdate.tgz
    
     # Outputs the time the backup finished
     echo Time backup finished = $(date +%T)
    
     # Remove Backup File from Temp Directory
     rm -f /tmp/mail.backup.$backupdate.tgz
     
     # Calculates and outputs total time taken
     after="$(date +%s)"
     elapsed="$(expr $after - $before)"
     hours=$(($elapsed / 3600))
     elapsed=$(($elapsed - $hours * 3600))
     minutes=$(($elapsed / 60))
     seconds=$(($elapsed - $minutes * 60))
     echo Time taken: "$hours hours $minutes minutes $seconds seconds"
    I'm loving it. It works great. My only question is this. I would really like it to create a log file with the whole process, and send it along with the tar file. So that on my backup server I have a .tar for that days backup as well as the log file for that .tar. So if for some reason I go to restore that day's .tar and I'd like to check out the log file for that .tar. Hope this makes sense.

    I'm not much of a coder so I have no clue how to do this.

    Also, and probably most importantly, is this method a good route to take with backing up? Is restore with these backups easily done? Should I be considering an alternate method of backups? If so what would those alternate methods be? Thanks in advance!
    Last edited by physikal; 05-14-2009 at 11:49 AM.

  2. #2
    physikal is offline Loyal Member
    Join Date
    Apr 2009
    Posts
    90
    Rep Power
    5

    Default something?

    Anyone have any ideas?

  3. #3
    Enake is offline Active Member
    Join Date
    Jan 2009
    Posts
    40
    Rep Power
    6

    Default

    Hellow...

    I'm using the same script for my backups...

    If you want a log you could implement the backup via cron.

    I have this in the root crontab:

    0 3 * * * /root/zimbrabackup.sh > /tmp/zmbackuplog.txt 2>&1

    Every night at 3:00 a.m. the backup starts...

    This backup restore the whole installation of Zimbra... if you prefer per user backups you may consider the NE version...

    Hope this helps.

  4. #4
    physikal is offline Loyal Member
    Join Date
    Apr 2009
    Posts
    90
    Rep Power
    5

    Default

    Ya, I would love the NE version. I just can't justify the cost. If it was like 2-3k flat fee for unlimited users then I would have bought it a week ago. heh.

    Don't get me wrong. I think its well worth it. With the kind of support these guys provide, that truly is priceless. We as a small business just don't have 10k laying around just yet. Some day though, I hope!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 658
    Last Post: 04-04-2014, 09:01 AM
  2. zimbra opesource Backup Script Problem!
    By tashi in forum Administrators
    Replies: 4
    Last Post: 03-30-2009, 11:49 PM
  3. Zimbra Open Source Backup Help
    By ayush1440 in forum Administrators
    Replies: 8
    Last Post: 11-13-2008, 04:56 AM
  4. Zimbra Backup Script ... Small Problem
    By frankb in forum Administrators
    Replies: 12
    Last Post: 07-14-2008, 08:40 AM
  5. [SOLVED] Backups failing, "unable to read metadata for account"
    By smcgrath1111 in forum Administrators
    Replies: 10
    Last Post: 04-10-2008, 03:15 PM

Posting Permissions

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