如何从.Bat文件中删除密码提示?

时间:2019-06-13 09:12:37

标签: postgresql batch-file pgagent

我正在为我的PostgreSQL数据库创建每日备份调度程序,为此,我安装了Pg-agent并还创建了作业调度程序。我已经创建了一个.bat文件并在其中编写了脚本,效果很好。我想在命令提示符下执行.bat bat文件时要求输入密码,所以我想删除该文件并执行.bat文件而不要求输入密码。

@echo Backup database  %PG_PATH%%PG_FILENAME%
@echo off
SET PG_BIN="C:\Program Files\PostgreSQL\9.5\bin\pg_dump.exe"
SET PG_HOST=localhost
SET PG_PORT=5432
SET PG_DATABASE=postgres
SET PG_USER=postgres
SET PG_PASSWORD=postgres
SET PG_PATH=C:\OEM
SET FECHAYHORA=%date:/=%-%time:-0,8%
SET FECHAYHORA=%FECHAYHORA::=-%
SET FECHAYHORA=%FECHAYHORA: =0%
SET PG_FILENAME=zerodefect_%time:~0,2%%time:~3,2%%time:~6,2%_%date:~-10,2%%date:~-7,2%%date:~-4,4%.sql
%PG_BIN% -h %PG_HOST% -p %PG_PORT% -U %PG_USER% %PG_DATABASE% > %PG_FILENAME%

@echo Backup Taken Complete %PG_PATH%%PG_FILENAME%

输出:
output

1 个答案:

答案 0 :(得分:0)

变量应命名为PGPASSWORD(不带下划线),如doc

中所述

顺便说一句,您可能希望在脚本的开头添加setlocal,并在脚本的末尾添加endlocal,这样包含密码的变量将从结尾处从内存中删除。 / p>