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 05-14-2009, 11:42 AM
Loyal Member
 
Posts: 87
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..
Reply With Quote
  #2 (permalink)  
Old 05-15-2009, 11:58 AM
Loyal Member
 
Posts: 87
Default something?

Anyone have any ideas?
Reply With Quote
  #3 (permalink)  
Old 05-18-2009, 01:49 AM
Active Member
 
Posts: 38
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.
Reply With Quote
  #4 (permalink)  
Old 05-18-2009, 09:49 AM
Loyal Member
 
Posts: 87
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!
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.