Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -x
- #
- # Modified le 10.02.2011 à 09:48
- #
- # Need to create /var/log/rsync
- # Need package heirloom-mailx, rsync, smbfs
- #
- # To launch it every day at 2AM, add the following line to /etc/crontab :
- # 00 2 * * * /root/script_sauvegarde_rsync_module > /var/log/rsync/sauvegarde_rsync_module.log
- #
- ### PARAMS TO SETTING
- #ANNONCE="fichiers transferes :"
- HOST=`hostname` # not modify this !!!
- DIR2LOG="/var/log/rsync" # Dir where files log are writing
- DIR2NAS="/mnt/Datas/backup/crocolion/" # Dir where files are saved in NAS
- EMAIL_FROM="root@$HOST"
- EMAIL_TO="cddp47.webmestre@crdp-aquitaine.fr"
- FILE_BOO="/root/rsync_boo.log"
- FILE_ERROR="$DIR2LOG/rsync_error.log"
- FILE_LOG="$DIR2LOG/rsync_files.log"
- FILE_PID="$DIR2LOG/rsync.pid"
- mail="/usr/bin/mail"
- LOGIN="***"
- PASS="***"
- SYNC_OPTIONS="-avcRHKz --delete-after --exclude=*~ --ignore-errors --force --numeric-ids --partial --stats --timeout=900"
- SRVR_IP="10.133.173.1" # IP NAS
- SRVR_MODULE="SvgServerCrocolion" # Module Server Rsync
- declare -i NB_ARCHIVES=7
- declare -i NICE_LEVEL=-15
- declare -a DIR2BCKP="()" # not modify this !!!
- DIR2BCKP[0]="/etc/apache2/"
- DIR2BCKP[1]="/etc/apt/"
- DIR2BCKP[2]="/etc/bind/"
- DIR2BCKP[3]="/etc/fail2ban/"
- DIR2BCKP[4]="/etc/log*/"
- DIR2BCKP[5]="/etc/lvm/"
- DIR2BCKP[6]="/etc/mdadm/"
- DIR2BCKP[7]="/etc/network/"
- DIR2BCKP[8]="/etc/rsyslog*/"
- DIR2BCKP[9]="/etc/ssh/"
- DIR2BCKP[10]="/etc/ssl/"
- DIR2BCKP[11]="/etc/webmin/"
- DIR2BCKP[12]="/etc/fstab"
- DIR2BCKP[13]="/etc/group"
- DIR2BCKP[14]="/etc/gshadow"
- DIR2BCKP[15]="/etc/host*"
- DIR2BCKP[16]="/etc/iptables*"
- DIR2BCKP[17]="/etc/passwd"
- DIR2BCKP[18]="/etc/shadow"
- DIR2BCKP[19]="/etc/sudoers"
- DIR2BCKP[20]="/etc/sysctl.conf"
- DIR2BCKP[21]="--exclude=Downloads/ --exclude=apt-mirror/ /home/cddp/"
- DIR2BCKP[22]="/root/"
- DIR2BCKP[23]="/var/log/"
- DIR2BCKP[24]="/var/mail/"
- DIR2BCKP[25]="/var/webmin/"
- DIR2BCKP[26]="/var/www/"
- DIR2BCKP[27]="/etc/monit/"
- DIR2BCKP[28]="/etc/munin/"
- DIR2BCKP[29]="/etc/openvpn/"
- DIR2BCKP[30]="/var/cache/"
- ### FIN DES PARAMETRES A ADAPTER
- declare -i count=${#DIR2BCKP[@]}
- declare -i i=0
- # if user != root, die !
- if (( `id -u` != 0 )); then
- date > $FILE_BOO;
- echo "Sorry, must be root. Exiting..." >> $FILE_BOO;
- exit;
- fi
- if [ -e "$FILE_ERROR" ]; then rm $FILE_ERROR; fi
- if [ -e "$FILE_LOG" ]; then rm $FILE_LOG; fi
- if [ ! -d "$DIR2LOG" ]; then
- if [ `mkdir -p $DIR2LOG` ]; then
- echo "*** Making dir $DIR2LOG !" >> $FILE_LOG
- else
- date >> $FILE_BOO;
- echo "*** Boo : dir $DIR2LOG can't created!" >> $FILE_BOO;
- if [ -s "$FILE_BOO" ]; then
- $mail -a $FILE_BOO -q $FILE_BOO -r $EMAIL_FROM -s "Error to create dir $DIR2LOG" $EMAIL_TO
- fi
- exit;
- fi
- fi
- # start with writing date on file log
- date >> $FILE_LOG
- date_start="$(date +%s)"
- # rsync while
- while [ "$i" -lt "$count" ]; do
- echo "***" >> $FILE_LOG
- date >> $FILE_LOG
- echo "$ANNONCE ${DIR2BCKP[$i]}" >> $FILE_LOG
- if [ "$i" -eq "$count" ]; then
- nice $NICE_LEVEL rsync $RSYNC_OPTIONS ${DIR2BCKP[$i]} $LOGIN@$SRVR_IP::$SRVR_MODULE >> $FILE_LOG 2>> $FILE_ERROR | echo `pidof rsync` > $FILE_PID
- echo " " >> $FILE_LOG
- date_stop="$(date +%s)"
- elapsed=$((date_stop-date_start))
- hour=$((elapsed/3600))
- elapsed=$((elapsed-hour*3600))
- minutes=$((elapsed/60))
- seconds=$((elapsed-minutes*60))
- echo "Rsync executed in: $hours hours $minutes minutes $seconds seconds" >> $FILE_LOG
- else
- nice $NICE_LEVEL rsync $RSYNC_OPTIONS ${DIR2BCKP[$i]} $LOGIN@$SRVR_IP::$SRVR_MODULE >> $FILE_LOG 2>> $FILE_ERROR | echo `pidof rsync` > $FILE_PID
- fi
- echo " " >> $FILE_LOG
- let "i++"
- done
- if [ -s "$FILE_LOG" ]; then
- $mail -a $FILE_LOG -q $FILE_LOG -r $EMAIL_FROM -s "Sauvegarde $HOST:NAS $ANNONCE" $EMAIL_TO
- fi
- # MAKE SNAPSHOTS !!!
- #;/root/rotate_backup
- #;/root/rotate_backup_papilion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement