script_di_backup_su_ispconfig

Questa è una vecchia versione del documento!


Lo script è eseguito in /etc/cron.daily

#!/bin/bash #DICHIARO UN ARRAY declare -a array1

### System Setup ### BACKUP=/tmp/backup.$$ NOW=$(date +“%d-%m-%Y”) INCFILE=“/root/tar-inc-backup.dat” DAY=$(date +“%a”) FULLBACKUP=“lun”

### MySQL Setup ### MUSER=“root” MPASS=“e1r1g1o1-” MHOST=“localhost” MYSQL=“$(which mysql)” MYSQLDUMP=“$(which mysqldump)” GZIP=“$(which gzip)”

### FTP server Setup ### FTPD=“/host03/incremental” FTPU=“ftpbackup” FTPP=“f1t1p1b1-” FTPS=“10.255.0.79” NCFTP=“$(which ncftpput)”

#DIRECTORY DI CUI FARE IL BACKUP DIRECTORY=“/var/www/” #INSERIRE IL PREFIX PER COMPIARE SOLO LE CARTELLE CHE HANNO UNA DETERMINATA STRINGA# #ALL'INTERNO DEL NOME PREFIX=“web”

### Other stuff ### EMAILID=“tech@ergon2000.it”

#FILE IN CUI SALVARE LA LISTA DELLE DIRECTORY FILE=.backuplist

if $PREFIX = "" then

ls $DIRECTORY | more > $FILE

else

ls $DIRECTORY | more | grep $PREFIX > $FILE

fi

if [ -f $FILE ]; then

array1=(`cat $FILE |tr '\n' ' '`)

else

echo "File $FILE does not exists"
exit 3

fi #echo ${array1[2]}

#CONTO IL NUMERO DELLE CARTELLE conta_elementi=${#array1[*]}

### Start Backup for file system ### [ ! -d $BACKUP ] && mkdir -p $BACKUP || :

if [ “$DAY” == “$FULLBACKUP” ]; then

FTPD="/host03/full"
COUNTER=0
while [  $COUNTER -lt $conta_elementi ]; do
    DIRS=$DIRECTORY/${array1[$COUNTER]}  
    FILE="fs-full-${array1[$COUNTER]}.tar.gz"
    nice -n 19 tar -zcvf $BACKUP/$FILE $DIRS
    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

### 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