So currently my script looks like:
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.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 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!


LinkBack URL
About LinkBacks

