backup-2.72.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. DATE=`date +%Y-%m-%d`
  3. exclude_file=exclude.exl
  4. time_main1=$(date +"%s")
  5. mainlogfile=/mnt/LVM1/backup/Backup_10.0.4.3-$DATE.log
  6. #start logging
  7. echo "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" >> $mainlogfile
  8. echo " " >> $mainlogfile
  9. echo "-----------------start backup @ `date`-----------------------------------------------------------------------------------------------------------------------" >> $mainlogfile
  10. #load config files
  11. for file in */*.cfg
  12. #load config file parameters
  13. do
  14. LINES=()
  15. while IFS= read -r line
  16. do
  17. LINES[${#LINES[@]}]="$line"
  18. done < $file
  19. #set some variables
  20. logfile=${file##*/}
  21. logfile=${logfile%%.cfg}.log
  22. exclude_file=${LINES[4]}
  23. time1=$(date +"%s")
  24. #Do the Job
  25. echo "Start backup script $logfile @ `date`" >> $mainlogfile
  26. #remove old logfile
  27. echo " removing old log file ${LINES[2]}/$logfile, start rsync for $logfile @ `date`" >> $mainlogfile
  28. rm ${LINES[2]}/$logfile >> $mainlogfile
  29. echo "Start backup script @ $time_main" >> ${LINES[2]}/$logfile
  30. echo "start rsync for forlder ${LINES[1]} @ ${LINES[5]}"
  31. echo "start rsync for forlder ${LINES[1]} @ ${LINES[5]} `date`" >> ${LINES[2]}/$logfile
  32. echo " " >> ${LINES[2]}/$logfile
  33. rsync -avL --exclude-from=$exclude_file --log-file=${LINES[2]}/$logfile -e "ssh -i ${LINES[3]}" --delete-during ${LINES[5]}${LINES[1]} ${LINES[2]}/ >> ${LINES[2]}/$logfile
  34. echo "Rsync ${LINES[1]} TO ${LINES[2]} Read the log file: ${LINES[2]}/$logfile for details"
  35. echo " " >> ${LINES[2]}/$logfile
  36. echo "This Backup is made: `date`" >> ${LINES[2]}/$logfile
  37. echo
  38. echo " rsync done for $logfile @ `date`" >> $mainlogfile
  39. #calculate running-time
  40. time2=$(date +"%s")
  41. time21=$(date +"%T")
  42. diff=$(($time2-$time1))
  43. echo "$(($diff / 60)) minutes and $(($diff % 60)) seconds elapsed." >> ${LINES[2]}/$logfile
  44. done
  45. #write some info to mainlogfile
  46. time_main2=$(date +"%s")
  47. diff=$(($time_main2-$time_main1))
  48. echo "finisch a backup sequence @ `date`" >> $mainlogfile
  49. echo "$(($diff / 60)) minutes and $(($diff % 60)) seconds elapsed." >> $mainlogfile
  50. #CFG FILE LAYOUT
  51. #user@x.x.x.x:
  52. #/path/from
  53. #/path/to
  54. #/path/.ssh/id_rsa
  55. #/path/exclude.exl (use "exclude.exl" for defalt settings)
  56. #user@x.x.x.x:
  57. echo "-------------------------------------------------------------------------------------------"
  58. echo "end of backup script"
  59. echo "job done $(date)"
  60. echo "-------------------------------------------------------------------------------------------"
  61. scp -i ~/.ssh/id_rsa $mainlogfile root@10.0.4.1:/root/log/.