sexta-feira, 23 de setembro de 2011

Zimbra - Backup Online do ZCSOS

O Zimbra OpenSource Edition não possui uma ferramenta de backup online, como na versão Enterprise, então para realizar um backup muitos param o servidor(zmcontrol stop) e utilizam o rsync para este passo.

Nunca gostei disso então resolvi fazer o meu próprio backup e com o Zimbra online, ou seja, sem ter que parar o servidor.

Importante:

- Não serve para realizar o backup das configurações do domínio, ou seja, não é para disaster recovery.

Ai vai o código fonte do cara e após explico seu funcionamento:

1 - Crie o arquivo '/opt/zimbra/bin/zcsos-hotbackup.pl' e insira o seguinte conteúdo:


#!/usr/bin/perl
#
# Description: Generate a ZCSOS online backup
#
#
#Author:
#        Gabriel Prestes (helkmut@gmail.com)
#
#07-16-2010 : Created
#02-18-2011 : Modify
#02-28-2011 : Modify
#03-01-2011 : Modify
#03-02-2011 : Final version 0.2
#04-15-2011 : Bug fix
#08-26-2011 : Final version 1.0
#09-01-2011 : Final version 1.1


# --- New Features --- #
# * Agent renamed to ZCSOS-Hotbackup
# * Agent use Zimbra Admin account to send mail status job
# * Now you can restore an account using destination prefix to avoid overwriting the original account
# * Automatically creates accounts in Zimbra's backup if full restoration
# * File configuration parameters
# * Backup rotate control


# --- Bugs fixed --- #


# - v0.2 -
# * Log to console
# * First run does not tell that the folder '/opt/backup/zimbra' does not exist


# --- Wishlist --- #
# * Binary version
# * Validation of the server name and license generated
# * GUI for administration of backups and restores


# Modules
use strict;
use POSIX;
use Getopt::Long;
use File::Basename;
use Switch;
use Net::SMTP;


# ENVs
$ENV{"USER"}="zimbra";
$ENV{"HOME"}="/opt/zimbra";
$ENV{'PATH'} = '/opt/zimbra/bin:/opt/zimbra/postfix/sbin:/opt/zimbra/openldap/bin:/opt/zimbra/snmp/bin:/opt/zimbra/bdb/bin:/opt/zimbra/openssl/bin:/opt/zimbra/java/bin:/usr/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin';


# Global variables
 our $name = basename($0, ".pl");
 our $version="1.1";
 our $log= "/opt/zimbra/log/zcsos-hotbackup.log";
 our $props = "/opt/zimbra/conf/zcsos-hotbackup.props";
 our ($opt_help, $opt_verbose, $opt_version, $opt_type, $opt_account, $opt_prefix, $opt_mailto);


# Props defs
 our $adminuser;
 our $adminpass;
 our $domain;
 our $passworday;
 our $path;
 our $bkpper;


sub main {


        # --- Get Options --- #
        getoption();


        # --- Get props program --- #
        my $counter = 0;
        my @prop_split = ();
        open (PROPS, "$props") or error();
        my @props_array = <PROPS>;
        close(PROPS);


        foreach(@props_array){


                chomp($_);
                @prop_split = split(/=/,$_);
        if($counter == 0){$adminuser = $prop_split[1];}
        if($counter == 1){$adminpass = $prop_split[1];}
                if($counter == 2){$domain = $prop_split[1];}
                if($counter == 3){$passworday = $prop_split[1];}
                if($counter == 4 and !$opt_mailto){$opt_mailto = $prop_split[1];}
                if($counter == 5){$path = $prop_split[1];}
                if($counter == 6){$bkpper = $prop_split[1];}
            $counter++;


        }


        $counter=0;


        # --- My local vars --- #
        my $dflog;
        my @countlog=();
        my $maillog;


        # --- Log permission verify --- #
        $maillog=`\$\(which touch\) $log 2> /dev/null` if(not -e $log);
    if((not -w $log) and ($opt_verbose==1)){


                $opt_verbose=0;
                logger("ERROR - Missing permissions to write to log file ZCSOS-Hotbackup");
                        mail("ERROR - Missing permissions to write to log file ZCSOS-Hotbackup") if($opt_mailto);
                exit;


    }


        # --- Log control --- #
        $dflog=`\$\(which du\) $log 2> /dev/null`;
        @countlog=split(/ /,$dflog);
        if($countlog[0]>10240){logger("WARNING - Log more than 10Mb");}


        # --- Init agent --- #
        logger("INIT Agent");


        # --- Verify path --- #
        if(not -w $path){


                logger("ERROR - Please create $path");
                mail("ERROR - Please create $path") if($opt_mailto);
                exit;


        }


        # --- Get accounts and backup  or restore --- #
    switch ($opt_type) {


                case "B"      {       bkpa();                                                                                                                          }
                case "R"      {       resa();                                                                                                                          }
                else          {       logger("ERROR : Can't call function"); mail("ERROR - Wrong option type") if($opt_mailto); exit(1);                        }


        }


        # --- Send mail status job and exit --- #
        $maillog=`\$\(which tail\) -1 $log 2> /dev/null`;
        mail("$maillog") if ($opt_mailto);
        exit;


}


sub bkpa {


        # --- My vars --- #
        my @accounts=`\$\(which zmprov\) -l gaa 2> /dev/null`;
        my $accounts_ret=$?;
        my $counter=0;
        my $flag=0;
        my $maillog;
    my $date=strftime("%m-%d-%Y",localtime);
    my $bkpdestaccount="$path/ACCOUNT-$date";
    my $bkpdestfull="$path/FULL-$date";
    my $cmd;
    my $ducmd;
    my @countdu=();
    my @bkpsmain=();
        my $checkbkp;


        # --- Accounts problem --- #
        if($accounts_ret!=0){


                logger("ERROR - Cannot get ZCSOS accounts");
                return;


        }


        # --- To backup one account --- #
        if($opt_account){


                # --- Search account --- #
                foreach(@accounts){


                        chomp($_);
                        if($_ =~ $opt_account){


                                $flag++;
                                if($opt_verbose==1){logger("OK - Account $opt_account exist");}
                                last;


                        }


                }


                # --- Check if account exist --- #
                if($flag==0){


                        logger("ERROR - Account $opt_account not exist in ZCS");
                        return;


                }


                # --- Validate destiny --- #
                $bkpdestaccount="$path/ACCOUNT-$date";
                $cmd;


                if(not -e $bkpdestaccount){


                        $cmd=`\$\(which mkdir\) -p $bkpdestaccount`;
                        logger("Create backup folder $bkpdestaccount");


                }


                $flag=0;


                # --- Run backup --- #
                logger("Init backup $opt_account");


                if($opt_verbose==1){


                $cmd=`\$\(which curl\) -S -v -k -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_account/?fmt=tgz > $bkpdestaccount/$opt_account.tgz 2>> $log`;
                        $cmd=`\$\(which head\) -n20 $bkpdestaccount/$opt_account.tgz`;
                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                $cmd=`\$\(which curl\) -S -v -k -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_account/calendar?fmt=ics > $bkpdestaccount/$opt_account.ics 2>> $log`;
                        $cmd=`\$\(which head\) -n20 $bkpdestaccount/$opt_account.ics`;
                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}




                }


                else{


            $cmd=`\$\(which curl\) -S -v -k -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_account/?fmt=tgz > $bkpdestaccount/$opt_account.tgz`;
                        $cmd=`\$\(which head\) -n20 $bkpdestaccount/$opt_account.tgz`;
                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


            $cmd=`\$\(which curl\) -S -v -k -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_account/calendar?fmt=ics > $bkpdestaccount/$opt_account.ics`;
                        $cmd=`\$\(which head\) -n20 $bkpdestaccount/$opt_account.ics`;
                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                }


                # --- Thresholds --- #
                if($flag>0){


                        logger("ERROR: Backup account $opt_account fail");
                        return;


                }


                else {


                        logger("SUCCESS: Backup account $opt_account finished");
                        return;


                }


        }


        # --- Full backup --- #
        else{


                # --- Verify if exist a old backup --- #
                if(!$bkpper){$bkpper=0;}


                $counter=0;


                @bkpsmain=`\$\(which ls\) -tr $path`;


                foreach(@bkpsmain){


                        chomp($_);
                        if ($_ =~ "FULL"){
                                if($counter>=$bkpper){


                                        $checkbkp=`\$\(which rm\) -rf $path/$_`;
                                        logger("BACKUP $_ removed");


                                }


                                $counter++;


                        }


                }


                $counter=0;


                # --- Validate destiny --- #
                if(not -e $bkpdestfull){


                        $cmd=`\$\(which mkdir\) -p $bkpdestfull`;
                    logger("Create backup folder $bkpdestfull");


                }


                # --- Init backup --- #
                logger("Init backup all accounts");


        foreach(@accounts){


                        chomp($_);


                if($opt_verbose==1){


                                logger("$counter ACCOUNT: $_");


                                $cmd=`\$\(which curl\) -v -k -u $adminuser:$adminpass https://127.0.0.1:7071/home/$_/?fmt=tgz > $bkpdestfull/$_.tgz 2>> $log`;
                                $cmd=`\$\(which head\) -n20 $bkpdestfull/$_.tgz`;
                                if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                                $cmd=`\$\(which curl\) -v -k -u $adminuser:$adminpass https://127.0.0.1:7071/home/$_/calendar?fmt=ics > $bkpdestfull/$_.ics 2>> $log`;
                                $cmd=`\$\(which head\) -n20 $bkpdestfull/$_.ics`;
                                if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                        }


                        else{


                                $cmd=`\$\(which curl\) -v -k -u $adminuser:$adminpass https://127.0.0.1:7071/home/$_/?fmt=tgz > $bkpdestfull/$_.tgz`;
                                $cmd=`\$\(which head\) -n20 $bkpdestfull/$_.tgz`;
                                if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}
                                $cmd=`\$\(which curl\) -v -k -u $adminuser:$adminpass https://127.0.0.1:7071/home/$_/calendar?fmt=ics > $bkpdestfull/$_.ics`;
                                $cmd=`\$\(which head\) -n20 $bkpdestfull/$_.ics`;
                                if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                        }


                        $counter++;


                }


                # --- Thresholds --- #
                if($flag>=$counter){


                logger("ERROR: Backup full fail");
                        return;


                }


                if($flag>1){


                logger("WARNING: Backup full finished with warnings");
                        return;


                }


                if($flag==0){


                        logger("SUCCESS: Backup full finished successfully");
                        return;


                }


        }


}


sub resa {


        # --- Get accounts --- #
        my @accounts=`\$\(which zmprov\) -l gaa`;
        my $accounts_ret=$?;
        my $counter=0;
        my $flag=0;
        my $flag_prefix=0;
        my @tgzbkp=();
        my @icsbkp=();
        my @abkp=();
        my $cmd;
        my $last;
        my $tempa;
        my $tempb;


        # --- Accounts problem --- #
        if($accounts_ret!=0){


                logger("ERROR - Cannot get ZCSOS accounts");
                return;


        }


        # --- To restore one account --- #
        if($opt_account){


                # --- Check if account exist in backup --- #
                @tgzbkp=`\$\(which find\) $path -name "$opt_account*tgz" | \$\(which sort\) -r`;
                @icsbkp=`\$\(which find\) $path -name "$opt_account*ics" | \$\(which sort\) -r`;


                if(!$tgzbkp[0] or !$icsbkp[0]){


                        logger("ERROR - You dont have backup to account: $opt_account");
                        return;


                }


                logger("OK - Backup exist in $tgzbkp[0] and $icsbkp[0]");


                # --- Search account --- #
                foreach(@accounts){


                        chomp($_);
                        if($_ =~ $opt_account){


                                $flag++;
                                if($opt_verbose==1){logger("OK - Account $opt_account exist");}


                        }


                        if($_ =~ "$opt_prefix.$opt_account"){


                                $flag_prefix++;
                                if($opt_verbose==1){logger("WARNING - Account prefix $opt_prefix.$opt_account exist");}


                        }


                }


                # --- Exit if account not exit in Zimbra --- #
                if($flag==0){


                        logger("ERROR - Account $opt_account not exist in ZCS");
                        return;


                }


                $flag=0;


                if(!$opt_prefix){


                        # --- Run restore --- #
                        logger("Init restore $opt_account");
                        chomp($tgzbkp[0]);
                        chomp($icsbkp[0]);


                        if($opt_verbose==1){


                                $cmd=`\$\(which curl\) -v -k --data-binary \@$tgzbkp[0] -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_account/?fmt=tgz 2>> $log`;
                                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}
                                $cmd=`\$\(which curl\) -v -k --data-binary \@$icsbkp[0] -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_account/calendar?fmt=ics 2>> $log`;
                                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                        }


                        else{


                                        $cmd=`\$\(which curl\) -v -k --data-binary \@$tgzbkp[0] -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_account/?fmt=tgz`;
                                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}
                                $cmd=`\$\(which curl\) -v -k --data-binary \@$icsbkp[0] -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_account/calendar?fmt=ics`;
                                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                        }


                        # --- Thresholds --- #
                        if($flag>0){


                                logger("ERROR: Restore account $opt_account fail");
                                return;


                        }


                        if($flag==0){


                                logger("SUCCESS: Restore account $opt_account done");
                                return;


                        }


                }


                if(($opt_prefix) and ($flag_prefix==0)){


                        # --- Run restore --- #
            logger("Init restore $opt_prefix.$opt_account");
            chomp($tgzbkp[0]);
            chomp($icsbkp[0]);


                        if($opt_verbose==1){


                                $cmd=`\$\(which zmprov\) ca $opt_prefix.$opt_account $passworday 2>> $log`;
                                $cmd=`\$\(which curl\) -v -k --data-binary \@$tgzbkp[0] -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_prefix.$opt_account/?fmt=tgz 2>> $log`;
                                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}
                                $cmd=`\$\(which curl\) -v -k --data-binary \@$icsbkp[0] -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_prefix.$opt_account/calendar?fmt=ics 2>> $log`;
                                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                        }


                        else{


                                $cmd=`\$\(which zmprov\) ca $opt_prefix.$opt_account $passworday`;
                                        $cmd=`\$\(which curl\) -v -k --data-binary \@$tgzbkp[0] -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_prefix.$opt_account/?fmt=tgz`;
                                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}
                                $cmd=`\$\(which curl\) -v -k --data-binary \@$icsbkp[0] -u $adminuser:$adminpass https://127.0.0.1:7071/home/$opt_prefix.$opt_account/calendar?fmt=ics`;
                                        if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                        }


                        # --- Thresholds --- #
                        if($flag>0){


                                logger("ERROR: Restore account $opt_account fail");
                                return;


                        }


                        if($flag==0){


                                logger("SUCCESS: Restore done - your account is: $opt_prefix.$opt_account and your password is $passworday");
                                return;


                        }


                } else {


                        logger("ERROR - Account $opt_prefix.$opt_account exist in ZCSOS");
                        return;


                }


        }


        # --- Full restore --- #
        else{


                # --- Get a last backup --- #
                $last=`\$\(which ls\) $path | \$\(which grep\) FULL`;


                if(!$last){


                        logger("ERROR - Not exist last backup");
                        return;


                }


                # --- Get all backuped accounts --- #
                chomp($last);
                @abkp=`\$\(which ls\) $path/$last/*.tgz`;


                # --- Backup validated --- #
                if($#accounts>$#abkp){


                        logger("WARNING - ZCS have more accounts than your last backup");


                }


                # --- Init backup --- #
                logger("Init restore all accounts");




                # --- Restore accounts --- #
                foreach(@abkp){


                        chomp($_);


                        if($_ =~ /^.+\/(.+)\.tgz$/){$tempa=$1;}
                        if($_ =~ /^(.+)\.tgz$/){$tempb=$1;}


                        if($opt_verbose==1){


                                logger("$counter ACCOUNT RESTORE: $tempa");


                                $cmd=`\$\(which zmprov\) ca $tempa $passworday 2>> $log`;
                                $cmd=`\$\(which curl\) -v -k --data-binary \@$_ -u $adminuser:$adminpass https://127.0.0.1:7071/home/$tempa/?fmt=tgz 2>> $log`;
                                if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}
                                $cmd=`\$\(which curl\) -v -k --data-binary \@$tempb\.ics -u $adminuser:$adminpass https://127.0.0.1:7071/home/$tempa/calendar?fmt=ics 2>> $log`;
                                if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                        } else{


                                $cmd=`\$\(which zmprov\) ca $tempa $passworday`;
                                $cmd=`\$\(which curl\) -v -k --data-binary \@$_ -u $adminuser:$adminpass https://127.0.0.1:7071/home/$tempa/?fmt=tgz`;
                                if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}
                                $cmd=`\$\(which curl\) -v -k --data-binary \@$tempb\.ics -u $adminuser:$adminpass https://127.0.0.1:7071/home/$tempa/calendar?fmt=ics`;
                                if(($cmd =~ "HTTP ERROR") or ($cmd =~ "Authentication problem")){$flag++;}


                        }


                        $counter++;


                }


                        # --- Thresholds --- #
                        if($flag>=$counter){


                        logger("ERROR: Restore full fail");
                                return;


                        }


                        if($flag>1){


                        logger("SUCCESS: Restore full finished with warnings");
                                return;


                        }


                        if($flag==0){


                                logger("SUCCESS: Restore full finished without errors");
                                return;


                        }


        }


}


