Skip to content

Commit 3bc6bc7

Browse files
committed
fix(backup): update backup file extensions to support multiple compression formats
1 parent 4d8fea8 commit 3bc6bc7

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

lgsm/modules/command_backup.sh

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ fn_firstcommand_set
1313
# Trap to remove lockfile on quit.
1414
fn_backup_trap() {
1515
echo -e ""
16-
echo -en "backup ${backupname}.tar.gz..."
16+
echo -en "backup ${backupname}.${compressext}..."
1717
fn_print_canceled_eol_nl
18-
fn_script_log_info "Backup ${backupname}.tar.gz: CANCELED"
19-
rm -f "${backupdir:?}/${backupname}.tar.gz" | tee -a "${lgsmlog}"
20-
echo -en "backup ${backupname}.tar.gz..."
18+
fn_script_log_info "Backup ${backupname}.${compressext}: CANCELED"
19+
rm -f "${backupdir:?}/${backupname}.${compressext}" | tee -a "${lgsmlog}"
20+
echo -en "backup ${backupname}.${compressext}..."
2121
fn_print_removed_eol_nl
22-
fn_script_log_info "Backup ${backupname}.tar.gz: REMOVED"
22+
fn_script_log_info "Backup ${backupname}.${compressext}: REMOVED"
2323
# Remove backup lockfile.
2424
rm -f "${lockdir:?}/backup.lock"
2525
fn_backup_start_server
@@ -132,7 +132,6 @@ fn_select_compression() {
132132

133133
# Compressing files.
134134
fn_backup_compression() {
135-
fn_select_compression
136135

137136
fn_print_info "A total of ${rootdirduexbackup} will be compressed."
138137
fn_script_log_info "A total of ${rootdirduexbackup} will be compressed: ${backupdir}/${backupname}.${compressext}"
@@ -161,7 +160,7 @@ fn_backup_compression() {
161160
fn_script_log_fail "Starting backup"
162161
else
163162
fn_print_ok_eol
164-
fn_print_ok_nl "Completed: ${italic}${backupname}.${compressext}${default}, total size $(du -sh "${backupdir}/${backupname}.${compressext}" | awk '{print $1}')"
163+
fn_print_ok "Completed: ${italic}${backupname}.${compressext}${default}, total size $(du -sh "${backupdir}/${backupname}.${compressext}" | awk '{print $1}')"
165164
fn_script_log_pass "Backup created: ${backupname}.${compressext}, total size $(du -sh "${backupdir}/${backupname}.${compressext}" | awk '{print $1}')"
166165
alert="backup"
167166
alert.sh
@@ -177,7 +176,7 @@ fn_backup_prune() {
177176
# How many backups exceed maxbackups.
178177
backupquotadiff=$((backupcount - maxbackups))
179178
# How many backups exceed maxbackupdays.
180-
backupsoudatedcount=$(find "${backupdir}"/ -type f -name "*.tar.gz" -mtime +"${maxbackupdays}" | wc -l)
179+
backupsoudatedcount=$(find "${backupdir}"/ -type f -name "*.tar.*" -mtime +"${maxbackupdays}" | wc -l)
181180
# If anything can be cleared.
182181
if [ "${backupquotadiff}" -gt "0" ] || [ "${backupsoudatedcount}" -gt "0" ]; then
183182
fn_print_dots "Pruning"
@@ -192,7 +191,7 @@ fn_backup_prune() {
192191
fn_print_dots "Pruning: Clearing ${backupquotadiff} backup(s)"
193192
fn_script_log_info "Pruning: Clearing ${backupquotadiff} backup(s)"
194193
# Clear backups over quota.
195-
find "${backupdir}"/ -type f -name "*.tar.gz" -printf '%T@ %p\n' | sort -rn | tail -${backupquotadiff} | cut -f2- -d" " | xargs rm
194+
find "${backupdir}"/ -type f -name "*.tar.*" -printf '%T@ %p\n' | sort -rn | tail -${backupquotadiff} | cut -f2- -d" " | xargs rm
196195
fn_print_ok_nl "Pruning: Clearing ${backupquotadiff} backup(s)"
197196
fn_script_log_pass "Pruning: Cleared ${backupquotadiff} backup(s)"
198197
# If maxbackupdays is used over maxbackups.
@@ -215,15 +214,15 @@ fn_backup_prune() {
215214
fn_backup_relpath() {
216215
# Written by CedarLUG as a "realpath --relative-to" alternative in bash.
217216
# Populate an array of tokens initialized from the rootdir components.
218-
declare -a rdirtoks=($(readlink -f "${rootdir}" | sed "s/\// /g"))
217+
mapfile -t rdirtoks < <(readlink -f "${rootdir}" | sed "s/\//\n/g")
219218
if [ ${#rdirtoks[@]} -eq 0 ]; then
220219
fn_print_fail_nl "Problem assessing rootdir during relative path assessment"
221220
fn_script_log_fail "Problem assessing rootdir during relative path assessment: ${rootdir}"
222221
core_exit.sh
223222
fi
224223

225224
# Populate an array of tokens initialized from the backupdir components.
226-
declare -a bdirtoks=($(readlink -f "${backupdir}" | sed "s/\// /g"))
225+
mapfile -t bdirtoks < <(readlink -f "${backupdir}" | sed "s/\//\n/g")
227226
if [ ${#bdirtoks[@]} -eq 0 ]; then
228227
fn_print_fail_nl "Problem assessing backupdir during relative path assessment"
229228
fn_script_log_fail "Problem assessing backupdir during relative path assessment: ${rootdir}"
@@ -268,7 +267,7 @@ fn_backup_start_server() {
268267
fn_print_dots ""
269268
check.sh
270269
core_logs.sh
271-
270+
fn_select_compression
272271
fn_backup_check_lockfile
273272
fn_backup_init
274273
fn_backup_stop_server

lgsm/modules/info_distro.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ if [ -d "${backupdir}" ]; then
252252
backupcount=0
253253

254254
# If there are backups in backup dir.
255-
if [ "$(find "${backupdir}" -name "*.tar.gz" | wc -l)" -ne "0" ]; then
255+
if [ "$(find "${backupdir}" -name "*.tar.*" | wc -l)" -ne "0" ]; then
256256
# number of backups.
257-
backupcount="$(find "${backupdir}"/*.tar.gz | wc -l)" # integer
257+
backupcount="$(find "${backupdir}"/*.tar.* | wc -l)" # integer
258258
# most recent backup.
259-
lastbackup="$(ls -1t "${backupdir}"/*.tar.gz | head -1)" # string
259+
lastbackup="$(ls -1t "${backupdir}"/*.tar.* | head -1)" # string
260260
# date of most recent backup.
261261
lastbackupdate="$(date -r "${lastbackup}")" # string
262262
# no of days since last backup.

0 commit comments

Comments
 (0)