Jelajahi Sumber

Merge branch 'master' of https://git.sebastianvendt.de/sebastian/backup

Sebastian Vendt 3 bulan lalu
induk
melakukan
28d2956c3b
3 mengubah file dengan 28 tambahan dan 5 penghapusan
  1. 1 0
      .gitignore
  2. 12 2
      backupMgr/Readme.md
  3. 15 3
      backupMgr/getRemoteBackup.sh

+ 1 - 0
.gitignore

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

+ 12 - 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,16 @@ mailTo="user@domain.com"
 rotationDays=14
 ```
 
+As in the example, for each source a exclude file can be optionally provided. 
+The *absolute* 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 listed in the exclude file shall be given relative to the source folder of the rsync command!  
+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 
 ```

+ 15 - 3
backupMgr/getRemoteBackup.sh

@@ -22,16 +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 -a $tmpLogFilePath
+		split[1]=""
+	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!
-		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} ${destinationFolder} | tee -a $tmpLogFilePath 2>&1
 		rsyncExitCode=$?
 		echo "Ending backup job" | tee -a $tmpLogFilePath
 		date | tee -a $tmpLogFilePath