定时备份postgressql数据库

1.1在postgresql数据库目录下C:\Program Files\PostgreSQL\9.4新建bat文件:pg_backup.bat,内容如下:
@ECHO OFF
@setlocal enableextensions
@cd /d "%~dp0"
SET PGPATH=C:\"Program Files"\PostgreSQL\9.4\bin\pg_dump
SET SVPATH=D:\postgres\backup\
SET DBNAME=njcdc20180510
SET DBUSR=postgres
SET DBROLE=postgres
if not exist %SVPATH% md %SVPATH%
FOR /F "TOKENS=1,2,3 DELIMS=/ " %%i IN ('DATE /T') DO SET d=%%i-%%j-%%k
FOR /F "TOKENS=1,2,3 DELIMS=: " %%i IN ('TIME /T') DO SET t=%%i%%j%%k
SET DBDUMP=%DBNAME%_%d%_%t%.backup
@ECHO OFF
%PGPATH% -h localhost -p 5432 -U %DBUSR% --role %DBROLE% -w -F c -b -v -f %SVPATH%%DBDUMP% %DBNAME% 
echo Backup Taken Complete %SVPATH%%DBDUMP%

1.2在数据库data目录下C:\Program Files\PostgreSQL\9.4\data新建文件:pgpass.conf,内容如下:localhost:5432:njcdc20180510:postgres:postgres
注:ip:端口:数据库名:用户名:密码

1.3在环境变量得系统变量中新建:变量名: PGPASSFILE,变量值: C:\Program Files\PostgreSQL\9.4\data\pgpass.conf

1.4运行taskschd.msc把pg_backup.bat配置为windows计划任务。

你可能感兴趣的:(备份)