2

I'm writing a backup script in VBScript for a PostgreSQL 9.1 database on a Window 7.

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run postgresqlPath & "pg_dump.exe " & ServerId & " > " &  backupFolder & "Database.dump.out"
Wscript.Sleep 500
 objShell.SendKeys "Password~"

This script seems to run twice and returns no file in the destination folder.

To exclude errors in the path I had tried the command into the command-line tool, there everything worked fine as expected.

Any hints are appreciated

4
  • 1
    Use -f file to specify output file. And do not forget to put " around backupFolder . Commented Nov 29, 2012 at 16:12
  • 1
    Also try using the PGPASSWORD environment variable to pass password to pg_dump. Commented Nov 29, 2012 at 16:13
  • Hi, thanks! backup folder is a variable for the path, so " want do no good. The SendKey is working fine, I'm also using it for createdb.exe. No Problem there. What might be a little misunderstanding in the script is the Server ID, it is actually the name of the database I want to drop. I tried the -f option and it not working too. Even without the SendKeys I' m not asked for password, what is quite strange. Commented Nov 30, 2012 at 7:13
  • I tried to put the password into the C:\Users\myUser\AppData\Roaming\postgresql\pgpass.conf file. This works fine when I'm using the command line tool (C:/.../pg_dump.exe -U postgres DbName > C:/backupFolder/Database.dump.out). As soon as I'm using the vbscript my luck is gone. I also tried the PGPASSWORD environment variable @IgorRomanchenko mentioned, but didn't succeed. Besides adding the PGPASSWORD into the global environment variables, do I have to add something into objShell.Run postgresqlPath & "pg_dump.exe " & ServerId & " > " & backupFolder & "Database.dump.out" Commented Dec 6, 2012 at 10:16

1 Answer 1

2

You can also use a DOS script

pg_dump --host 192.168.0.1 --port 5432 --username "postgres" --role "postgres" --no-password --format plain --encoding UTF8 --inserts --verbose --file "C:\backup\mydatabase%ldt%.sql" "mydatabase"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.