문제

I need to create 2 .bat files:

  1. To dump my PostgreSQL database
  2. To restore the PostgreSQL database

How can I move out variables (database name, login, passw, etc...) to an external file so both .bat files can use the same external file with variable declarations.

Thanks!

도움이 되었습니까?

해결책

File #1, e.g. setup_env.cmd

set server=localhost
set db=postgres
set port=5432

File #2, e.g. do_dump.cmd

call ~dp0setup_env.cmd
pg_dump -h %server% -p %port% %db%

다른 팁

with defaults:

set server=localhost
set db=yourdb
set port=5432

if {%1}=={} goto dostuff
set server=%1

if {%2}=={} goto dostuff
set db=%2

if {%3}=={} goto dostuff
set port=%3


:dostuff

ECHO


<your command> %server% %db% %port%

You can call it from different file:

call dump.bat <servername> <dbname> <portnumber>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top