Browse Source

fix(backup): update backup file extensions to support multiple compression formats

pull/4795/head
Daniel Gibbs 4 weeks ago
parent
commit
3bc6bc7303
  1. 23
      lgsm/modules/command_backup.sh
  2. 6
      lgsm/modules/info_distro.sh

23
lgsm/modules/command_backup.sh

@ -13,13 +13,13 @@ fn_firstcommand_set
# Trap to remove lockfile on quit. # Trap to remove lockfile on quit.
fn_backup_trap() { fn_backup_trap() {
echo -e "" echo -e ""
echo -en "backup ${backupname}.tar.gz..." echo -en "backup ${backupname}.${compressext}..."
fn_print_canceled_eol_nl fn_print_canceled_eol_nl
fn_script_log_info "Backup ${backupname}.tar.gz: CANCELED" fn_script_log_info "Backup ${backupname}.${compressext}: CANCELED"
rm -f "${backupdir:?}/${backupname}.tar.gz" | tee -a "${lgsmlog}" rm -f "${backupdir:?}/${backupname}.${compressext}" | tee -a "${lgsmlog}"
echo -en "backup ${backupname}.tar.gz..." echo -en "backup ${backupname}.${compressext}..."
fn_print_removed_eol_nl 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. # Remove backup lockfile.
rm -f "${lockdir:?}/backup.lock" rm -f "${lockdir:?}/backup.lock"
fn_backup_start_server fn_backup_start_server
@ -132,7 +132,6 @@ fn_select_compression() {
# Compressing files. # Compressing files.
fn_backup_compression() { fn_backup_compression() {
fn_select_compression
fn_print_info "A total of ${rootdirduexbackup} will be compressed." fn_print_info "A total of ${rootdirduexbackup} will be compressed."
fn_script_log_info "A total of ${rootdirduexbackup} will be compressed: ${backupdir}/${backupname}.${compressext}" 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" fn_script_log_fail "Starting backup"
else else
fn_print_ok_eol 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}')" fn_script_log_pass "Backup created: ${backupname}.${compressext}, total size $(du -sh "${backupdir}/${backupname}.${compressext}" | awk '{print $1}')"
alert="backup" alert="backup"
alert.sh alert.sh
@ -177,7 +176,7 @@ fn_backup_prune() {
# How many backups exceed maxbackups. # How many backups exceed maxbackups.
backupquotadiff=$((backupcount - maxbackups)) backupquotadiff=$((backupcount - maxbackups))
# How many backups exceed maxbackupdays. # 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 anything can be cleared.
if [ "${backupquotadiff}" -gt "0" ] || [ "${backupsoudatedcount}" -gt "0" ]; then if [ "${backupquotadiff}" -gt "0" ] || [ "${backupsoudatedcount}" -gt "0" ]; then
fn_print_dots "Pruning" fn_print_dots "Pruning"
@ -192,7 +191,7 @@ fn_backup_prune() {
fn_print_dots "Pruning: Clearing ${backupquotadiff} backup(s)" fn_print_dots "Pruning: Clearing ${backupquotadiff} backup(s)"
fn_script_log_info "Pruning: Clearing ${backupquotadiff} backup(s)" fn_script_log_info "Pruning: Clearing ${backupquotadiff} backup(s)"
# Clear backups over quota. # 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_print_ok_nl "Pruning: Clearing ${backupquotadiff} backup(s)"
fn_script_log_pass "Pruning: Cleared ${backupquotadiff} backup(s)" fn_script_log_pass "Pruning: Cleared ${backupquotadiff} backup(s)"
# If maxbackupdays is used over maxbackups. # If maxbackupdays is used over maxbackups.
@ -215,7 +214,7 @@ 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. # 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 if [ ${#rdirtoks[@]} -eq 0 ]; then
fn_print_fail_nl "Problem assessing rootdir during relative path assessment" fn_print_fail_nl "Problem assessing rootdir during relative path assessment"
fn_script_log_fail "Problem assessing rootdir during relative path assessment: ${rootdir}" fn_script_log_fail "Problem assessing rootdir during relative path assessment: ${rootdir}"
@ -223,7 +222,7 @@ fn_backup_relpath() {
fi fi
# Populate an array of tokens initialized from the backupdir components. # 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 if [ ${#bdirtoks[@]} -eq 0 ]; then
fn_print_fail_nl "Problem assessing backupdir during relative path assessment" fn_print_fail_nl "Problem assessing backupdir during relative path assessment"
fn_script_log_fail "Problem assessing backupdir during relative path assessment: ${rootdir}" fn_script_log_fail "Problem assessing backupdir during relative path assessment: ${rootdir}"
@ -268,7 +267,7 @@ fn_backup_start_server() {
fn_print_dots "" fn_print_dots ""
check.sh check.sh
core_logs.sh core_logs.sh
fn_select_compression
fn_backup_check_lockfile fn_backup_check_lockfile
fn_backup_init fn_backup_init
fn_backup_stop_server fn_backup_stop_server

6
lgsm/modules/info_distro.sh

@ -252,11 +252,11 @@ if [ -d "${backupdir}" ]; then
backupcount=0 backupcount=0
# If there are backups in backup dir. # 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. # number of backups.
backupcount="$(find "${backupdir}"/*.tar.gz | wc -l)" # integer backupcount="$(find "${backupdir}"/*.tar.* | wc -l)" # integer
# most recent backup. # 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. # date of most recent backup.
lastbackupdate="$(date -r "${lastbackup}")" # string lastbackupdate="$(date -r "${lastbackup}")" # string
# no of days since last backup. # no of days since last backup.

Loading…
Cancel
Save