Remove default backup dir and do not create backup folder automatically

Fails if the backup folder does not exist or is not writable.
This commit is contained in:
2025-10-15 18:46:02 +09:00
parent bb5c65818b
commit 3eb09635f9

View File

@@ -57,7 +57,7 @@ LOG_PATH='';
# base path for PostgreSQL binary # base path for PostgreSQL binary
# DBPATH_BASE=''; # DBPATH_BASE='';
# defaults # defaults
_BACKUPDIR='/mnt/backup/db_dumps_fc/'; _BACKUPDIR='';
_DB_VERSION=$( _DB_VERSION=$(
pgv=$( pgv=$(
pg_dump --version | grep "pg_dump" | cut -d " " -f 3 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; exit 0;
fi; fi;
if [ ! -d "${BACKUPDIR}" ] ; then # not directory or length is zero
if ! mkdir "${BACKUPDIR}" ; then if [ ! -d "${BACKUPDIR}" ] || [ -z "${BACKUPDIR}" ]; then
echo "Cannot create backup directory: ${BACKUPDIR}" echo "Backup directory does not exist: ${BACKUPDIR}";
exit 0; exit 0;
fi
fi fi
# check if we can write into that folder # check if we can write into that folder
touch "${BACKUPDIR}/tmpfile" || echo "[!] touch failed"; touch "${BACKUPDIR}/tmpfile" || echo "[!] touch failed";
@@ -336,7 +335,7 @@ if [ ! -f "${BACKUPDIR}/tmpfile" ]; then
echo "Cannot write to ${BACKUPDIR}"; echo "Cannot write to ${BACKUPDIR}";
exit 0; exit 0;
else else
rm -f "${BACKUPDIR}/tmpfile"; rm "${BACKUPDIR}/tmpfile";
fi; fi;
# if backupdir is "." rewrite to pwd # if backupdir is "." rewrite to pwd
if [ "${BACKUPDIR}" == '.' ]; then if [ "${BACKUPDIR}" == '.' ]; then