首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

Windows上Postgres数据库自动备份

2013-02-28 
Windows下Postgres数据库自动备份1、首先新建一个bat文件,用来执行数据库备份命令。内容如下:(路径、IP、文件

Windows下Postgres数据库自动备份

1、首先新建一个bat文件,用来执行数据库备份命令。

内容如下:(路径、IP、文件名等按需指定)

@ECHO OFF @set DirName=%date:~0,7% @set FileName=%date:~0,10%_DB_NAME.backup @if %date:~8,2% == 01 (md E:\DBbackup\"%DirName%") @if not exist E:\DBbackup\"%DirName%" (md E:\DBbackup\"%DirName%") @if not exist %DirName% (md %DirName%) "D:\PostgreSQL\9.1\bin\pg_dump.exe" -i -h xxx.xxx.xxx.xxx -p 5432 -U postgres -Ft -f E:\DBbackup\%FileName% DB_NAME@ECHO ON 

2、执行上边的bat时会要求输入数据库密码,为解决该问题,

需创建postgres密码文件“pgpass.conf”,

内容为“xxx.xxx.xxx.xxx:5432:DB_NAME:postgres:PASSWORD”

放在“D:\PostgreSQL\9.1\data”路径下,

并新建环境变量【PGPASSFILE】值为“D:\PostgreSQL\9.1\data\pgpass.conf”,这样运行时就不需要输入密码了。


3、最后把bat放到任务计划中,每天执行即可。

热点排行