|
@@ -113,8 +113,15 @@ fn_backup_compression(){
|
|
|
fn_print_dots "Backup (${rootdirduexbackup}) ${backupname}.tar.gz, in progress..."
|
|
fn_print_dots "Backup (${rootdirduexbackup}) ${backupname}.tar.gz, in progress..."
|
|
|
fn_script_log_info "backup ${rootdirduexbackup} ${backupname}.tar.gz, in progress"
|
|
fn_script_log_info "backup ${rootdirduexbackup} ${backupname}.tar.gz, in progress"
|
|
|
excludedir=$(fn_backup_relpath)
|
|
excludedir=$(fn_backup_relpath)
|
|
|
- # CHECK THAT excludedir isn't empty. Sanity check here -CedarLUG
|
|
|
|
|
- tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "${excludedir}" ./*
|
|
|
|
|
|
|
+
|
|
|
|
|
+ # CHECK THAT excludedir is a valid path.
|
|
|
|
|
+ if [ ! -d "${excludedir}" ] ; then
|
|
|
|
|
+ fn_print_info_nl "Problem identifying the previous backup directory for exclusion."
|
|
|
|
|
+ fn_script_log_error "Problem identifying the previous backup directory for exclusion"
|
|
|
|
|
+ core_exit.sh
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "${excludedir}" --exclude "${tmpdir}/.backup.lock" ./*
|
|
|
local exitcode=$?
|
|
local exitcode=$?
|
|
|
if [ ${exitcode} -ne 0 ]; then
|
|
if [ ${exitcode} -ne 0 ]; then
|
|
|
fn_print_fail_eol
|
|
fn_print_fail_eol
|
|
@@ -183,26 +190,46 @@ fn_backup_prune(){
|
|
|
|
|
|
|
|
fn_backup_relpath() {
|
|
fn_backup_relpath() {
|
|
|
# Written by CedarLUG as a "realpath --relative-to" alternative in bash
|
|
# Written by CedarLUG as a "realpath --relative-to" alternative in bash
|
|
|
|
|
+
|
|
|
|
|
+ # Populate an array of tokens initialized from the rootdir components:
|
|
|
declare -a rdirtoks=($(readlink -f "${rootdir}" | sed "s/\// /g"))
|
|
declare -a rdirtoks=($(readlink -f "${rootdir}" | sed "s/\// /g"))
|
|
|
- # CHECK THAT the array is populated correctly. Sanity check here -CedarLUG
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if [ ${#rdirtoks[@]} -eq 0 ]; then
|
|
|
|
|
+ fn_print_info_nl "Problem assessing rootdir during relative path assessment"
|
|
|
|
|
+ fn_script_log_error "Problem assessing rootdir during relative path assessment: ${rootdir}"
|
|
|
|
|
+ core_exit.sh
|
|
|
|
|
+ fi
|
|
|
|
|
+
|
|
|
|
|
+ # Populate an array of tokens initialized from the backupdir components:
|
|
|
declare -a bdirtoks=($(readlink -f "${backupdir}" | sed "s/\// /g"))
|
|
declare -a bdirtoks=($(readlink -f "${backupdir}" | sed "s/\// /g"))
|
|
|
- # CHECK THAT the array is populated correctly. Sanity check here -CedarLUG
|
|
|
|
|
|
|
+ if [ ${#bdirtoks[@]} -eq 0 ]; then
|
|
|
|
|
+ fn_print_info_nl "Problem assessing backupdir during relative path assessment"
|
|
|
|
|
+ fn_script_log_error "Problem assessing backupdir during relative path assessment: ${rootdir}"
|
|
|
|
|
+ core_exit.sh
|
|
|
|
|
+ fi
|
|
|
|
|
|
|
|
|
|
+ # Compare the leading entries of each array. These common elements will be clipped off
|
|
|
|
|
+ # for the relative path output.
|
|
|
for ((base=0; $base<${#rdirtoks[@]}; base++))
|
|
for ((base=0; $base<${#rdirtoks[@]}; base++))
|
|
|
do
|
|
do
|
|
|
[[ "${rdirtoks[$base]}" != "${bdirtoks[$base]}" ]] && break
|
|
[[ "${rdirtoks[$base]}" != "${bdirtoks[$base]}" ]] && break
|
|
|
done
|
|
done
|
|
|
|
|
|
|
|
|
|
+ # Next, climb out of the remaining rootdir location with updir references...
|
|
|
for ((x=${base};$x<${#rdirtoks[@]};x++))
|
|
for ((x=${base};$x<${#rdirtoks[@]};x++))
|
|
|
do
|
|
do
|
|
|
echo -n "../"
|
|
echo -n "../"
|
|
|
done
|
|
done
|
|
|
|
|
|
|
|
|
|
+ # Climb down the remaining components of the backupdir location.
|
|
|
for ((x=${base};$x<$(( ${#bdirtoks[@]} - 1 ));x++))
|
|
for ((x=${base};$x<$(( ${#bdirtoks[@]} - 1 ));x++))
|
|
|
do
|
|
do
|
|
|
echo -n "${bdirtoks[$x]}/"
|
|
echo -n "${bdirtoks[$x]}/"
|
|
|
done
|
|
done
|
|
|
|
|
|
|
|
|
|
+ # In the event there were no directories left in the backupdir above to
|
|
|
|
|
+ # traverse down, just add a newline. Otherwise at this point, there is
|
|
|
|
|
+ # one remaining directory component in the backupdir to navigate.
|
|
|
if (( "$base" < "${#bdirtoks[@]}" )) ; then
|
|
if (( "$base" < "${#bdirtoks[@]}" )) ; then
|
|
|
echo ${bdirtoks[ $(( ${#bdirtoks[@]} - 1)) ]}
|
|
echo ${bdirtoks[ $(( ${#bdirtoks[@]} - 1)) ]}
|
|
|
else
|
|
else
|