原 在Windows系统中定时pg_dump逻辑导出备份PG或GreenPlum数据库(异机备份、动态生成导出命令)
Tags: 原创PGGreenPlumPostgreSQL备份恢复定时任务逻辑导出导入pg_dump异机备份
脚本
先删除2天前的备份文件,然后开始备份数据库,Z盘可以是映射的网络驱动器。
直接编辑如下的bat文件,然后定时任务调用bat文件即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | rem @echo off chcp 65001 set backupDir=Z:\bk set DaysAgo=2 forfiles /p %backupDir% /s /m *.bk /d -%DaysAgo% /c "cmd /c del /f /q /a @path" set currentDateTime=%date:~3,4%%date:~8,2%%date:~11,2%%time:~0,2%%time:~3,2%%time:~6,2% set "currentDateTime=%currentDateTime: =0%" echo "================= >> begin bk %currentDateTime% " >> %backupDir%\bk_db.log echo "-h 192.168.88.39 -p 5438 %currentDateTime% " >> %backupDir%\bk_db.log D:\PostgreSQL\16\bin\pg_dumpall -U postgres -h 192.168.88.39 -p 5438 --file=%backupDir%\pg_6139_%currentDateTime%.bk set currentDateTime=%date:~3,4%%date:~8,2%%date:~11,2%%time:~0,2%%time:~3,2%%time:~6,2% set "currentDateTime=%currentDateTime: =0%" echo "-h 192.168.88.30 -p 5432 %currentDateTime% " >> %backupDir%\bk_db.log D:\PostgreSQL\16\bin\pg_dumpall -U postgres -h 192.168.88.30 -p 5432 --file=%backupDir%\pg_6130_%currentDateTime%.bk set currentDateTime=%date:~3,4%%date:~8,2%%date:~11,2%%time:~0,2%%time:~3,2%%time:~6,2% set "currentDateTime=%currentDateTime: =0%" echo "-h 192.168.88.21 -p 5432 --dbname=HLHTDB %currentDateTime% " >> %backupDir%\bk_db.log D:\Greenplum\greenplum-clients\bin\pg_dump -U gpadmin -h 192.168.88.21 --dbname=HLHTDB --format=custom --file=%backupDir%\HLHTDB_%currentDateTime%.bk set currentDateTime=%date:~3,4%%date:~8,2%%date:~11,2%%time:~0,2%%time:~3,2%%time:~6,2% set "currentDateTime=%currentDateTime: =0%" echo "================= >> end bk %currentDateTime% " >> %backupDir%\bk_db.log |