سؤال

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