Created
October 1, 2015 16:03
-
-
Save renatoassis01/535133cac97f0a744ab7 to your computer and use it in GitHub Desktop.
Batch Script backup Postgres
This file contains 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 | |
; dependencias: 7-zip, curl | |
rem * ******************************************************************* | |
rem * pg_backup.cmd - PostgresSQL Backup and copy FTP * | |
rem * * | |
rem * Author: Renato Assis * | |
rem * ******************************************************************* | |
set DATESTAMP=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2% | |
set TIMESTAMP=%TIME:~0,2%%TIME:~3,2%%TIME:~6,2% | |
set DATA_HORA=%DATESTAMP%%TIMESTAMP% | |
rem * ******************************************************************* | |
rem * Alterar os parametros abaixo conforme a necessidade * | |
rem * ******************************************************************* | |
set PATH=%PATH%;C:\Program Files\7-Zip\ | |
set PATH=%PATH%;C:\Program Files (x86)\PostgreSQL\8.3\bin\ | |
set PATH=%PATH%;<ROOT_DIR> | |
set PGHOST=localhost | |
set PGPORT=5432 | |
set PGUSER= | |
set PGPASSWORD= | |
set PGDATABASE= | |
set BACKUP_FILE=%PGDATABASE%%DATA_HORA%.backup | |
set DIR_LOCAL_BKP= | |
set CD=<ROOT_DIR> | |
set USER_FTP= | |
set PASS_FTP= | |
set HOST_FTP= | |
set DIR_REMOTE_BKP= | |
set INI_FTP= | |
set LOG_FILE= | |
rem * ******************************************************************* | |
rem * Chamada principal * | |
rem * ******************************************************************* | |
goto __main__ | |
:__main__ | |
goto __backup__ | |
goto __runzip__ | |
goto __ftp__ | |
exit | |
:__backup__ | |
pg_dump -i -h %PGHOST% -p %PGPORT% -U %PGUSER% -F c -b -v -f %DIR_LOCAL_BKP%\%BACKUP_FILE% %PGDATABASE% | |
:__runzip__ | |
e: | |
cd /d %CD% | |
7z.exe a -t7z %BACKUP_FILE%.7z *.backup | |
del *.backup | |
:__ftp__ | |
@echo -T %DIR_LOCAL_BKP%\\%BACKUP_FILE%.7z > %INI_FTP% | |
@echo -u %USER_FTP%:%PASS_FTP% >> %INI_FTP% | |
@echo --url=%HOST_FTP%%DIR_REMOTE_BKP%>>%INI_FTP% | |
curl > %LOG_FILE% -K %INI_FTP% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment