Răsfoiți Sursa

Replacing realpath dependency and idosyncracies.

CedarLUG 8 ani în urmă
părinte
comite
f25f643ae0
1 a modificat fișierele cu 31 adăugiri și 1 ștergeri
  1. 31 1
      lgsm/functions/command_backup.sh

+ 31 - 1
lgsm/functions/command_backup.sh

@@ -112,7 +112,8 @@ fn_backup_compression(){
 	sleep 2
 	fn_print_dots "Backup (${rootdirduexbackup}) ${backupname}.tar.gz, in progress..."
 	fn_script_log_info "backup ${rootdirduexbackup} ${backupname}.tar.gz, in progress"
-	excludedir=$(realpath --relative-to="${rootdir}" "${backupdir}")
+	excludedir=fn_backup_relpath
+	# CHECK THAT excludedir isn't empty.  Sanity check here -CedarLUG
 	tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "${excludedir}" ./*
 	local exitcode=$?
 	if [ ${exitcode} -ne 0 ]; then
@@ -180,6 +181,35 @@ fn_backup_prune(){
 	fi
 }
 
+fn_backup_relpath() {
+  	# Written by CedarLUG as a "realpath --relative-to" alternative in bash
+  	declare -a rdirtoks=($(readlink -f "${rootdir}" | sed "s/\// /g"))
+	# CHECK THAT the array is populated correctly.  Sanity check here -CedarLUG
+  	declare -a bdirtoks=($(readlink -f "${backupdir}" | sed "s/\// /g"))
+	# CHECK THAT the array is populated correctly.  Sanity check here -CedarLUG
+
+  	for ((base=0; $base<${#rdirtoks[@]}; base++)) ;
+  	do
+      		[[ "${rdirtoks[$base]}" != "${bdirtoks[$base]}" ]] && break
+  	done
+
+  	for ((x=${base};$x<${#rdirtoks[@]};x++))
+  	do
+      		echo -n "../"
+  	done
+
+  	for ((x=${base};$x<$(( ${#bdirtoks[@]} - 1 ));x++))
+  	do
+      		echo -n "${bdirtoks[$x]}/"
+  	done
+
+  	if (( "$base" < "${#bdirtoks[@]}" )) ; then
+      		echo ${bdirtoks[ $(( ${#bdirtoks[@]} - 1)) ]}
+  	else
+      		echo
+  	fi
+}
+
 # Restart the server if it was stopped for the backup
 fn_backup_start_server(){
 	if [ "${serverstopped}" == "yes" ]; then