rSync Script to backup ZeXtras backup to another server/location via SSH
Results 1 to 4 of 4

Thread: rSync Script to backup ZeXtras backup to another server/location via SSH

  1. #1
    Junior Member
    Join Date
    May 2015
    Posts
    2

    rSync Script to backup ZeXtras backup to another server/location via SSH

    Hi all,

    I just had to register here, but I am not a new one to Zimbra and ZeXtras at all. I have started using Zimbra in 2005, when it was still in the infancy.

    Anyway, I'm not here to tell my story, I'm here to give you one of my scripts - A VERY SIMPLE SCRIPT - which takes the ZeXtras backup your server is doing locally and transfers it over to another server via SSH/rSync ...

    It's well commented, so I won't say more about it, however, I will answer all queries, so just keep asking. Here it is:

    Code:
    #!/bin/bash
    
    # Zimbra Backup Script v0.0001
    # Requires that you have ssh-keys: https://help.ubuntu.com/community/SSHHowto#Public%20key%20authentication
    # This script is intended to run from the crontab as root
    # Compiled from different resources by Oliver Bross - oliver@bross.eu
    
    # the destination log file
    BACKUPLOG="/var/log/rsync-backup.log"
    # the destination directory for local backups
    # example : DESTLOCAL=/opt/zimbra-backup/
    DESTLOCAL=your-destination here
    # the destination for remote backups
    # example: DESTREMOTE="zimbrabackp.server.net:/Backup/zextras"
    DESTREMOTE=and-the-destination-here
    
    # Outputs the time the backup started, for log/tracking purposes
    START=$(date +%s)
    w
    echo ZeXtras Remote rSync Backup > $BACKUPLOG
    echo >> $BACKUPLOG
    echo Time backup started : $(date +%a) $(date +%T). >> $BACKUPLOG
    
    # Let's write few bits into the log file
    echo >> $BACKUPLOG
    echo Source : $DESTLOCAL >> $BACKUPLOG
    echo Destination : $DESTREMOTE >> $BACKUPLOG
    echo Backup Log : $BACKUPLOG >> $BACKUPLOG
    echo >> $BACKUPLOG
    
    # Am I root or not?
    if [ x`whoami` != xroot ]; then
      echo Error: Must be run as root user
      exit 1
    fi
     # exit 0
    
    # backup the backup dir to remote
    echo Syncing files started >> $BACKUPLOG
    rsync -azrtqHK --delete $DESTLOCAL $DESTREMOTE >> $BACKUPLOG 2>&1
    echo Syncing of files finished >> $BACKUPLOG
    echo "(Any errors would be showsn abowe, if nothing shown, all went accoding to the plan!)" >> $BACKUPLOG
    echo >> $BACKUPLOG
    
    # Outputs the time the backup finished
    FINISH=$(date +%s)
    echo Time backup finished : $(date +%a) $(date +%T). >> $BACKUPLOG
    
    # Lets see how log it all took
    echo "Total Backup Time taken :  $(( ($FINISH-$START) / 60 )) minutes, $(( ($FINISH-$START) % 60 )) seconds" >> $BACKUPLOG
    echo >> $BACKUPLOG
    
    # Email some details over ... well, email the log file :-)
    ( echo "Subject: ZeXtras Remote rSync Backup results"; echo; cat $BACKUPLOG ) | /opt/zimbra/postfix/sbin/sendmail youremail@address.com
    
    # end
    ENJOY!

    P.S.
    just copy everything to whatever.sh file, change permissions to "X" and add schedule in the crontab file!

  2. #2
    ZeXtras Community Manager ZeXtras Employee Cine's Avatar
    Join Date
    Apr 2011
    Posts
    2,328
    Hello bugsysiegel!

    Welcome to the forums and thank you for your contribution, it's really appreciated!

    Have a nice day,
    Cine
    the ZeXtras Team
    IT Support Team Contact Form
    Sales Team Contact Form

    ZeXtras Website
    # ZeXtras Wiki # ZeXtras Store

    Have ZeXtras Suite or ZeXtras Migration Tool been helpful to you?
    Share your experience in the Zimbra Gallery!

    ZeXtras Suite on the Zimbra Gallery
    ZeXtras Migration Tool on the Zimbra Gallery

  3. #3
    Junior Member
    Join Date
    May 2015
    Posts
    2
    Just couple more points:

    1. do this first: https://www.digitalocean.com/communi...up-ssh-keys--2 ... what you don't want is for the server to wait for the password, the other server needs to accept incoming ssh connection without password ... that's just an example guide, there are plenty of others on the internet. If you struggle, just ask

    2. don't forget to change the email address on the end of the script! You will receive an email with backup details and errors directly to your mailbox - fabulous!

    Any questions, just ask.

    Bugsy

  4. #4
    Active Member
    Join Date
    Jul 2012
    Posts
    5
    awesome script

    line 53 and 54 should be

    Code:
    # Email some details over ... well, email the log file :-)
    ( echo "Subject: ZeXtras Remote rSync Backup results"; echo; cat $BACKUPLOG ) | /usr/sbin/sendmail
    vs
    Code:
    # Email some details over ... well, email the log file :-)
    ( echo "Subject: ZeXtras Remote rSync Backup results"; echo; cat $BACKUPLOG ) | /opt/zimbra/postfix/sbin/sendmail

    for 8.7 zimbra correct path to sendmail other then that works great so far and appreciate the digital ocean link for ssh keys that was very useful
    Code:
    [root@zimbra ~]# ls -l /usr/sbin/sendmail
    lrwxrwxrwx. 1 root root 21 Jul 29  2015 /usr/sbin/sendmail -> /etc/alternatives/mta
    [root@zimbra ~]#

    just in case anyone else has an error when trying to use with latest zimbra 8.7 save you some time

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •