Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.

Link a questa pagina di confronto

Entrambe le parti precedenti la revisioneRevisione precedente
Prossima revisione
Revisione precedente
script_di_backup_su_ispconfig [2010/11/08 11:24] lucascript_di_backup_su_ispconfig [2014/07/03 14:57] (versione attuale) – modifica esterna 127.0.0.1
Linea 1: Linea 1:
 Lo script è eseguito in /etc/cron.daily Lo script è eseguito in /etc/cron.daily
  
- #!/bin/bash +  #!/bin/bash 
-#DICHIARO UN ARRAY +  #DICHIARO UN ARRAY 
-declare -a array1 +  declare -a array1 
- +   
-### System Setup ### +  ### System Setup ### 
-BACKUP=/tmp/backup.$$ +  BACKUP=/tmp/backup.$$ 
-NOW=$(date +"%d-%m-%Y"+  NOW=$(date +"%d-%m-%Y"
-INCFILE="/root/tar-inc-backup.dat" +  INCFILE="/root/tar-inc-backup.dat" 
-DAY=$(date +"%a"+  DAY=$(date +"%a"
-FULLBACKUP="lun" +  FULLBACKUP="lun" 
- +   
-### MySQL Setup ### +  ### MySQL Setup ### 
-MUSER="root" +  MUSER="root" 
-MPASS="e1r1g1o1-" +  MPASS="e1r1g1o1-" 
-MHOST="localhost" +  MHOST="localhost" 
-MYSQL="$(which mysql)" +  MYSQL="$(which mysql)" 
-MYSQLDUMP="$(which mysqldump)" +  MYSQLDUMP="$(which mysqldump)" 
-GZIP="$(which gzip)" +  GZIP="$(which gzip)" 
- +   
-### FTP server Setup ### +  ### FTP server Setup ### 
-FTPD="/host03/incremental" +  FTPD="/host03/incremental" 
-FTPU="ftpbackup" +  FTPU="ftpbackup" 
-FTPP="f1t1p1b1-" +  FTPP="f1t1p1b1-" 
-FTPS="10.255.0.79" +  FTPS="10.255.0.79" 
-NCFTP="$(which ncftpput)" +  NCFTP="$(which ncftpput)" 
- +   
-#DIRECTORY DI CUI FARE IL BACKUP +  #DIRECTORY DI CUI FARE IL BACKUP 
-DIRECTORY="/var/www/" +  DIRECTORY="/var/www/" 
-#INSERIRE IL PREFIX PER COMPIARE SOLO LE CARTELLE CHE HANNO UNA DETERMINATA STRINGA# +  #INSERIRE IL PREFIX PER COMPIARE SOLO LE CARTELLE CHE HANNO UNA DETERMINATA STRINGA# 
-#ALL'INTERNO DEL NOME +  #ALL'INTERNO DEL NOME 
-PREFIX="web" +  PREFIX="web" 
- +   
-### Other stuff ### +  ### Other stuff ### 
-EMAILID="tech@ergon2000.it" +  EMAILID="tech@ergon2000.it" 
- +   
-#FILE IN CUI SALVARE LA LISTA DELLE DIRECTORY +  #FILE IN CUI SALVARE LA LISTA DELLE DIRECTORY 
-FILE=.backuplist +  FILE=.backuplist 
- +   
-if [[ $PREFIX = "" ]] +  if [[ $PREFIX = "" ]] 
-then  +  then  
- ls $DIRECTORY | more > $FILE +   ls $DIRECTORY | more > $FILE 
-else +  else 
- ls $DIRECTORY | more | grep $PREFIX > $FILE +   ls $DIRECTORY | more | grep $PREFIX > $FILE 
-fi +  fi 
- +   
-if [ -f $FILE ]; then +  if [ -f $FILE ]; then 
- array1=(`cat $FILE |tr '\n' ' '`) +   array1=(`cat $FILE |tr '\n' ' '`) 
-else +  else 
- echo "File $FILE does not exists" +   echo "File $FILE does not exists" 
- exit 3 +   exit 3 
-fi +  fi 
-#echo ${array1[2]} +  #echo ${array1[2]} 
- +   
-#CONTO IL NUMERO DELLE CARTELLE +  #CONTO IL NUMERO DELLE CARTELLE 
-conta_elementi=${#array1[*]} +  conta_elementi=${#array1[*]} 
- +   
-### Start Backup for file system ### +  ### Start Backup for file system ### 
-[ ! -d $BACKUP ] && mkdir -p $BACKUP || : +  [ ! -d $BACKUP ] && mkdir -p $BACKUP || : 
- +   
-if [ "$DAY" == "$FULLBACKUP" ]; then +  if [ "$DAY" == "$FULLBACKUP" ]; then 
-  FTPD="/host03/full" +    FTPD="/host03/full" 
-  COUNTER=0 +    COUNTER=0 
-  while [  $COUNTER -lt $conta_elementi ]; do +    while [  $COUNTER -lt $conta_elementi ]; do 
-      DIRS=$DIRECTORY/${array1[$COUNTER]}   +        DIRS=$DIRECTORY/${array1[$COUNTER]}   
-      FILE="fs-full-${array1[$COUNTER]}.tar.gz" +        FILE="fs-full-${array1[$COUNTER]}.tar.gz" 
-      nice -n 19 tar -zcvf $BACKUP/$FILE $DIRS +        nice -n 19 tar -zcvf $BACKUP/$FILE $DIRS 
-      let COUNTER=COUNTER+1 +        let COUNTER=COUNTER+1  
 +    done 
 +    cp /etc/passwd $DIRECTORY/passwd.txt.tar.gz 
 +    cp /etc/shadow $DIRECTORY/shadow.txt.tar.gz 
 +    cp /etc/group  $DIRECTORY/group.txt.tar.gz 
 +  else 
 +    COUNTER=0 
 +    while [  $COUNTER -lt $conta_elementi ]; do 
 +        DIRS=$DIRECTORY/${array1[$COUNTER]}  
 +        i=$(date +"%Hh%Mm%Ss"
 +        FILE="fs-i-${array1[$COUNTER]}-$i.tar.gz" 
 +        #echo $FILE 
 +        TMP=$BACKUP/$FILE 
 +        echo $DIRS 
 +        nice -n 19 tar -g $INCFILE -zcvf $TMP $DIRS 
 +        let COUNTER=COUNTER+1 
 +    done 
 +  fi 
 +   
 +  ### Start MySQL Backup ### 
 +  # Get all databases name 
 +  FILE=$BACKUP/mysql-FullBackup.gz 
 +  $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS --all-databases | $GZIP -9 > $FILE 
 +  DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" 
 +  for db in $DBS 
 +  do 
 +   FILE=$BACKUP/mysql-$db.gz 
 +   $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
   done   done
-  cp /etc/passwd $DIRECTORY/passwd.txt.tar.gz +   
-  cp /etc/shadow $DIRECTORY/shadow.txt.tar.gz +  ### Dump backup using FTP ### 
-  cp /etc/group  $DIRECTORY/group.txt.tar.gz +  #Start FTP backup using ncftp 
-else +  ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF 
-  COUNTER=0 +  mkdir $FTPD 
-  while [  $COUNTER -lt $conta_elementi ]; do +  mkdir $FTPD/$NOW 
-      DIRS=$DIRECTORY/${array1[$COUNTER]}  +  cd $FTPD/$NOW 
-      i=$(date +"%Hh%Mm%Ss"+  lcd $BACKUP 
-      FILE="fs-i-${array1[$COUNTER]}-$i.tar.gz" +  mput * 
-      #echo $FILE +  quit 
-      TMP=$BACKUP/$FILE +  EOF 
-      echo $DIRS +   
-      nice -n 19 tar -g $INCFILE -zcvf $TMP $DIRS +  ### Find out if ftp backup failed or not ### 
-      let COUNTER=COUNTER+1 +  if [ "$?" == "0" ]; then 
-  done +   rm -f $BACKUP/* 
-fi +  else 
- +   T=/tmp/backup.fail 
-### Start MySQL Backup ### +   echo "Date: $(date)">$T 
-# Get all databases name +   echo "Hostname: $(hostname)" >>$T 
-FILE=$BACKUP/mysql-FullBackup.gz +   echo "Backup failed" >>$T 
-$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS --all-databases | $GZIP -9 > $FILE +   mail  -s "BACKUP FAILED" "$EMAILID" <$T 
-DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" +   rm -f $T 
-for db in $DBS +  fi 
-do +   
- FILE=$BACKUP/mysql-$db.gz +   
- $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE +  #echo $conta_elementi
-done +
- +
-### Dump backup using FTP ### +
-#Start FTP backup using ncftp +
-ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF +
-mkdir $FTPD +
-mkdir $FTPD/$NOW +
-cd $FTPD/$NOW +
-lcd $BACKUP +
-mput * +
-quit +
-EOF +
- +
-### Find out if ftp backup failed or not ### +
-if [ "$?" == "0" ]; then +
- rm -f $BACKUP/* +
-else +
- T=/tmp/backup.fail +
- echo "Date: $(date)">$T +
- echo "Hostname: $(hostname)" >>$T +
- echo "Backup failed" >>$T +
- mail  -s "BACKUP FAILED" "$EMAILID" <$T +
- rm -f $T +
-fi +
- +
- +
-#echo $conta_elementi+