minor improvements

This commit is contained in:
Jorge Holgado 2022-07-26 16:59:28 +02:00
parent 2e243942da
commit 800206d4d9
Signed by: dodger
GPG Key ID: F6701F6CB4D1C826
2 changed files with 62 additions and 21 deletions

View File

@ -5,13 +5,19 @@
####################################
PGDATA=/var/lib/pgsql/12/data
PGDUMP="$(which pg_dump)"
PGDUMPALL="$(which pg_dumpall)"
PGDUMP="${PGDUMP} -h 127.0.0.1"
PGDUMPALL="${PGDUMPALL} -h 127.0.0.1"
PSQL="$(which psql) -h 127.0.0.1"
TODAY="$(date +%Y%m%d)"
NOW="$(date +%Y%m%d%H%M%S)"
# For debugging
WAITSEC=10
####################################
# output folders
####################################
BACKUPDIR="/var/lib/postgres/scripts/get_all_pgmetadata/${HOSTNAME,,}"
LOGDIR="${BACKUPDIR}/logs/"
@ -21,16 +27,35 @@ LOGDIR="${BACKUPDIR}/logs/"
# multi-db support, this is auto
#DIFFILE="${BACKUPDIR}/FULL_${DBNAME}_METADATA.sql"
PSQL="$(which psql) -h 127.0.0.1"
CHANGEFILE=${BACKUPDIR}/$(basename $0 .sh)_changefile_${NOW}.log
DIFFILE=${BACKUPDIR}/$(basename $0 .sh)_changefile_${NOW}.log
LOGFILE=${LOGDIR}/$(basename $0 .sh)_${NOW}.log
SCRIPTLOG="${LOGFILE}"
ERRFILE=${LOGDIR}/$(basename $0 .sh)_${NOW}.err
SCRIPTLOGERR="${ERRFILE}"
####################################
# output options
####################################
# set to 0 to split full metadata into files (DEFAULT behavior)
SPLIT_METADATA=0
# dump user passwords
DUMP_ROLE_PASSWORDS=0
####################################
# DEBUG
####################################
# set to 0 to debug
DEBUG=0
DEBUG=1
# For debugging
WAITSEC=10
####################################
# git usage
####################################

View File

@ -11,12 +11,13 @@
########################################################################
# INIT
########################################################################
DEBUGME="${1:2}"
if [[ "${DEBUGME,,}" = "debug" ]] ; then
DEBUG=0
else
DEBUG=1
fi
# moved to config
#DEBUGME="${1:2}"
#if [[ "${DEBUGME,,}" = "debug" ]] ; then
# DEBUG=0
#else
# DEBUG=1
#fi
CONFIGFILE="$(dirname $(readlink -f $0))/$(basename $(readlink -f $0) .sh).config"
@ -157,6 +158,16 @@ generate_split_metadata()
done 3< ${FULLMETADATA}
}
dump_all_roles()
{
debug_me
if [[ ${DUMP_ROLE_PASSWORDS} -eq 0 ]] ; then
${PGDUMPALL} --roles-only > ${OUTPUTDIR}/dump_roles.sql
else
${PGDUMPALL} --roles-only --no-role-passwords > ${OUTPUTDIR}/dump_roles.sql
fi
}
init_staff()
{
[[ ! -d ${BACKUPDIR} ]] && mkdir -p ${BACKUPDIR}
@ -218,11 +229,11 @@ if [[ "$(tty)" = "not a tty" ]] ; then
exec 2> ${SCRIPTLOGERR}
elif [[ ${DEBUG} -eq 0 ]] ; then
echo -e "${BLUE}DEBUGMODE${RESET} is on"
echo -e "\t SCRIPTLOG will be ${SCRIPTLOG}"
echo -e "\t SCRIPTLOGERR will be ${SCRIPTLOGERR}"
set -x
exec > ${SCRIPTLOG}
exec 2> ${SCRIPTLOGERR}
#echo -e "\t SCRIPTLOG will be ${SCRIPTLOG}"
#echo -e "\t SCRIPTLOGERR will be ${SCRIPTLOGERR}"
#set -x
#exec > ${SCRIPTLOG}
#exec 2> ${SCRIPTLOGERR}
fi
[[ ${DEBUG} -eq 0 ]] && DEBUGME="bash -x"
@ -235,13 +246,18 @@ debug_me
for DBNAME in ${DATABASES} ; do
FULLMETADATA="${BACKUPDIR}/FULL_${DBNAME}_METADATA.sql"
debug_me "generate_full_metadata"
generate_full_metadata
debug_me
if [[ ${SPLIPT_METADATA} -eq 0 ]] ; then
debug_me "generate_split_metadata"
generate_split_metadata
debug_me
fi
debug_me "dump_all_roles"
dump_all_roles
done
if [[ ${ISGITREPO} -eq 0 ]] ; then
debug_me "upload_to_git"
upload_to_git
fi