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

pappu_kutty
  • 2,378
  • 8
  • 49
  • 93
  • 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 – Frank Heikens Dec 29 '22 at 13:59

1 Answers1

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.

gile
  • 5,580
  • 1
  • 25
  • 31