LinuxScriptSoluzioniZimbra

Zimbra mailbox HOT Backup and HOT Restore, backup e ripristino a caldo delle cassette postali

Pubblicato il
twitterlinkedin

Linee guida per attivare una procedura automatica di backup delle cassette postali in VMWare Zimbra e invio log in e.mail.

Requisiti
pacchetto sendEmail in /usr/local/bin, download in http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz

Descrizione delle variabili
mount_dir=”/mnt/backup”
log_dir=”/var/log/backup/mailbox”
dest_dir=”$mount_dir/mailbox”
count_file=”$dest_dir/zzcount.dat”
fecha=`date +”%Y-%m-%d”`
nome_file_bkp=”mailbox”
nr_keep=+7
check_file=”$mount_dir/check.dat”

Procedura di backup mailbox
bkp_mailbox_adv

#!/bin/bash

##### ---DICHIARAZIONE  VARIABILI GLOBALI---
##### variabili non dipendenti dal contatore

mount_dir="/mnt/backup"
log_dir="/var/log/backup/mailbox"
dest_dir="$mount_dir/mailbox"
count_file="$dest_dir/zzcount.dat"
fecha=`date +"%Y-%m-%d"`
nome_file_bkp="mailbox"
nr_keep=+7
check_file="$mount_dir/check.dat"

##### NOTIFICHE EMAIL
hostserver="mx.hostname.dominio"
emailfrom="admin@mx.hostname.dominio"
emaildest=( admin@mx.hostname.dominio email@example.com )

##### EVENTUALI MOUNT
# mount -t cifs \\[ip NAS]\[nome condivisione] -o username=[username],password=[password] $mount_dir

##### VERIFICA DI AVVENUTO MOUNT NELL'AREA PREPOSTA AI BACKUP
##### PROCEDURA CHECK FILE
if [ -f $check_file ];
then
  # file esiste, area mount ok
  # nulla da notificare
  echo ""
else
  # file NON esiste, area mount ERRATA
  # notifica ed esci
  # INVIO E-MAIL DI NOTIFICA CON IN ALLEGATO IL LOG-FILE PRODOTTO
  nrz=${#emaildest[*]}
  for (( I = 0 ; I < $nrz ; I++ ))
  do
    /usr/local/bin/sendEmail -f $emailfrom -t ${emaildest[$I]} -u "ERRORE NAS $hostserver" -m "ERRORE NAS $hostserver: MOUNT FALLITO!"
  done
  exit 1
fi

##### VERIFICA CARTELLE DI DESTINAZIONE
if [ -d $dest_dir ];
    then
      echo ""
    else
      mkdir -p $dest_dir
    fi
if [ -d $log_dir ];
    then
      echo ""
    else
      mkdir -p $log_dir
    fi

##### PROCEDURA CONTATORE
if [ -f $count_file ];
then
  nr=`cat $count_file`
  let "nr += 1"
  echo "$nr" > $count_file
else
  touch $count_file
  echo "1" > $count_file
fi

nr=`cat $count_file`

if [ $nr -gt $nr_keep ]
then
  echo "1" > $count_file
fi

nr=`cat $count_file`

#### LOG FILE
log_file="${log_dir}/$nome_file_bkp-$fecha-ver.$nr.log"

if [ -f $log_file ];
then
  rm $log_file
fi

##### CANCELLAZIONE FILE in modalita' *FIFO*
if [ -f $log_dir/*-ver.$nr.* ];
then
  rm $log_dir/*-ver.$nr.*
fi

##### INIZIO PROCEDURA DI BACKUP
echo "INIZIO BACKUP " $(date) >> $log_file
echo "===============================================================================================" >> $log_file

##### BACKUP MAILBOX: $dest_dir/$nome_file_bkp-$fecha-ver.$nr.tgz

all_account=`/opt/zimbra/bin/zmprov -l gaa`
for account in ${all_account}
do

    echo "start backup account " $(date) >> $log_file

    dest_dir_account="${dest_dir}/${account}"

    if [ -d $dest_dir_account ]
    then
      echo "${dest_dir_account} destination_dir ESISTE, OK" >> $log_file
    else
      mkdir -p ${dest_dir_account}
      echo "${dest_dir_account} destination_dir CREATA, OK" >> $log_file
    fi

    ##### CANCELLAZIONE FILE in modalita' *FIFO*
    if [ -f ${dest_dir_account}/*-ver.$nr.* ];
    then
      rm ${dest_dir_account}/*-ver.$nr.*
    fi

    mb_size=`/opt/zimbra/bin/zmmailbox -z -m ${account} gms`
    echo "Mailbox size of ${account} = ${mb_size} - backup.." >> $log_file
    `/opt/zimbra/bin/zmmailbox -z -m ${account} getRestURL "//?fmt=tgz" > ${dest_dir_account}/$nome_file_bkp-${account}-$fecha-ver.$nr.tgz`

    echo "end backup account " $(date) >> $log_file

    echo "===============================================================================================" >> $log_file

done

##### FINE PROCEDURA DI BACKUP
echo "-----------------------------------------------------------------------------------------------" >> $log_file
echo "Lista files backuped in $dest_dir" >> $log_file
echo "-----------------------------------------------------------------------------------------------" >> $log_file
ls -la $dest_dir >> $log_file
echo "-----------------------------------------------------------------------------------------------" >> $log_file
echo "Lista files logger in $log_dir" >> $log_file
echo "-----------------------------------------------------------------------------------------------" >> $log_file
ls -la $log_dir >> $log_file
echo "===============================================================================================" >> $log_file
echo "FINE BACKUP " $(date) >> $log_file

##### INVIO E-MAIL DI NOTIFICA CON IN ALLEGATO IL LOG-FILE PRODOTTO
nrz=${#emaildest[*]}
for (( I = 0 ; I < $nrz ; I++ ))
do
  /usr/local/bin/sendEmail -f $emailfrom -t ${emaildest[$I]} -u "Log MAILBOX Backup $hostserver" -m "Backup server $hostserver" -a $log_file
done

#### sync dischi
sync

#### EVENTUALI UMOUNT
# umount $mount_dir

 

Procedura di ripristino mailbox
/opt/zimbra/bin/zmmailbox -z -m [email] postRestURL “//?fmt=tgz&resolve=reset” [file mailbox]

NOTA.
Se desideri ricevere aiuto o consulenza invia una richiesta gratuita compilando la scheda contatti al seguente link http://www.andreabalboni.com/contatti/ .

 

twitterlinkedin