sub getoption {


        Getopt::Long::Configure('bundling');
        GetOptions(
                                'A|account=s'           => \$opt_account,
                                'M|mail=s'                              => \$opt_mailto,
                                'P|prefix=s'                    => \$opt_prefix,
                'T|type=s'              => \$opt_type,
                'V|version'             => \$opt_version,
                'h|help'                => \$opt_help,
                'v|verbose=i'           => \$opt_verbose,
        );


     if($opt_help){


             printHelp();
             exit;


     }


     if($opt_version){


             print "$name - '$version'\n";
             exit;


     }


     if(!$opt_verbose){


             $opt_verbose = 1;


     }


         if(!$opt_type){


                print "ERROR - Missing option type\n";
                exit;


         }


}


sub logger {


        return (0) if (not defined $opt_verbose);


        my $msg = shift (@_);
                my $date=strftime("%m-%d-%Y",localtime);




        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
                $wday++;
                $yday++;
                $mon++;
                $year+=1900;
                $isdst++;


        if ($opt_verbose == 0){


                     print "$msg\n";


        } else {


                open(LOG, ">>$log") or do {


                                if($opt_mailto){


                                        mail("JOB FAIL");
                                        exit;


                                } else {


                                        print "ERROR - Unable to write to the log agent\n";
                                        exit;


                                }


                };


                printf LOG ("%02i/%02i/%i - %02i:%02i:%02i => %s\n",$mday,$mon,$year,$hour,$min,$sec,$msg);
            close(LOG);


        }


}


sub mail {


                # --- My vars --- #
        my $msg = shift (@_);
                my $date=strftime("%m-%d-%Y",localtime);
                my $smtp;


                # --- Mail API --- #
                $smtp = Net::SMTP->new('127.0.0.1');
                $smtp->mail("$adminuser");
                $smtp->auth("$adminuser","$adminpass");
                $smtp->to("$opt_mailto");
                $smtp->data();
                $smtp->datasend("Subject: JOB ZCSOS-Hotbackup (Zimbra) - report $date\n");
                $smtp->datasend("MIME-Version: 1.0\n");
                $smtp->datasend("Content-type: text/html\n");
                $smtp->datasend("Content-Transfer-Encoding: 7bit\n");
                $smtp->datasend("\n");
                $smtp->datasend("$msg\n\n");
                $smtp->dataend();
                $smtp->quit;


}




sub printHelp {


                my $help = <<'HELP';


                ZCSOS-Hotbackup : On-line backup with Zimbra Open Source Edition.


                        Requirements:


                                - To use the ZCSOS-Hotbackup directory '/opt/backup/zimbra' must exist and its owner must be the same user running the Zimbra suite.
                                - Curl.


                        Controls:


                                - FULL backup: You can restore just a last backup
                                - Log rotate : When the log be 10MB it will be removed if you want to keep it back up the log as well.


            Syntax:


                                -A  : If backup or restore is for a unique account specify account in this arg


                                -M  : Send status of job by e-mail


                                -P  : Prefix to destiny account in restor process


                                -T  : Restore(R) or Backup(B)


                                -V  : Version


                                -h  : Help


                -v 1: Send to log
                -v 0: Show log in console


                        Example:


                        Backup full                     : /opt/zimbra/bin/zcsos-hotbackup.pl -T B -v 1 -M suporte@km2.com.br
                        Backup account                  : /opt/zimbra/bin/zcsos-hotbackup.pl -T B -A prestesg@domain.com -v 1 -M suporte@km2.com.br
                        Restore full                    : /opt/zimbra/bin/zcsos-hotbackup.pl -T R -v 1 -M suporte@km2.com.br
                        Restore account                 : /opt/zimbra/bin/zcsos-hotbackup.pl -T R -A prestesg@domain.com -v 1 -M suporte@km2.com.br
                        Restore account with prefix     : /opt/zimbra/bin/zcsos-hotbackup.pl -T R -A prestesg@domain.com -P test -v 1 -M suporte@km2.com.br


            Required APIs:


                use strict;
                use Getopt::Long;
                use POSIX;
                use File::Basename;
                                use Switch;
                                use Net::SMTP;


            Support: suporte@km2.com.br


                        Author's words: Only Jesus can save him from the apocalypse.


HELP


                system("clear");
                print $help;


}
&main


