Advertisement
Guest User

Untitled

a guest
Feb 21st, 2011
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. #!/bin/bash -x
  2. #
  3. # Modified le 10.02.2011 à 09:48
  4. #
  5. # Need to create /var/log/rsync
  6. # Need package heirloom-mailx, rsync, smbfs
  7. #
  8. # To launch it every day at 2AM, add the following line to /etc/crontab :
  9. # 00 2 * * * /root/script_sauvegarde_rsync_module > /var/log/rsync/sauvegarde_rsync_module.log
  10. #
  11.  
  12. ### PARAMS TO SETTING
  13. #ANNONCE="fichiers transferes :"
  14. HOST=`hostname` # not modify this !!!
  15.  
  16. DIR2LOG="/var/log/rsync" # Dir where files log are writing
  17. DIR2NAS="/mnt/Datas/backup/crocolion/" # Dir where files are saved in NAS
  18.  
  19. EMAIL_FROM="root@$HOST"
  20. EMAIL_TO="cddp47.webmestre@crdp-aquitaine.fr"
  21.  
  22. FILE_BOO="/root/rsync_boo.log"
  23. FILE_ERROR="$DIR2LOG/rsync_error.log"
  24. FILE_LOG="$DIR2LOG/rsync_files.log"
  25. FILE_PID="$DIR2LOG/rsync.pid"
  26.  
  27. mail="/usr/bin/mail"
  28.  
  29. LOGIN="***"
  30. PASS="***"
  31.  
  32. SYNC_OPTIONS="-avcRHKz --delete-after --exclude=*~ --ignore-errors --force --numeric-ids --partial --stats --timeout=900"
  33.  
  34. SRVR_IP="10.133.173.1" # IP NAS
  35. SRVR_MODULE="SvgServerCrocolion" # Module Server Rsync
  36.  
  37. declare -i NB_ARCHIVES=7
  38. declare -i NICE_LEVEL=-15
  39.  
  40. declare -a DIR2BCKP="()" # not modify this !!!
  41.  
  42. DIR2BCKP[0]="/etc/apache2/"
  43. DIR2BCKP[1]="/etc/apt/"
  44. DIR2BCKP[2]="/etc/bind/"
  45. DIR2BCKP[3]="/etc/fail2ban/"
  46. DIR2BCKP[4]="/etc/log*/"
  47. DIR2BCKP[5]="/etc/lvm/"
  48. DIR2BCKP[6]="/etc/mdadm/"
  49. DIR2BCKP[7]="/etc/network/"
  50. DIR2BCKP[8]="/etc/rsyslog*/"
  51. DIR2BCKP[9]="/etc/ssh/"
  52. DIR2BCKP[10]="/etc/ssl/"
  53. DIR2BCKP[11]="/etc/webmin/"
  54. DIR2BCKP[12]="/etc/fstab"
  55. DIR2BCKP[13]="/etc/group"
  56. DIR2BCKP[14]="/etc/gshadow"
  57. DIR2BCKP[15]="/etc/host*"
  58. DIR2BCKP[16]="/etc/iptables*"
  59. DIR2BCKP[17]="/etc/passwd"
  60. DIR2BCKP[18]="/etc/shadow"
  61. DIR2BCKP[19]="/etc/sudoers"
  62. DIR2BCKP[20]="/etc/sysctl.conf"
  63. DIR2BCKP[21]="--exclude=Downloads/ --exclude=apt-mirror/ /home/cddp/"
  64. DIR2BCKP[22]="/root/"
  65. DIR2BCKP[23]="/var/log/"
  66. DIR2BCKP[24]="/var/mail/"
  67. DIR2BCKP[25]="/var/webmin/"
  68. DIR2BCKP[26]="/var/www/"
  69. DIR2BCKP[27]="/etc/monit/"
  70. DIR2BCKP[28]="/etc/munin/"
  71. DIR2BCKP[29]="/etc/openvpn/"
  72. DIR2BCKP[30]="/var/cache/"
  73.  
  74.  
  75. ### FIN DES PARAMETRES A ADAPTER
  76.  
  77. declare -i count=${#DIR2BCKP[@]}
  78. declare -i i=0
  79.  
  80. # if user != root, die !
  81. if (( `id -u` != 0 )); then
  82. date > $FILE_BOO;
  83. echo "Sorry, must be root. Exiting..." >> $FILE_BOO;
  84. exit;
  85. fi
  86.  
  87. if [ -e "$FILE_ERROR" ]; then rm $FILE_ERROR; fi
  88. if [ -e "$FILE_LOG" ]; then rm $FILE_LOG; fi
  89.  
  90. if [ ! -d "$DIR2LOG" ]; then
  91. if [ `mkdir -p $DIR2LOG` ]; then
  92. echo "*** Making dir $DIR2LOG !" >> $FILE_LOG
  93. else
  94. date >> $FILE_BOO;
  95. echo "*** Boo : dir $DIR2LOG can't created!" >> $FILE_BOO;
  96. if [ -s "$FILE_BOO" ]; then
  97. $mail -a $FILE_BOO -q $FILE_BOO -r $EMAIL_FROM -s "Error to create dir $DIR2LOG" $EMAIL_TO
  98. fi
  99. exit;
  100. fi
  101. fi
  102.  
  103. # start with writing date on file log
  104. date >> $FILE_LOG
  105.  
  106. date_start="$(date +%s)"
  107.  
  108. # rsync while
  109. while [ "$i" -lt "$count" ]; do
  110. echo "***" >> $FILE_LOG
  111. date >> $FILE_LOG
  112. echo "$ANNONCE ${DIR2BCKP[$i]}" >> $FILE_LOG
  113.  
  114. if [ "$i" -eq "$count" ]; then
  115. nice $NICE_LEVEL rsync $RSYNC_OPTIONS ${DIR2BCKP[$i]} $LOGIN@$SRVR_IP::$SRVR_MODULE >> $FILE_LOG 2>> $FILE_ERROR | echo `pidof rsync` > $FILE_PID
  116. echo " " >> $FILE_LOG
  117.  
  118. date_stop="$(date +%s)"
  119.  
  120. elapsed=$((date_stop-date_start))
  121. hour=$((elapsed/3600))
  122. elapsed=$((elapsed-hour*3600))
  123. minutes=$((elapsed/60))
  124. seconds=$((elapsed-minutes*60))
  125.  
  126. echo "Rsync executed in: $hours hours $minutes minutes $seconds seconds" >> $FILE_LOG
  127.  
  128. else
  129. nice $NICE_LEVEL rsync $RSYNC_OPTIONS ${DIR2BCKP[$i]} $LOGIN@$SRVR_IP::$SRVR_MODULE >> $FILE_LOG 2>> $FILE_ERROR | echo `pidof rsync` > $FILE_PID
  130. fi
  131.  
  132. echo " " >> $FILE_LOG
  133. let "i++"
  134. done
  135.  
  136. if [ -s "$FILE_LOG" ]; then
  137. $mail -a $FILE_LOG -q $FILE_LOG -r $EMAIL_FROM -s "Sauvegarde $HOST:NAS $ANNONCE" $EMAIL_TO
  138. fi
  139.  
  140. # MAKE SNAPSHOTS !!!
  141. #;/root/rotate_backup
  142. #;/root/rotate_backup_papilion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement