Postgres转储批处理辅助备份目录

时间:2016-02-09 04:03:21

标签: postgresql batch-file directory backup

我正在运行此脚本来备份数据库。它工作,但我想添加一个辅助备份目录,以获取两个不同目录中的输出文件。任何帮助表示赞赏..)

REM Set paths and database info
    set PGPASSWORD='postgre'
    set PGuser='postgres'
    set PGinstance='e3238s'
    set PGdump='F:/Program Files/PostgreSQL/9.5/bin\pg_dump'
    set BackupDir='F:/backup'
    set BackupName='DB_BK'

REM Build a datetime stamp
    set DateTime='%DATE:~-4%_%DATE:~-7,2%_%DATE:~-10,2%_%TIME:~0,2%_%TIME:~3,2% _%TIME:~6,2%'
echo %DateTime%

REM Backup 
    "%PGdump%" -f "%BackupDir%\%BackupName%%DateTime%.sql" --format plain -U %PGuser% -v %PGinstance%

1 个答案:

答案 0 :(得分:0)

这与Postgres完全无关,而且与您在同一次运行中输出两个文件的方式有关。

你可以使用像this这样的东西,在你的情况下,变成:

REM Backup 
    "%PGdump%" --format plain -U %PGuser% -v %PGinstance% >  "%BackupDir%\%BackupName%%DateTime%.sql" & type "%BackupDir%\%BackupName%%DateTime%.sql"  >> "%SecondaryBackupDir%\%BackupName%%DateTime%.sql"