{"id":371,"date":"2014-07-11T23:44:38","date_gmt":"2014-07-12T06:44:38","guid":{"rendered":"https:\/\/analogman.org\/?p=371"},"modified":"2014-07-11T23:44:38","modified_gmt":"2014-07-12T06:44:38","slug":"simple-backup-script-for-single-server-zimbra-community","status":"publish","type":"post","link":"https:\/\/www.analogman.org\/?p=371","title":{"rendered":"Simple backup script for Single Server Zimbra Community"},"content":{"rendered":"<p>This is just a simple script that I wrote to manage backing a singer server installation of Zimbra Community. It needs some attention, additional tests, etc. but works as is with zimbra 8.x on an ubuntu 12.04 server installation. Of course you will need to change ip addresses to suit your environment&#8230;<\/p>\n<p>&#8212;&#8211; start of script &#8212;&#8211;<\/p>\n<p>#!\/bin\/bash<br \/>\n# 6.4.14<br \/>\n# run this as root<br \/>\n# should we run zmcontrol stop before we backup ldap<br \/>\n# exclude the ldap database directory from the rsync operation<br \/>\n# this assumes an ssh connection to the destination for the rsync<\/p>\n<p>SOURCE=&#8217;\/opt\/zimbra&#8217;<br \/>\nDEST=&#8217;192.168.113.3:\/opt&#8217;<br \/>\nEXCLUDE=&#8217;data.mdb&#8217;<br \/>\nLDAP_SRC=&#8217;\/opt\/zimbra\/data\/ldap\/mdb\/db&#8217;<br \/>\nLDAP_DEST_LOCAL=&#8217;\/opt\/ldapbackup&#8217;<br \/>\nLDAP_DEST_REMOTE=&#8217;192.168.113.3:\/opt\/zimbra\/data\/ldap\/mdb\/db\/&#8217;<br \/>\nBACKUPLOG=&#8217;\/opt\/backuplog\/backup_$(date +%a).log&#8217;<br \/>\nMDBCOPY_LOC=&#8217;\/opt\/zimbra\/openldap\/bin\/mdb_copy&#8217;<br \/>\nRSYNC_LOC=&#8217;\/usr\/bin\/rsync&#8217;<\/p>\n<p>if [ x`whoami` != xroot ]; then<br \/>\n  echo Error: must be run as root user<br \/>\n  exit 1<br \/>\nfi<\/p>\n<p># exit 0<\/p>\n<p># create a log file with the date2<br \/>\n# need to test for existence of directory &#8211; if not exist make the directory &#8211; then<br \/>\ntouch \/opt\/backuplog\/backup_$(date +&#8221;%a&#8221;).log<br \/>\n# set a start time<br \/>\nSTART1=$(date +%s)<\/p>\n<p># send the start time to the log file<br \/>\necho \u201cTime backup started = $(date +%a) $(date +%T)\u201d  >> \/opt\/backuplog\/backup_$(date +%a).log<\/p>\n<p># execute the live sync&#8230;<br \/>\n# test for exist rsync &#8211; if not exit else then<br \/>\n# test for exist source and dest &#8211; if not either one &#8211; exit else<br \/>\necho syncning files from $SOURCE to $DEST<br \/>\n$RSYNC_LOC -avH &#8211;exclude $EXCLUDE &#8211;delete  $SOURCE $DEST<\/p>\n<p># set a finish live sync time and calculate the difference<br \/>\nFINISH1=$(date +%s)<\/p>\n<p># i will use the times to output to a log file later<br \/>\necho &#8220;total time live rsync $(( ($FINISH1-$START1) \/ 60 )) minutes, $(( ($FINISH1-$START1) % 60 )) seconds&#8221; >> \/opt\/backuplog\/backup_$(date +%a).log<\/p>\n<p># start the clock again<br \/>\nSTART2=$(date +%s)<\/p>\n<p># next backup the ldap databse to a local spot &#8211; may not work if there is a file there<br \/>\n# test for exist &#8211; if not exist &#8211; exit else<\/p>\n<p>$MDBCOPY_LOC $LDAP_SRC   $LDAP_DEST_LOCAL<\/p>\n<p># now sync the database with the remote destination<br \/>\n$RSYNC_LOC -turv  $LDAP_DEST_LOCAL\/data.mdb     $LDAP_DEST_REMOTE<\/p>\n<p># run rsync again to try and catch any files that might have been in use<br \/>\n# sync again &#8211; should not take long<br \/>\n$RSYNC_LOC -avH &#8211;exclude $EXCLUDE &#8211;delete  $SOURCE $DEST<\/p>\n<p># here we should gather some info on the condition of the server, etc and stick it in the<br \/>\nlog file.<\/p>\n<p>FINISH2=$(date +%s)<br \/>\necho &#8220;total time services down: $(( ($FINISH2-$START2) \/ 60 )) minutes, $(( ($FINISH2-$START2) % 60 )) seconds&#8221; >>  \/opt\/backuplog\/backup_$(date +%a).log<\/p>\n<p># Display Zimbra services status<br \/>\necho &#8220;Displaying Zimbra services status&#8221; >> \/opt\/backuplog\/backup_$(date +%a).log<\/p>\n<p>su &#8211; zimbra -c\/opt\/zimbra\/bin\/zmcontrol status >> \/opt\/backuplog\/backup_$(date +%a).log<br \/>\n#<br \/>\n# We need to clean up some things like removing the data.mdb file from \/opt\/ldapbackup because mdb_copy destination has to be empty<br \/>\n#<\/p>\n<p>echo &#8220;Good bye&#8221; >> \/opt\/backuplog\/backup_$(date +%a).log<br \/>\nexit 0<\/p>\n<p>#### will grow this after some testing ####<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is just a simple script that I wrote to manage backing a singer server installation of Zimbra Community. It needs some attention, additional tests, etc. but works as is with zimbra 8.x on an ubuntu 12.04 server installation. Of course you will need to change ip addresses to suit your environment&#8230; &#8212;&#8211; start of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[27,8],"tags":[],"class_list":["post-371","post","type-post","status-publish","format-standard","hentry","category-linux","category-mods"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.analogman.org\/index.php?rest_route=\/wp\/v2\/posts\/371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.analogman.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.analogman.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.analogman.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.analogman.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=371"}],"version-history":[{"count":1,"href":"https:\/\/www.analogman.org\/index.php?rest_route=\/wp\/v2\/posts\/371\/revisions"}],"predecessor-version":[{"id":372,"href":"https:\/\/www.analogman.org\/index.php?rest_route=\/wp\/v2\/posts\/371\/revisions\/372"}],"wp:attachment":[{"href":"https:\/\/www.analogman.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.analogman.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.analogman.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}