Explorar o código

Adding full support and fixing bugs for source specific exclude files

Sebastian Vendt (Manaslu) hai 1 ano
pai
achega
85a6da7491
Modificáronse 3 ficheiros con 12 adicións e 9 borrados
  1. 1 0
      .gitignore
  2. 3 2
      backupMgr/Readme.md
  3. 8 7
      backupMgr/getRemoteBackup.sh

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 *.conf
 *.yaml
+*.txt

+ 3 - 2
backupMgr/Readme.md

@@ -41,12 +41,13 @@ rotationDays=14
 ```
 
 As in the example, for each source a exclude file can be optionally provided. 
-The path to the exclude file is appended to the destination path and separated by a semicolon. 
+The path to the exclude file is appended to the destination path and separated by a semicolon. The file needs to be placed on the host, executing the rsync command. 
+Wildcards, as shown in the example can be used. All paths shall be given relative to the source folder!  
 The excludes.txt can look as follows
 
 ```
 *.log
-/tmp/files/
+tmp/files/
 ``` 
 
 ## How to run the script

+ 8 - 7
backupMgr/getRemoteBackup.sh

@@ -22,27 +22,28 @@ fi
 echo "Starting backup job(s)" | tee $tmpLogFilePath
 for sourceFolder in "${!backup_folders[@]}"
 do
-	mkdir -p ${backup_folders[$sourceFolder]}
-
 	#Exclude files
 	IFS=';' read -ra split <<< "${backup_folders[$sourceFolder]}"
 	#check if exclude file is given and file exists. Set to zero if not existing.
 	if [[ -n ${split[1]} ]] && ! [ -f ${split[1]} ]; then
-		echo "Error: Could not find exclude file ${split[1]}. Ignoring it." | tee $tmpLogFilePath
+		echo "Error: Could not find exclude file ${split[1]}. Ignoring it." | tee -a $tmpLogFilePath
 		split[1]=""
-	else
-		echo "Exclude file: ${split[1]}" | tee $tmpLogFilePath
 	fi
 
+	destinationFolder=${split[0]}
+	mkdir -p ${destinationFolder}
+
+
 	while [ "$retryAttempts" -ge "0" ]
 	do
 		echo "Starting Job" | tee -a $tmpLogFilePath
 		echo "SRC: ${sourceFolder}" | tee -a $tmpLogFilePath
-		echo "DEST: ${backup_folders[$sourceFolder]}" | tee -a $tmpLogFilePath
+		echo "DEST: ${destinationFolder}" | tee -a $tmpLogFilePath
+		echo "Exclude file: ${split[1]}" | tee -a $tmpLogFilePath
 		date | tee -a $tmpLogFilePath
 		#SSH Host settings need to be set in the ssh client config!
 		excludeDIRs=${split[1]}
-		rsync --delete --out-format="%t %f %''b" -avz ${excludeDIRs:+"--exclude-from" "$excludeDIRs}"} $sourceFolder ${backup_folders[$sourceFolder]} | tee -a $tmpLogFilePath 2>&1
+		rsync --delete --out-format="%t %f %''b" -avz ${excludeDIRs:+"--exclude-from=$excludeDIRs"} ${sourceFolder} ${destinationFolder} | tee -a $tmpLogFilePath 2>&1
 		rsyncExitCode=$?
 		echo "Ending backup job" | tee -a $tmpLogFilePath
 		date | tee -a $tmpLogFilePath