2 - Dê permissão de execução ao arquivo do item 1.

3 - Crie o arquivo '/opt/zimbra/conf/zcsos-hotbackup.props' com o seguinte conteúdo:


adminuser=admin
adminpass=teste123
domain="\@km2.com.br"
passworday=testkm2
opt_mailto=helkmut@gmail.com
pathbackup=/opt/zimbra/backup
backup_persistence=2

4 - Crie o diretório '/opt/zimbra/backup' e coloque como owner o usuário 'zimbra'. 

5 - Coloque o seguinte conteúdo no Crontab do usuário 'zimbra':

# BACKUP BEGIN
00 18 * * * /opt/zimbra/bin/zcsos-hotbackup.pl -T B
# BACKUP END

6 - Todos os arquivos dos passos acima devem ser arquivos do usuário 'zimbra', altere o owner. 

Explicando o funcionamento. 

O arquivo '/opt/zimbra/conf/zcsos-hotbackup.props' contêm as propriedades do funcionamento do agente, logo:

adminuser=admin - É o usuário que executará o backup (o ideal é criar um outro usuário administrador só para o backup)
adminpass=teste123 - Senha deste usuário
domain="\@km2.com.br" - Domínio do seu servidor de e-mails
passworday=testkm2 - Senha temporária para caso restaure uma conta
opt_mailto=helkmut@gmail.com - E-mail que receberá os logs de execução dos backups 
pathbackup=/opt/zimbra/backup - Caminho de armazenamento dos backups.
backup_persistence=2 - Número de backups FULL que serão persistidos no disco. 

Help do agente:

                ZCSOS-Hotbackup : On-line backup with Zimbra Open Source Edition.

                        Requirements:

                                - To use the ZCSOS-Hotbackup directory '/opt/backup/zimbra' must exist and its owner must be the same user running the Zimbra suite.
                                - Curl.

                        Controls:

                                - FULL backup: You can restore just a last backup
                                - Log rotate : When the log be 10MB it will be removed if you want to keep it back up the log as well.

            Syntax:

                                -A  : If backup or restore is for a unique account specify account in this arg

                                -M  : Send status of job by e-mail

                                -P  : Prefix to destiny account in restor process

                                -T  : Restore(R) or Backup(B)

                                -V  : Version

                                -h  : Help

                -v 1: Send to log
                -v 0: Show log in console

                        Example:

                        Backup full                     : /opt/zimbra/bin/zcsos-hotbackup.pl -T B -v 1 -M suporte@km2.com.br
                        Backup account                  : /opt/zimbra/bin/zcsos-hotbackup.pl -T B -A prestesg@domain.com -v 1 -M suporte@km2.com.br
                        Restore full                    : /opt/zimbra/bin/zcsos-hotbackup.pl -T R -v 1 -M suporte@km2.com.br
                        Restore account                 : /opt/zimbra/bin/zcsos-hotbackup.pl -T R -A prestesg@domain.com -v 1 -M suporte@km2.com.br
                        Restore account with prefix     : /opt/zimbra/bin/zcsos-hotbackup.pl -T R -A prestesg@domain.com -P test -v 1 -M suporte@km2.com.br

            Required APIs:

                use strict;
                use Getopt::Long;
                use POSIX;
                use File::Basename;
                                use Switch;
                                use Net::SMTP;

            Support: suporte@km2.com.br

                        Author's words: Only Jesus can save him from the apocalypse.

4 comentários: