0

i would like to take backup and restore of my postgresql database automatically.

  1. take backup automatically from postgresql with cron trigger in windows pc
  2. later i will do restore when ever it required.

i have below bat commands to take back up of my database

F:
cd F:\softwares\postgresql-12.1-3-windows-x64-binaries\pgsql\bin
pg_dump.exe -U postgres -s fuelman > E:\fuel_man_prod_backup\prod.sql
cmd /k

but i am getting

pg_dump: error: too many command-line arguments (first is "-s")

also i need to take both schema structure with data.

Edit :- removed password -W

1
  • 1
    -s means schema only. And when only have a backup of the schema, you don't have the data. And it looks like a \ is missing in your command, but I'm not familiar with Windows Commented Dec 29, 2022 at 13:59

1 Answer 1

1
  1. "Too many command line" probably is due to -W option; the string "postgres" after -W is interpreted as db name, so following -s gives error. Anyway, when running pg_dump from a script you must not use -W; use .pgpass file or set PGPASSWORD environment variable (look at pg_dump: too many command line arguments for more details).

  2. As for Frank Heikens comment, if you need to dump both object definition and data, avoid -s option. pg_dump documentation is quite clear.

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

3 Comments

yeah i removed -w and now it takes dump of object definition, but i need to enter password manually, is there a ways to take password input from cmd automatically?
ok got it .pgpass would work..
As already written: use .pgpass file or set PGPASSWORD environment variable

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.