Talk:Automated Backup on Linux

From PostgreSQL wiki

Revision as of 07:56, 1 July 2014 by Adrianlzt (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Hi Guys,

This works well but i have to manually type in the password to access database.

If i need to automate this , i need to have the password read automatically.

Please assist on how to do this.

Maloke

With the default installation postgres user is allowed to access but via socket no via localhost. A quick fix is to remove

-h "$HOSTNAME"

from the psql commands.

--adrianlzt


In the pg_backup.sh script it didn't check if the config file exists:

if [ $# = 0 ]; then
       SCRIPTPATH=$(cd ${0%/*} && pwd -P)
       source $SCRIPTPATH/pg_backup.config
fi;

Without the config file it will not make any backup because this will be empty or false:

SCHEMA_ONLY_DB_LIST=`psql -h "$HOSTNAME" -U "$USERNAME" -At -c "$SCHEMA_ONLY_QUERY" postgres`
if [ $ENABLE_PLAIN_BACKUPS = "yes" ]
if [ $ENABLE_CUSTOM_BACKUPS = "yes" ]


I think that piece of code should be changed to be like the pg_backup_rotated.sh script:

if [ -z $CONFIG_FILE_PATH ] ; then
       SCRIPTPATH=$(cd ${0%/*} && pwd -P)
       CONFIG_FILE_PATH="${SCRIPTPATH}/pg_backup.config"
fi

if [ ! -r ${CONFIG_FILE_PATH} ] ; then
       echo "Could not load config file from ${CONFIG_FILE_PATH}" 1>&2
       exit 1
fi

source "${CONFIG_FILE_PATH}"

--adrianlzt



With Bash 4.1.2: /usr/local/sbin/pg_backup_rotated.sh: line 37: [: too many arguments

Line 37 should be changed to:

if  $BACKUP_USER != "" && "$(id -un)" != "$BACKUP_USER"  ; then
Personal tools