gpt4 book ai didi

postgresql - 备份 PostgreSQL 数据库的简单脚本

转载 作者:行者123 更新时间:2023-11-29 13:02:53 27 4
gpt4 key购买 nike

<分区>

你好,我写了一个简单的批处理脚本来备份postgeSQL数据库,但是我发现一个奇怪的问题,pg_dump命令是否可以指定密码?

有批处理脚本:

 REM script to backup PostgresSQL databases
@ECHO off

FOR /f "tokens=1-4 delims=/ " %%i IN ("%date%") DO (

SET dow=%%i
SET month=%%j
SET day=%%k
SET year=%%l
)

SET datestr=%month%_%day%_%year%
SET db1=opennms
SET db2=postgres
SET db3=sr_preproduction
REM SET db4=sr_production

ECHO datestr is %datestr%

SET BACKUP_FILE1=D:\%db1%_%datestr%.sql
SET FIlLENAME1=%db1%_%datestr%.sql

SET BACKUP_FILE2=D:\%db2%_%datestr%.sql
SET FIlLENAME2=%db2%_%datestr%.sql

SET BACKUP_FILE3=D:\%db3%_%datestr%.sql
SET FIlLENAME3=%db3%_%datestr%.sql

SET BACKUP_FILE4=D:\%db14%_%datestr%.sql
SET FIlLENAME4=%db4%_%datestr%.sql

ECHO Backup file name is %FIlLENAME1% , %FIlLENAME2% , %FIlLENAME3% , %FIlLENAME4%

ECHO off
pg_dump -U postgres -h localhost -p 5432 %db1% > %BACKUP_FILE1%
pg_dump -U postgres -h localhost -p 5432 %db2% > %BACKUP_FILE2%
pg_dump -U postgres -h localhost -p 5432 %db3% > %BACKUP_FILE3%
REM pg_dump -U postgres -h localhost -p 5432 %db4% > %BACKUP_FILE4%

ECHO DONE !

请多多指教

问候米克

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com