PostgresSQL不像SQLServer一样提供了作业管理器来定时自动备份数据库,需要用户自己使用pgdump来手动备份。
@echo off for /f "tokens=1-4 delims=/ " %%i in ("%date%") do ( set year=%%i set month=%%j set day=%%k set dow=%%l ) set datestr=%year%_%month%_%day% echo datestr is %datestr% SET SAVEPATH=D:\ SET PGPATH=C:\"Program Files"\PostgreSQL\10\bin\ SET PGUSER=postgres SET PGPASSWORD=postgres SET PGDB=report set BACKUP_FILE=%SAVEPATH%%PGDB%_%datestr%.backup echo backup file is %BACKUP_FILE% echo on %PGPATH%pg_dump -h localhost -p 5432 -U %PGUSER% -F c -b -v -f %BACKUP_FILE% %PGDB% @echo Backup Completed. @echo Backup File: %BACKUP_FILE%
参考:https://wiki.postgresql.org/wiki/Automated_Backup_on_Windows
如果一个数据库下有多个模式,怎么指定备份某个模式下的数据呢
https://www.postgresql.org/docs/current/app-pgdump.html
有个 –schema 参数指定