Clean up all scripts to match bash linting rules
pg_db_dump_file log parameter never set the log folder, it was always overwritten pg_drop_restore had a double ;; inside which stopped the script from working All: remove -a flag for Amazon Linux OS. This was only for V1 type and we do no longer support this (or use it) and V2 AWS Linux is based more on a redhat type, so the -r flag will work Various other formatting updates Change all strange ls to find calls Change all exec calls with params to params in array
This commit is contained in:
@@ -11,7 +11,7 @@ set -e -u -o pipefail
|
||||
function usage ()
|
||||
{
|
||||
cat <<- EOT
|
||||
Usage: ${0##/*/} [-t] [-s] [-g] [-c] [-r|-a] [-k <number to keep>] [-n] [-b <path>] [-i <postgreSQL version>] [-d <dump database name> [-d ...]] [-e <exclude dump> [-e ...]] [-u <db user>] [-h <db host>] [-p <db port>] [-l <db password>] [-L <log path>]
|
||||
Usage: ${0##/*/} [-t] [-s] [-g] [-c] [-r] [-k <number to keep>] [-n] [-b <path>] [-i <postgreSQL version>] [-d <dump database name> [-d ...]] [-e <exclude dump> [-e ...]] [-u <db user>] [-h <db host>] [-p <db port>] [-l <db password>] [-L <log path>]
|
||||
|
||||
-t: test usage, no real backup is done
|
||||
-s: turn ON ssl mode, default mode is off
|
||||
@@ -28,7 +28,6 @@ function usage ()
|
||||
-p <db port>: default port is '5432'
|
||||
-l <db password>: default password is empty
|
||||
-r: use redhat base paths instead of debian
|
||||
-a: use amazon base paths instead of debian
|
||||
-L <log path>: where to put the dump log file, if not set tries to use PostgreSQL log folder
|
||||
EOT
|
||||
}
|
||||
@@ -67,12 +66,11 @@ _DB_PORT=5432;
|
||||
_EXCLUDE=''; # space separated list of database names
|
||||
_INCLUDE=''; # space seperated list of database names
|
||||
REDHAT=0;
|
||||
AMAZON=0;
|
||||
# CONN_DB_HOST='';
|
||||
ERROR=0;
|
||||
|
||||
# set options
|
||||
while getopts ":ctsgnk:b:i:d:e:u:h:p:l:L:ram" opt; do
|
||||
while getopts ":ctsgnk:b:i:d:e:u:h:p:l:L:rm" opt; do
|
||||
# pre test for unfilled
|
||||
if [ "${opt}" = ":" ] || [[ "${OPTARG-}" =~ ${OPTARG_REGEX} ]]; then
|
||||
if [ "${opt}" = ":" ]; then
|
||||
@@ -204,10 +202,6 @@ while getopts ":ctsgnk:b:i:d:e:u:h:p:l:L:ram" opt; do
|
||||
r)
|
||||
REDHAT=1;
|
||||
;;
|
||||
# a|amazon)
|
||||
a)
|
||||
AMAZON=1;
|
||||
;;
|
||||
# L|logpath)
|
||||
L)
|
||||
if [ -z "${LOG_PATH}" ]; then
|
||||
@@ -234,11 +228,6 @@ if [ ${ERROR} -eq 1 ]; then
|
||||
exit 0;
|
||||
fi;
|
||||
|
||||
if [ "${REDHAT}" -eq 1 ] && [ "${AMAZON}" -eq 1 ]; then
|
||||
echo "You cannot set the -a and -r flag at the same time";
|
||||
exit 0;
|
||||
fi;
|
||||
|
||||
# if we have numeric keep and keep number is set to 0 abort
|
||||
if [ "${CLEAN_NUMBER}" -eq 1 ] && [ "${KEEP}" -lt 1 ]; then
|
||||
echo "If keep in numbers is on, keep must be at least 1 or higher";
|
||||
@@ -264,13 +253,6 @@ if [ "${REDHAT}" -eq 1 ]; then
|
||||
if [ -z "${LOG_PATH}" ]; then
|
||||
LOG_PATH="/var/lib/pgsql/${DB_VERSION}/data/log/";
|
||||
fi;
|
||||
elif [ "${AMAZON}" -eq 1 ]; then
|
||||
# only older 9.6 or before
|
||||
PG_BASE_PATH="/usr/lib64/pgsql";
|
||||
# LOG PATH, will be attached to DB VERSION
|
||||
if [ -z "${LOG_PATH}" ]; then
|
||||
LOG_PATH="/var/lib/pgsql${DB_VERSION}/data/pg_log";
|
||||
fi;
|
||||
else
|
||||
# Debian base path
|
||||
PG_BASE_PATH="/usr/lib/postgresql/";
|
||||
@@ -362,7 +344,18 @@ fi;
|
||||
|
||||
# if we have an ident override set, set a different DUMP VERSION here than the automatic one
|
||||
if [ "${SET_IDENT}" -eq 1 ]; then
|
||||
DUMP_DB_VERSION=$(pgv=$("${PG_PATH}/pg_dump" --version | grep "pg_dump" | cut -d " " -f 3); if [[ $(echo "${pgv}" | cut -d "." -f 1) -ge 10 ]]; then echo "${pgv}" | cut -d "." -f 1; else echo "${pgv}" | cut -d "." -f 1,2; fi );
|
||||
DUMP_DB_VERSION=$(
|
||||
pgv=$(
|
||||
"${PG_PATH}/pg_dump" --version | \
|
||||
grep "pg_dump" | \
|
||||
cut -d " " -f 3
|
||||
);
|
||||
if [[ $(echo "${pgv}" | cut -d "." -f 1) -ge 10 ]]; then
|
||||
echo "${pgv}" | cut -d "." -f 1;
|
||||
else
|
||||
echo "${pgv}" | cut -d "." -f 1,2;
|
||||
fi
|
||||
);
|
||||
else
|
||||
DUMP_DB_VERSION=${DB_VERSION};
|
||||
fi;
|
||||
@@ -568,7 +561,10 @@ function clean_up
|
||||
TO_DELETE=$((count-KEEP));
|
||||
echo "- Remove old backups for '${name}', found ${count}, will delete ${TO_DELETE}";
|
||||
if [ ${TEST} -eq 0 ]; then
|
||||
find "${BACKUPDIR}" -name "${name}${DB_TYPE}*.sql" -type f -printf "%Ts\t%p\n" | sort -nr | head -n ${TO_DELETE} | xargs rm;
|
||||
find "${BACKUPDIR}" -name "${name}${DB_TYPE}*.sql" -type f -printf "%Ts\t%p\n" | \
|
||||
sort -n | \
|
||||
head -n ${TO_DELETE} | \
|
||||
xargs rm;
|
||||
else
|
||||
print "find \"${BACKUPDIR}\" -name \"${name}${DB_TYPE}*.sql\" -type f -printf \"%Ts\\t%p\\n\" | sort -nr | head -n ${TO_DELETE} | xargs rm";
|
||||
fi;
|
||||
|
||||
Reference in New Issue
Block a user