Browse Source

Upload files to ''

Thierry Reijnhout 4 years ago
parent
commit
61d5b23fcb
1 changed files with 74 additions and 0 deletions
  1. 74 0
      backup-2.72.sh

+ 74 - 0
backup-2.72.sh

@@ -0,0 +1,74 @@
+#!/bin/bash
+
+
+DATE=`date +%Y-%m-%d`
+exclude_file=exclude.exl
+time_main1=$(date +"%s")
+mainlogfile=/mnt/LVM1/backup/Backup_10.0.4.3-$DATE.log
+
+#start logging
+  echo "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" >> $mainlogfile
+  echo " " >> $mainlogfile
+  echo "-----------------start backup @ `date`-----------------------------------------------------------------------------------------------------------------------" >> $mainlogfile
+
+#load config files
+for file in */*.cfg
+
+#load config file parameters
+ do 
+  LINES=()
+  while IFS= read -r line
+   do
+   LINES[${#LINES[@]}]="$line"
+   done < $file 
+
+#set some variables
+ logfile=${file##*/}
+ logfile=${logfile%%.cfg}.log
+ exclude_file=${LINES[4]}
+ time1=$(date +"%s")
+
+#Do the Job  
+  echo "Start backup script $logfile @ `date`" >> $mainlogfile
+  
+ #remove old logfile 
+  echo " removing old log file ${LINES[2]}/$logfile, start rsync for $logfile @ `date`" >> $mainlogfile
+  rm ${LINES[2]}/$logfile >> $mainlogfile
+
+  echo "Start backup script @ $time_main" >> ${LINES[2]}/$logfile
+    echo "start rsync for forlder ${LINES[1]} @ ${LINES[5]}"
+   echo "start rsync for forlder ${LINES[1]} @ ${LINES[5]} `date`" >>  ${LINES[2]}/$logfile
+   echo " " >>  ${LINES[2]}/$logfile
+  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
+    echo "Rsync ${LINES[1]} TO ${LINES[2]} Read the log file: ${LINES[2]}/$logfile for details"
+   echo " " >> ${LINES[2]}/$logfile
+   echo "This Backup is made: `date`" >> ${LINES[2]}/$logfile
+    echo 
+   echo "     rsync done for $logfile @ `date`" >> $mainlogfile
+   
+#calculate running-time    
+ time2=$(date +"%s")
+ time21=$(date +"%T")
+  diff=$(($time2-$time1))
+  echo "$(($diff / 60)) minutes and $(($diff % 60)) seconds elapsed." >> ${LINES[2]}/$logfile 
+ done
+#write some info to mainlogfile
+ time_main2=$(date +"%s")
+  diff=$(($time_main2-$time_main1))
+  echo "finisch a backup sequence @ `date`" >> $mainlogfile
+  echo "$(($diff / 60)) minutes and $(($diff % 60)) seconds elapsed." >> $mainlogfile 
+
+
+#CFG FILE LAYOUT
+#user@x.x.x.x:
+#/path/from
+#/path/to
+#/path/.ssh/id_rsa
+#/path/exclude.exl   (use "exclude.exl" for defalt settings)
+#user@x.x.x.x:
+
+echo "-------------------------------------------------------------------------------------------"
+echo "end of backup script"
+echo "job done $(date)"
+echo "-------------------------------------------------------------------------------------------"
+scp -i ~/.ssh/id_rsa $mainlogfile root@10.0.4.1:/root/log/.