From 68c16e198b37e91d51d997c624c7b4dade63f9e2 Mon Sep 17 00:00:00 2001 From: xiagw Date: Sun, 21 May 2023 12:45:42 +0800 Subject: [PATCH] remove useless if condition --- entrypoint | 26 +++++++++++--------------- functions.sh | 30 +++++++++++++----------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/entrypoint b/entrypoint index 5a8193e3..1bc507e7 100755 --- a/entrypoint +++ b/entrypoint @@ -103,13 +103,11 @@ if [[ -n "$DB_RESTORE_TARGET" ]]; then # Execute additional scripts for pre backup restore processing. For example, # uncompress a tarball that contains the tarballs for the sql dump and a # wordpress installation. - if [ -d /scripts.d/pre-restore/ ]; then - for i in $(ls /scripts.d/pre-restore/*.sh); do - if [ -x $i ]; then - DB_RESTORE_TARGET=${DB_RESTORE_TARGET} DB_DUMP_DEBUG=${DB_DUMP_DEBUG} $i - fi - done - fi + for i in /scripts.d/pre-restore/*.sh; do + if [ -x $i ]; then + DB_RESTORE_TARGET=${DB_RESTORE_TARGET} DB_DUMP_DEBUG=${DB_DUMP_DEBUG} $i + fi + done uri_parser ${DB_RESTORE_TARGET} if [[ "${uri[schema]}" == "file" ]]; then cp $DB_RESTORE_TARGET $TMPRESTORE 2>/dev/null @@ -154,17 +152,15 @@ if [[ -n "$DB_RESTORE_TARGET" ]]; then fi # Execute additional scripts for post backup restore processing. For example, # uncompress a tarball that contains the files of a wordpress installation - if [ -d /scripts.d/post-restore/ ]; then - for i in $(ls /scripts.d/post-restore/*.sh); do - if [ -x $i ]; then - DB_RESTORE_TARGET=${DB_RESTORE_TARGET} DB_DUMP_DEBUG=${DB_DUMP_DEBUG} $i - fi - done - fi + for i in /scripts.d/post-restore/*.sh; do + if [ -x $i ]; then + DB_RESTORE_TARGET=${DB_RESTORE_TARGET} DB_DUMP_DEBUG=${DB_DUMP_DEBUG} $i + fi + done else # wait for the next time to start a backup # for debugging - echo Starting at $(date) + echo "Starting at $(date)" last_run=0 current_time=$(date +"%s") freq_time=$(($DB_DUMP_FREQ*60)) diff --git a/functions.sh b/functions.sh index 4c910a74..ccbdb55e 100644 --- a/functions.sh +++ b/functions.sh @@ -105,14 +105,12 @@ function do_dump() { # Execute additional scripts for pre processing. For example, uncompress a # backup file containing this db backup and a second tar file with the # contents of a wordpress install so they can be restored. - if [ -d /scripts.d/pre-backup/ ]; then - for i in $(ls /scripts.d/pre-backup/*.sh); do - if [ -x $i ]; then - NOW=${now} DUMPFILE=${TMPDIR}/${TARGET} DUMPDIR=${TMPDIR} DB_DUMP_DEBUG=${DB_DUMP_DEBUG} $i - [ $? -ne 0 ] && return 1 - fi - done - fi + for i in /scripts.d/pre-backup/*.sh; do + if [ -x $i ]; then + NOW=${now} DUMPFILE=${TMPDIR}/${TARGET} DUMPDIR=${TMPDIR} DB_DUMP_DEBUG=${DB_DUMP_DEBUG} $i + [ $? -ne 0 ] && return 1 + fi + done # do the dump workdir="${TMP_PATH}/backup.$$" @@ -138,7 +136,7 @@ function do_dump() { exclude_list[$i]="true" done for onedb in $DB_LIST; do - if [ -v exclude_list[$onedb] ]; then + if [[ -v exclude_list[$onedb] ]]; then # skip db if it is in the exclude list continue fi @@ -165,14 +163,12 @@ function do_dump() { # Execute additional scripts for post processing. For example, create a new # backup file containing this db backup and a second tar file with the # contents of a wordpress install. - if [ -d /scripts.d/post-backup/ ]; then - for i in $(ls /scripts.d/post-backup/*.sh); do - if [ -x $i ]; then - NOW=${now} DUMPFILE=${TMPDIR}/${SOURCE} DUMPDIR=${TMPDIR} DB_DUMP_DEBUG=${DB_DUMP_DEBUG} $i - [ $? -ne 0 ] && return 1 - fi - done - fi + for i in ls /scripts.d/post-backup/*.sh; do + if [ -x $i ]; then + NOW=${now} DUMPFILE=${TMPDIR}/${SOURCE} DUMPDIR=${TMPDIR} DB_DUMP_DEBUG=${DB_DUMP_DEBUG} $i + [ $? -ne 0 ] && return 1 + fi + done # Execute a script to modify the name of the source file path before uploading to the dump target # For example, modifying the name of the source dump file from the default, e.g. db-other-files-combined.tar.$EXTENSION