From 3bc6bc7303ca113ff5a124c60c3243dfb29d0139 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Fri, 27 Jun 2025 01:02:34 +0100 Subject: [PATCH] fix(backup): update backup file extensions to support multiple compression formats --- lgsm/modules/command_backup.sh | 23 +++++++++++------------ lgsm/modules/info_distro.sh | 6 +++--- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lgsm/modules/command_backup.sh b/lgsm/modules/command_backup.sh index 4c1845b39..aeedcbb36 100644 --- a/lgsm/modules/command_backup.sh +++ b/lgsm/modules/command_backup.sh @@ -13,13 +13,13 @@ fn_firstcommand_set # Trap to remove lockfile on quit. fn_backup_trap() { echo -e "" - echo -en "backup ${backupname}.tar.gz..." + echo -en "backup ${backupname}.${compressext}..." fn_print_canceled_eol_nl - fn_script_log_info "Backup ${backupname}.tar.gz: CANCELED" - rm -f "${backupdir:?}/${backupname}.tar.gz" | tee -a "${lgsmlog}" - echo -en "backup ${backupname}.tar.gz..." + fn_script_log_info "Backup ${backupname}.${compressext}: CANCELED" + rm -f "${backupdir:?}/${backupname}.${compressext}" | tee -a "${lgsmlog}" + echo -en "backup ${backupname}.${compressext}..." fn_print_removed_eol_nl - fn_script_log_info "Backup ${backupname}.tar.gz: REMOVED" + fn_script_log_info "Backup ${backupname}.${compressext}: REMOVED" # Remove backup lockfile. rm -f "${lockdir:?}/backup.lock" fn_backup_start_server @@ -132,7 +132,6 @@ fn_select_compression() { # Compressing files. fn_backup_compression() { - fn_select_compression fn_print_info "A total of ${rootdirduexbackup} will be compressed." fn_script_log_info "A total of ${rootdirduexbackup} will be compressed: ${backupdir}/${backupname}.${compressext}" @@ -161,7 +160,7 @@ fn_backup_compression() { fn_script_log_fail "Starting backup" else fn_print_ok_eol - fn_print_ok_nl "Completed: ${italic}${backupname}.${compressext}${default}, total size $(du -sh "${backupdir}/${backupname}.${compressext}" | awk '{print $1}')" + fn_print_ok "Completed: ${italic}${backupname}.${compressext}${default}, total size $(du -sh "${backupdir}/${backupname}.${compressext}" | awk '{print $1}')" fn_script_log_pass "Backup created: ${backupname}.${compressext}, total size $(du -sh "${backupdir}/${backupname}.${compressext}" | awk '{print $1}')" alert="backup" alert.sh @@ -177,7 +176,7 @@ fn_backup_prune() { # How many backups exceed maxbackups. backupquotadiff=$((backupcount - maxbackups)) # How many backups exceed maxbackupdays. - backupsoudatedcount=$(find "${backupdir}"/ -type f -name "*.tar.gz" -mtime +"${maxbackupdays}" | wc -l) + backupsoudatedcount=$(find "${backupdir}"/ -type f -name "*.tar.*" -mtime +"${maxbackupdays}" | wc -l) # If anything can be cleared. if [ "${backupquotadiff}" -gt "0" ] || [ "${backupsoudatedcount}" -gt "0" ]; then fn_print_dots "Pruning" @@ -192,7 +191,7 @@ fn_backup_prune() { fn_print_dots "Pruning: Clearing ${backupquotadiff} backup(s)" fn_script_log_info "Pruning: Clearing ${backupquotadiff} backup(s)" # Clear backups over quota. - find "${backupdir}"/ -type f -name "*.tar.gz" -printf '%T@ %p\n' | sort -rn | tail -${backupquotadiff} | cut -f2- -d" " | xargs rm + find "${backupdir}"/ -type f -name "*.tar.*" -printf '%T@ %p\n' | sort -rn | tail -${backupquotadiff} | cut -f2- -d" " | xargs rm fn_print_ok_nl "Pruning: Clearing ${backupquotadiff} backup(s)" fn_script_log_pass "Pruning: Cleared ${backupquotadiff} backup(s)" # If maxbackupdays is used over maxbackups. @@ -215,7 +214,7 @@ fn_backup_prune() { fn_backup_relpath() { # 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")) + mapfile -t rdirtoks < <(readlink -f "${rootdir}" | sed "s/\//\n/g") if [ ${#rdirtoks[@]} -eq 0 ]; then fn_print_fail_nl "Problem assessing rootdir during relative path assessment" fn_script_log_fail "Problem assessing rootdir during relative path assessment: ${rootdir}" @@ -223,7 +222,7 @@ fn_backup_relpath() { fi # Populate an array of tokens initialized from the backupdir components. - declare -a bdirtoks=($(readlink -f "${backupdir}" | sed "s/\// /g")) + mapfile -t bdirtoks < <(readlink -f "${backupdir}" | sed "s/\//\n/g") if [ ${#bdirtoks[@]} -eq 0 ]; then fn_print_fail_nl "Problem assessing backupdir during relative path assessment" fn_script_log_fail "Problem assessing backupdir during relative path assessment: ${rootdir}" @@ -268,7 +267,7 @@ fn_backup_start_server() { fn_print_dots "" check.sh core_logs.sh - +fn_select_compression fn_backup_check_lockfile fn_backup_init fn_backup_stop_server diff --git a/lgsm/modules/info_distro.sh b/lgsm/modules/info_distro.sh index 67a9fd5df..a986edf1f 100644 --- a/lgsm/modules/info_distro.sh +++ b/lgsm/modules/info_distro.sh @@ -252,11 +252,11 @@ if [ -d "${backupdir}" ]; then backupcount=0 # If there are backups in backup dir. - if [ "$(find "${backupdir}" -name "*.tar.gz" | wc -l)" -ne "0" ]; then + if [ "$(find "${backupdir}" -name "*.tar.*" | wc -l)" -ne "0" ]; then # number of backups. - backupcount="$(find "${backupdir}"/*.tar.gz | wc -l)" # integer + backupcount="$(find "${backupdir}"/*.tar.* | wc -l)" # integer # most recent backup. - lastbackup="$(ls -1t "${backupdir}"/*.tar.gz | head -1)" # string + lastbackup="$(ls -1t "${backupdir}"/*.tar.* | head -1)" # string # date of most recent backup. lastbackupdate="$(date -r "${lastbackup}")" # string # no of days since last backup.