Created
April 21, 2016 19:14
-
-
Save zyuskin/dac924c531c02d202c2fb20de5366354 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal | |
set year=%date:~6,4% | |
set month=%date:~3,2% | |
set day=%date:~0,2% | |
set backup_path=D:\backup\postgres | |
set pg_sql=C:\"Program Files"\PostgreSQL\9.4.2-1.1C\bin\psql.exe | |
set pg_dump=C:\"Program Files"\PostgreSQL\9.4.2-1.1C\bin\pg_dump.exe | |
set pg_host="localhost" | |
set pg_port=5432 | |
set pg_username="postgres" | |
set pg_password="postgres" | |
set pg_role="postgres" | |
set pg_sql_databases_list="select array_to_string(array(select datname from pg_database where datname not in ('template0','template1','postgres') order by datname), ',')" | |
set databases= | |
IF NOT "%databases%"=="" goto :databasespars | |
FOR /F "usebackq" %%a IN (`%pg_sql% -t -U %pg_username% -c %pg_sql_databases_list%`) DO ( | |
set databases=%%a | |
) | |
:databasespars | |
call :parse "%databases%" | |
goto :eos | |
:parse | |
set list=%1 | |
set list=%list:"=% | |
FOR /f "tokens=1* delims=," %%a IN ("%list%") DO ( | |
if not "%%a" == "" call :sub %%a | |
if not "%%b" == "" call :parse "%%b" | |
) | |
goto :eos | |
:sub | |
%pg_dump% --host %pg_host% --port %pg_port% --username %pg_username% --role %pg_role% --no-password --format custom --blobs --compress 9 --encoding UTF8 --file "%backup_path%\%1-%day%-%month%-%year%.backup" %1 | |
goto :eos | |
:eos | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment