Advertisement
Guest User

Zimbra Backup Script

a guest
Jan 29th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Zimbra Backup Script
  4. # Revision: 20180129-01
  5.  
  6. # Remote destination for backups
  7. MOUNTPOINT="/mnt/zimbra_backup"
  8. DESTSHARE="//syno.dc.prd.local/zimbra_backup"
  9. SMBUSER="user"
  10. SMBPW="pw"
  11.  
  12. # Make sure remote destination (sync.dc.prd.local) is mounted
  13. if mount | grep $MOUNTPOINT > /dev/null; then
  14. echo "Already mounted!"
  15. else
  16. echo "Not mounted! Mounting..."
  17. mount -t cifs "$DESTSHARE" $MOUNTPOINT -o username=$SMBUSER,password=$SMBPW
  18.  
  19. # Outputs the time the backup started, for log/tracking purposes
  20. echo Time backup started = $(date +%T)
  21. before="$(date +%s)"
  22.  
  23. # Live sync before stopping Zimbra to minimize sync time with the services down
  24. # Comment out the following line if you want to try single cold-sync only
  25. rsync -avHK --delete /opt/zimbra/ $DESTLOCAL/zimbra
  26. rsync -avHK --delete /opt/zimbrab/ $DESTLOCAL/zimbrab
  27.  
  28. # Now we need to shut down Zimbra to rsync any files that were/are locked
  29. # whilst backing up when the server was up and running.
  30. before2="$(date +%s)"
  31.  
  32. # Stop Zimbra Services
  33. /etc/init.d/zimbra stop
  34. # Kill any orphaned Zimbra processes
  35. pkill -9 -u zimbra
  36.  
  37. # Sync to backup directory
  38. rsync -avHK --delete /opt/zimbra/ $DESTLOCAL/zimbra
  39. rsync -avHK --delete /opt/zimbrab/ $DESTLOCAL/zimbrab
  40.  
  41. # Start Zimbra Services
  42. #su - zimbra -c "/opt/zimbra/bin/zmcontrol start"
  43. /etc/init.d/zimbra start
  44.  
  45. # Calculates and outputs amount of time the server was down for
  46. after="$(date +%s)"
  47. elapsed="$(expr $after - $before2)"
  48. hours=$(($elapsed / 3600))
  49. elapsed=$(($elapsed - $hours * 3600))
  50. minutes=$(($elapsed / 60))
  51. seconds=$(($elapsed - $minutes * 60))
  52. echo SERVER WAS DOWN FOR: "$hours hours $minutes minutes $seconds seconds"
  53.  
  54. # Display Zimbra services status
  55. echo Displaying Zimbra services status...
  56. su - zimbra -c "/opt/zimbra/bin/zmcontrol status"
  57.  
  58. # Outputs the time the backup finished
  59. echo Time backup finished = $(date +%T)
  60.  
  61. # Calculates and outputs total time taken
  62. after="$(date +%s)"
  63. elapsed="$(expr $after - $before)"
  64. hours=$(($elapsed / 3600))
  65. elapsed=$(($elapsed - $hours * 3600))
  66. minutes=$(($elapsed / 60))
  67. seconds=$(($elapsed - $minutes * 60))
  68. echo Time taken: "$hours hours $minutes minutes $seconds seconds"
  69.  
  70. # end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement