@echo off


@rem *******************************************************************************************************************


@rem ** Author: Gustavo Moreira


@rem ** 


@rem ** This version is a modification of Robert Lie (Mobilefish.com) version.


@rem **


@rem ** Makes a backup of the semaspv database.


@rem ** One backup file is created: nome_cras_semaspv_<yyyymmdd>_<hhmm>.sql


@rem ** For example: miguel_couto_semaspv_20090520_1252.zip


@rem **


@rem ** Software requirement:


@rem ** - Windos XP


@rem ** - PostgreSQL Client


@rem **


@rem ** This script only works on Windows 2000 and XP because 


@rem ** option "usebackq" is only valid for these operating systems.


@rem **


@rem *******************************************************************************************************************





@rem ALTERE AS SEGUINTES CONFIGURACOES DE ACORDO COM A INSTALACAO NO DETERMINADO CRAS


@rem *** set BACKUP_FILE=xxxxx


set POSTGRE_DIR=C:\PostgreSQL\8.4\bin


set POSTGRE_USER_ACCOUNT=labbiousr


set POSTGRE_USER_PASSWORD=aSdBs&9n.


set POSTGRE_DATABASE=smcult





@rem *******************************************************************************************************************


@rem NAO MEXA NOS CODIGOS ABAIXO!!!


@rem *******************************************************************************************************************





set SCRIPT_DIR=C:\smcult_backup


set BACKUP_DIR=%SCRIPT_DIR%


set SCRIPT_VERSION=1.0





echo ***************************************************************"<br>"


echo Script para gerar arquivos backups de um determinado CRAS"<br>"


echo ***************************************************************"<br>"


echo Versao: %SCRIPT_VERSION%"<br>"


echo Configuracoes:"<br>"


echo Diretorio bin do PostgreSQL: %POSTGRE_DIR% "<br>"


echo Banco: %POSTGRE_DATABASE% "<br>"


echo Usuario: %POSTGRE_USER_ACCOUNT% "<br>"


echo ***************************************************************"<br>"





@rem Fill the day, month en year variables


for /F "usebackq tokens=3 delims=/ " %%i in ('%DATE%') do set d=%%i


for /F "usebackq tokens=2 delims=/ " %%i in ('%DATE%') do set m=%%i


for /F "usebackq tokens=4 delims=/ " %%i in ('%DATE%') do set y=%%i








@rem Fill the hour and minute variables


for /F "usebackq tokens=1 delims=:" %%i in ('%TIME%') do set hour=%%i


for /F "usebackq tokens=2 delims=:" %%i in ('%TIME%') do set minute=%%i


goto create








@rem *** Step 1: Create date dependent directory ***********************************************************************


:create


set datetime=%y%%m%%d%_%hour%%minute%


set dir=%BACKUP_DIR%


if not exist %dir% mkdir %dir%





@rem *** Step 2: Create backup database ********************************************************************************


@rem Do not change anything below unless you know what you are doing


cd %POSTGRE_DIR%


SET PGPASSWORD=postgres


pg_dump -a -f "%dir%\%1_%POSTGRE_DATABASE%_%datetime%.sql" -Fp -O -t usuario -t usuarioatividade -t usuariolazer -t usuarioslocaislazer -t historicousuario -t historicousuarioatividade -t historicousuariolazer -t historicousuariolocaislazer -t visita -U %POSTGRE_USER_ACCOUNT% %POSTGRE_DATABASE%





@rem *** Step 3: Delete the date dependent directory *******************************************************************


@rem ******************************************************


@rem * VERIFY IF %dir% IS SET CORRECTLY                   *


@rem * ONLY THEN ENABLE THE STATEMENT BELOW               *


@rem *                                                    *


@rem ******************************************************


@rem rmdir /S /Q %dir%





