Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Zimbra Backup Script
- # Revision: 20180129-01
- # Remote destination for backups
- MOUNTPOINT="/mnt/zimbra_backup"
- DESTSHARE="//syno.dc.prd.local/zimbra_backup"
- SMBUSER="user"
- SMBPW="pw"
- # Make sure remote destination (sync.dc.prd.local) is mounted
- if mount | grep $MOUNTPOINT > /dev/null; then
- echo "Already mounted!"
- else
- echo "Not mounted! Mounting..."
- mount -t cifs "$DESTSHARE" $MOUNTPOINT -o username=$SMBUSER,password=$SMBPW
- # 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/ $DESTLOCAL/zimbra
- rsync -avHK --delete /opt/zimbrab/ $DESTLOCAL/zimbrab
- # 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)"
- # Stop Zimbra Services
- /etc/init.d/zimbra stop
- # Kill any orphaned Zimbra processes
- pkill -9 -u zimbra
- # Sync to backup directory
- rsync -avHK --delete /opt/zimbra/ $DESTLOCAL/zimbra
- rsync -avHK --delete /opt/zimbrab/ $DESTLOCAL/zimbrab
- # Start Zimbra Services
- #su - zimbra -c "/opt/zimbra/bin/zmcontrol start"
- /etc/init.d/zimbra 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"
- # Display Zimbra services status
- echo Displaying Zimbra services status...
- su - zimbra -c "/opt/zimbra/bin/zmcontrol status"
- # Outputs the time the backup finished
- echo Time backup finished = $(date +%T)
- # 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"
- # end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement