From 3eb09635f98030ad069887b78a2ce80bc5a030e9 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 15 Oct 2025 18:46:02 +0900 Subject: [PATCH] Remove default backup dir and do not create backup folder automatically Fails if the backup folder does not exist or is not writable. --- pg_db_dump_file.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pg_db_dump_file.sh b/pg_db_dump_file.sh index bc040ee..348c7bb 100755 --- a/pg_db_dump_file.sh +++ b/pg_db_dump_file.sh @@ -57,7 +57,7 @@ LOG_PATH=''; # base path for PostgreSQL binary # DBPATH_BASE=''; # defaults -_BACKUPDIR='/mnt/backup/db_dumps_fc/'; +_BACKUPDIR=''; _DB_VERSION=$( pgv=$( pg_dump --version | grep "pg_dump" | cut -d " " -f 3 @@ -324,11 +324,10 @@ if [ ! -f "${PG_PSQL}" ] || [ ! -f "${PG_DUMP}" ] || [ ! -f "${PG_DUMPALL}" ]; t exit 0; fi; -if [ ! -d "${BACKUPDIR}" ] ; then - if ! mkdir "${BACKUPDIR}" ; then - echo "Cannot create backup directory: ${BACKUPDIR}" - exit 0; - fi +# not directory or length is zero +if [ ! -d "${BACKUPDIR}" ] || [ -z "${BACKUPDIR}" ]; then + echo "Backup directory does not exist: ${BACKUPDIR}"; + exit 0; fi # check if we can write into that folder touch "${BACKUPDIR}/tmpfile" || echo "[!] touch failed"; @@ -336,7 +335,7 @@ if [ ! -f "${BACKUPDIR}/tmpfile" ]; then echo "Cannot write to ${BACKUPDIR}"; exit 0; else - rm -f "${BACKUPDIR}/tmpfile"; + rm "${BACKUPDIR}/tmpfile"; fi; # if backupdir is "." rewrite to pwd if [ "${BACKUPDIR}" == '.' ]; then