for MySql, I use this to generate somehting I can pipe into the CLI:
print """
DROP DATABASE IF EXISTS %(db)s;
CREATE DATABASE %(db)s;
GRANT ALL
ON %(db)s.*
TO %(user)s
IDENTIFIED BY '%(pw)s'
with grant option;
""" % {
'db':settings.DATABASE_NAME,
'user':settings.DATABASE_USER,
'pw':settings.DATABASE_PASSWORD }
pipe that into the MySql CLI.
I can't figure out how to do it with psql without it prompting me for input.
I don't need it that fancy, just a script with everything hard coded would be
fine.
Carl K
psql will happily take piped input - you might need to edit
/etc/postgres/pg_hba.conf (or similar location) and you might need to
add your user - if it's prompting for a password then the only way I
know of getting round the password issue is to specify it as the
environmental variable PGPASSWD.
Hope that helps,
--
Brett Parker
PG_USER="_postgresql"
PG_PASS="password"
DB_HOST="127.0.0.1"
PREFIX="/backups/pgsql/`date "+%d"`"
DB="db_name"
echo $YOURSQL | PGUSER="$PG_USER" PGPASSWORD="$PG_PASS" psql -h $DB_HOST $DB
or:
PGUSER="$PG_USER" PGPASSWORD="$PG_PASS" psql -h $DB_HOST $DB -C "$YOURSQL"
--
Anton P. Linevich