Page 19 of 22 FirstFirst ... 91718192021 ... LastLast
Results 181 to 190 of 211

Thread: Full Server Backup and Restore of “open source version”

  1. #181
    zakai is offline Member
    Join Date
    Jun 2008
    Posts
    10
    Rep Power
    7

    Default

    Does anyone know the answer to the question here, which is: How does one backup/restore a single user?

  2. #182
    phoenix is online now Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,566
    Rep Power
    57

    Default

    Quote Originally Posted by zakai View Post
    Does anyone know the answer to the question here, which is: How does one backup/restore a single user?
    One method: restore your backup, find the user account then inject them into the server with zmlmtpinject?
    Regards


    Bill


    Acompli: A new adventure for Co-Founder KevinH.

  3. #183
    mauibay is offline Starter Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    6

    Default

    Quote Originally Posted by mmarodin View Post
    This is a per-user full backup script (based on mubley's code, 2005), for Zimbra 5.x. Zimbra DB and LDAP are also included.
    I've tested it on 5.0.12 version.

    I don't want to use ...
    Code:
    /opt/zimbra/bin/zmmailbox -z -m user@domain.com getRestURL “//?fmt=tgz” > /tmp/account.tgz
    ... because with this backup job I could not restore single messages, but only full mailbox.

    I hope it could be usefull for you!

    Code:
    #!/bin/sh
    #--------
    
    # Backup Zimbra Open Source 5.x
    # by mm@rodin - 20090206
    
    # Modify the following variables to suit your installation
    export time=`date +%y%m%d`
    export backup_dir=/opt/backup
    export zimbra_dir=/opt/zimbra
    export index_dir=$zimbra_dir/index
    export store_dir=$zimbra_dir/store
    
    # We need mysqldump.  If it doesn't exist,
    # copy mysql and modify it to call mysqldump.
    if [ ! -e $zimbra_dir/bin/mysqldump ]; then
       cp $zimbra_dir/bin/mysql $zimbra_dir/bin/mysqldump
       sed -i 's|/bin/mysql |/bin/mysqldump |g' $zimbra_dir/bin/mysqldump
    fi
    
    # Create the backup directory
    mkdir -p $backup_dir
    
    # Get a list of all accounts and execute
    # the contents of the for-loop for each account.
    for i in `$zimbra_dir/bin/zmprov gaa` ; do
    
    # Beginning of for-loop
    
    #  Use email address to get zimbra_id
       zimbraId=`$zimbra_dir/bin/zmprov ga $i |grep zimbraId |sed 's|zimbraId: ||g'`
       set $zimbraId
    
    #  Use mysql to get number id
       zimbra_nr=`$zimbra_dir/bin/mysql -e "use zimbra; select id from mailbox where account_id = '$1'"`
       zimbra_nr=`echo $zimbra_nr | sed 's|id ||g'`
    
    #  Check to make sure we got a valid number id
       if [ "$zimbra_nr" = "" ]; then
          echo $i has no mailbox.
       else
    
    #     Set zimbraAccountStatus to "maintenance"
          $zimbra_dir/bin/zmprov ma $i zimbraAccountStatus maintenance
    
    #     Marking user backup
          if [ ! -e $backup_dir/info-$zimbra_nr.txt ]; then
             echo "Zimbra ID:	$1" > $backup_dir/info-$zimbra_nr.txt
             echo "Mail address:	$i" >> $backup_dir/info-$zimbra_nr.txt
          fi
    
    #     Backup index and store files
          tar -czf $backup_dir/$time-$zimbra_nr-data.tgz $zimbra_dir/index/0/$zimbra_nr $zimbra_dir/store/0/$zimbra_nr
    
    #     Backup Mysql db
          $zimbra_dir/bin/mysqldump mboxgroup$zimbra_nr > $backup_dir/$time-$zimbra_nr.dump
          tar -czf $backup_dir/$time-$zimbra_nr.dump.tgz $backup_dir/$time-$zimbra_nr.dump
          rm -f $backup_dir/$time-$zimbra_nr.dump
    
    #     Set zimbraAccountStatus to "active"
          $zimbra_dir/bin/zmprov ma $i zimbraAccountStatus active
    
    #  End of if statement
       fi
    
    # End of for-loop
    done
    
    # Backup Zimbra master database and LDAP accounts database
    # First, set all accounts to maintenance.
    for i in `$zimbra_dir/bin/zmprov gaa` ; do
       $zimbra_dir/bin/zmprov ma $i zimbraAccountStatus maintenance
    done
    
    $zimbra_dir/bin/mysqldump zimbra  > $backup_dir/$time-zimbra.dump
    tar -czf $backup_dir/$time-zimbra.dump.tgz $backup_dir/$time-zimbra.dump
    rm -f $backup_dir/$time-zimbra.dump
    
    $zimbra_dir/bin/zmslapcat > $backup_dir/$time-zimbra.ldap
    tar -czf $backup_dir/$time-zimbra.ldap.tgz $backup_dir/$time-zimbra.ldap
    rm -f $backup_dir/$time-zimbra.ldap
    
    # Setting all accounts to active mode.
    for i in `$zimbra_dir/bin/zmprov gaa` ; do
       $zimbra_dir/bin/zmprov ma $i zimbraAccountStatus active
    done
    
    # Backup complete
    This looks promising for my needs, but can you describe with some detail the restore procedure? It's fairly clear to me on the conceptual level what this script is doing, but I'd appreciate an example of the steps needed to to a full restore from the backup files this script produces.

  4. #184
    tiger2000 is offline Elite Member
    Join Date
    May 2008
    Location
    Taiwan
    Posts
    296
    Rep Power
    7

    Default

    Here's my steps and scripts for per-user backup/restore :

    (please correct me if there's anything not correct)

    Backup:
    Run this script by : backup.sh filename
    and you can put the user account into such filename.

    backup.sh:

    Code:
    #!/bin/bash
    
    if [ $# -ne 1 ]; then
       echo "Usage: $0 filename"
       exit 1
    fi
    
    domain="@my.domain"
    backupdir="/root/backup/users"
    
    echo "Start to backup => `date`"
    
    if [ ! -d $backupdir ]; then
       echo "$backupdir not existing, create it now automatically"
       mkdir -p $backupdir
    fi
    
    cat $1 |
    while read line; do
      echo -n "backup user : $line..."
      sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m $line$domain getRestURL "//?fmt=tgz" > $backupdir/$line.tgz
      if [ $? -eq 0 ]; then
         echo "OK [`du -h $backupdir/$line.tgz | awk '{print $1}'`]"
      else
         echo "Fail"
      fi
    
    done
    
    echo "Backup finish => `date`"

    Restore:
    Run this script by : restore.sh username {reset,skip}
    e.g. restore.sh superman skip


    restore.sh

    Code:
    #!/bin/bash
    
    domain="@my.domain"
    backupdir="/root/backup/users"
    
    if [ $# -ne 2 ]; then
       echo "Usage: $0 account [reset, skip]"
       exit 1
    fi
    
    case "$2" in
            reset)
                    OPTION="reset"
                    ;;
            skip)
                    OPTION="skip"
                    ;;
            *)
                    echo "Usage: $0 account [reset, skip]"
                    exit 3
    esac
    
    echo "Start to restore => `date`"
    
    echo -n "Check account [$1] ==> "
    sudo -u zimbra /opt/zimbra/bin/zmprov ga $1$domain > /dev/null 2>&1
    if [ $? -ne 0 ]; then
       echo "NO, [$1] not exist"
       exit 2
    else
       echo "Yes, we have [$1]"
    fi
    
    echo -n "Check backup data for [$1] ==> "
    if [ ! -e $backupdir/$1.tgz ]; then
       echo "No, no backup data for [$1]"
       exit 3
    else
       echo "Yes, backup data for [$1] exists"
    fi
    
    echo -n "Start to restore user [$1] ==> "
    sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m $1$domain postRestURL "//?fmt=tgz&resolve=$OPTION" $backupdir/$1.tgz
    
    if [ $? -eq 0 ]; then
       echo "OK"
    else
       echo "Fail"
    fi
    
    echo "Restore finish => `date`"




    If you're going to backup ALL users in your system, then you can use this backupall.sh ;

    Code:
    #!/bin/bash
    
    domain="@my.domain"
    backupdir="/root/backup/users"
    
    echo "Start to backup => `date`"
    
    if [ ! -d $backupdir ]; then
       echo "$backupdir not existing, create it now automatically"
       mkdir -p $backupdir
    fi
    
    index=1
    sudo -u zimbra /opt/zimbra/bin/zmprov gaa |
    while read line; do
      echo -n "[$index]backup user : $line..."
      username=`echo $line | cut -d@ -f1`
      sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m $line getRestURL "//?fmt=tgz" > $backupdir/$username.tgz
      if [ $? -eq 0 ]; then
         echo "OK [`du -h $backupdir/$username.tgz | awk '{print $1}'`]"
      else
         echo "Fail"
      fi
    
      index=`expr $index + 1`
    done
    
    echo "Backup finish => `date`"
    Last edited by tiger2000; 05-06-2009 at 08:51 PM.

  5. #185
    phpasp is offline Member
    Join Date
    Feb 2009
    Posts
    11
    Rep Power
    6

    Default

    Thank you very much!

  6. #186
    edelvall is offline Active Member
    Join Date
    May 2009
    Location
    Lima, Peru
    Posts
    25
    Rep Power
    6

    Default

    Does this script still requires to turn off Zimbra in order to run the backup/restore job?
    Has somebody else done testing?

    Thanks,

    Ed
    Release 8.0.3.GA.5664.UBUNTU10.64 UBUNTU10_64 NETWORK edition.

  7. #187
    marcos.gw is offline Member
    Join Date
    Jun 2009
    Posts
    10
    Rep Power
    6

    Thumbs down Erro restore with restore.sh

    I ran backup.sh ok
    but I ran restore.sh and not ok

    Start to restore => Seg Jun 1 04:23:42 BRT 2009
    Check account [marcos] ==> Yes, we have [marcos]
    Check backup data for [marcos] ==> Yes, backup data for [marcos] exists
    Start to restore user [marcos] ==> ERROR: zclient.CLIENT_ERROR (file not found: /root/backup/users/marcos.tgz) (cause:java.io.FileNotFoundException
    /root/backup/users/marcos.tgz (Permission denied)) Fail

  8. #188
    marcos.gw is offline Member
    Join Date
    Jun 2009
    Posts
    10
    Rep Power
    6

    Default Resolved

    I changed my permissions and worked.

    I have one more question.

    Can I change backup.sh ( full to incremental ) ?

  9. #189
    tiger2000 is offline Elite Member
    Join Date
    May 2008
    Location
    Taiwan
    Posts
    296
    Rep Power
    7

    Default

    >Does this script still requires to turn off Zimbra in order to run the >backup/restore job?

    No, you don't need to turn off Zimbra during backup, because it's a online dump for user's folders.

  10. #190
    tiger2000 is offline Elite Member
    Join Date
    May 2008
    Location
    Taiwan
    Posts
    296
    Rep Power
    7

    Default

    > Can I change backup.sh ( full to incremental ) ?

    i'm not sure, because I don't whether there's any parameter for 'getResturl' access. did you see that 'postResturl' (the restore script) did have several parameters which can be used for reset or skip.. *maybe* 'getResturl' also does, but i'm not sure.

    perhaps someone who's more familiar with "zmmailbox with getRestUrl" can help here ?

Page 19 of 22 FirstFirst ... 91718192021 ... LastLast

LinkBacks (?)

  1. 11-14-2007, 01:09 AM
  2. 08-13-2007, 04:01 AM
  3. 07-31-2007, 09:37 AM
  4. 06-08-2007, 10:09 AM
  5. 05-31-2007, 01:44 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. mailbox backup & restore on open source version
    By Artturi in forum Administrators
    Replies: 3
    Last Post: 07-30-2010, 04:26 PM
  2. Restore single account failed from full backup
    By fmodola in forum Administrators
    Replies: 4
    Last Post: 06-20-2007, 05:27 AM
  3. 3 testing: LDAP: 389 Failed when restore zimbra
    By victorLeong in forum Administrators
    Replies: 15
    Last Post: 05-24-2007, 06:45 AM
  4. copying only last full backup to store offsite
    By riccadus in forum Administrators
    Replies: 0
    Last Post: 01-11-2007, 01:29 AM
  5. Zimbra Full Backup and Restore???
    By jgao in forum Administrators
    Replies: 3
    Last Post: 01-19-2006, 01:34 PM

Posting Permissions

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