backup.pl: Fix #12626 backup/include.user entries will not override backup/exclude

Message ID 20210521122250.7788-1-adolf.belka@ipfire.org
State Accepted
Commit e5f3e0397cb6609fc0fc7aa670ae190c68e09038
Headers
Series backup.pl: Fix #12626 backup/include.user entries will not override backup/exclude |

Commit Message

Adolf Belka May 21, 2021, 12:22 p.m. UTC
  - Current situation is that any restrictions in the exclude file will not
   be overwritten by the include.user file
- For example the global exclude file has *.tmp preventing any tmp files
   being backed up from the globally included IPFire files
   If a user has some specific tmp files they want to backup and include
   them in the include.user file they will not override the global
   exclude file.
- This fix does the backup of the global and user backups as two separate
   events and then appends them. This means that any tmp files in the
   include.user file will be backed up.
- The backups are created as a global tar file and then have the user
   tar file appended and then the combined file gzipped and given the .ipf
   suffix. This has to be done this was as gzipped files can not be
   appended to each other whereas tar files can.

Fixes: 12626
Signed-off-by: Adolf Belka <adolf.belka@ipfire.org>
---
 config/backup/backup.pl | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
  

Patch

diff --git a/config/backup/backup.pl b/config/backup/backup.pl
index d2e531252..8dffbf2e1 100644
--- a/config/backup/backup.pl
+++ b/config/backup/backup.pl
@@ -57,12 +57,21 @@  make_backup() {
 		make_addon_backup "${addon}"
 	done
 
-	tar cvzf "${filename}" \
+	# Backup using global exclude/include definitions
+	tar cvf "${filename}" \
 		--exclude-from="/var/ipfire/backup/exclude" \
+		$(process_includes "/var/ipfire/backup/include") \
+		"$@"
+
+	# Backup using user exclude/include definitions and append to global backup
+	tar rvf "${filename}" \
 		--exclude-from="/var/ipfire/backup/exclude.user" \
-		$(process_includes "/var/ipfire/backup/include" "/var/ipfire/backup/include.user") \
+		$(process_includes "/var/ipfire/backup/include.user") \
 		"$@"
 
+	# gzip the combined global/user backup and use .ipf suffix
+	gzip --suffix .ipf "${filename}"
+
 	return 0
 }
 
@@ -206,7 +215,7 @@  main() {
 			local filename="${1}"
 
 			if [ -z "${filename}" ]; then
-				filename="/var/ipfire/backup/${NOW}.ipf"
+				filename="/var/ipfire/backup/${NOW}"
 			fi
 
 			make_backup "${filename}" $(find_logfiles)
@@ -216,7 +225,7 @@  main() {
 			local filename="${1}"
 
 			if [ -z "${filename}" ]; then
-				filename="/var/ipfire/backup/${NOW}.ipf"
+				filename="/var/ipfire/backup/${NOW}"
 			fi
 
 			make_backup "${filename}"