1

I need to do a script that will backup my psql databases, i want to use the wal archive mode and not pg_dump. I've wrote this from a script i found on the web :

#!/bin/bash
#Test Script BackupSQL
PG_SQL_CMD=/opt/novell/idm/Postgres/bin/psql
PG_SQL_USER=postgres
PG_SQL_DB=password
PG_SQL_HOST=localhost

PG_BACKUP_LABEL='backup_label'

PG_BACKUP_START="$PG_SQL_CMD -U $PG_SQL_USER -h $PG_SQL_HOST -c \"select pg_start_backup('$PG_BACKUP_LABEL')\""
PG_BACKUP_STOP="$PG_SQL_CMD -U $PG_SQL_USER -h $PG_SQL_HOST -c \"select pg_stop_backup()\""


echo $PG_BACKUP_START
eval $PG_BACKUP_START
sleep 2
echo $PG_BACKUP_STOP
eval $PG_BACKUP_STOP

My problem is : the script prompt me for the psql password when i run it. I didn't found a way to specify the password in the psql command like you can do in mysql with the -p option.

How can i make the script answer the prompt ?

  • Upvoted Mattias for answering your question, but I see some potential issues with what you written above. Granted it's incomplete, so maybe you'll work it all out, but it seems easier to just reuse some existing scripts for this, like the ones we wrote at github.com/omniti-labs/omnipitr – xzilla Jan 7 '12 at 15:41
1

Try using the .pgpass file for not having to type the password.
See: http://www.postgresql.org/docs/8.3/static/libpq-pgpass.html

Or you can use a shell syntax like the following:

 psql -h database.server.com -U username <<EOF
 sekritpassword
 EOF

Or as a final option you should be able to use the environmental variables PGUSER and PGPASSWD.

0

If you have the following line in your pg_hba.conf file, you don't need to supply a password. You just need to run this command as postgres user.

local   all         all           ident

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.