فهرست منبع

Adding support for exclude files

Sebastian Vendt (Habicht) 1 سال پیش
والد
کامیت
86c3c9960c
2فایلهای تغییر یافته به همراه23 افزوده شده و 3 حذف شده
  1. 11 2
      backupMgr/Readme.md
  2. 12 1
      backupMgr/getRemoteBackup.sh

+ 11 - 2
backupMgr/Readme.md

@@ -23,10 +23,10 @@ Host sebastianvendt.de
 Create a configuration file, which holds the source and destination paths for the backup jobs as well as several configuration variables. 
 An example configuration file with all **required** variables is given in the following. 
 ```
-#Backup directories
+#Backup directories and source specific exclude file
 declare -A backup_folders 
 backup_folders["backupuser@hostA.com:/opt/SourceFolderA"]="opt/backup/folderA"
-backup_folders["/opt/SourceFolderB"]="opt/backup/folderB"
+backup_folders["/opt/SourceFolderB"]="opt/backup/folderB;/path/to/SourceFolderBSpecific/excludes.txt"
 
 #Configuration
 logPath=/home/user/logs/backupjob/
@@ -40,6 +40,15 @@ mailTo="user@domain.com"
 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 excludes.txt can look as follows
+
+```
+*.log
+/tmp/files/
+``` 
+
 ## How to run the script
 The script requires as argument the path to the configuration file 
 ```

+ 12 - 1
backupMgr/getRemoteBackup.sh

@@ -24,6 +24,16 @@ 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
+		split[1]=""
+	else
+		echo "Exclude file: ${split[1]}" | tee $tmpLogFilePath
+	fi
+
 	while [ "$retryAttempts" -ge "0" ]
 	do
 		echo "Starting Job" | tee -a $tmpLogFilePath
@@ -31,7 +41,8 @@ do
 		echo "DEST: ${backup_folders[$sourceFolder]}" | tee -a $tmpLogFilePath
 		date | tee -a $tmpLogFilePath
 		#SSH Host settings need to be set in the ssh client config!
-		rsync --delete --out-format="%t %f %''b" -avz $sourceFolder ${backup_folders[$sourceFolder]} | tee -a $tmpLogFilePath 2>&1
+		excludeDIRs=${split[1]}
+		rsync --delete --out-format="%t %f %''b" -avz ${excludeDIRs:+"--exclude-from" "$excludeDIRs}"} $sourceFolder ${backup_folders[$sourceFolder]} | tee -a $tmpLogFilePath 2>&1
 		rsyncExitCode=$?
 		echo "Ending backup job" | tee -a $tmpLogFilePath
 		date | tee -a $tmpLogFilePath