Tuesday, August 16, 2011

Database initialization and getting the last db schema - .bat file template

Batch file template:

@echo Setting database configuration...
@call db-config.bat
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
@echo .
@echo .
@echo .
@echo .
@echo .
@echo .
@echo .
@echo .
mysql -u %USER% --password=%PASS% --execute="DROP database %WORKING_DB%;"
@rem IF NOT %ERRORLEVEL% == 0 GOTO ERROR
mysql -u %USER% --password=%PASS% --execute="CREATE database %WORKING_DB%;"
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
mysql -u %USER% --password=%PASS% %WORKING_DB% < %MYMYSQLDIR%schema.sql @IF NOT %ERRORLEVEL% == 0 GOTO ERROR mysql -u %USER% --password=%PASS% %WORKING_DB% < %MYMYSQLDIR%update.sql @IF NOT %ERRORLEVEL% == 0 GOTO ERROR @rem mysqldump -u %USER% --password=%PASS% %WORKING__DB% --skip-add-drop-table --no-create-info --complete-insert --skip-triggers > %DB_DIR%latest-schema.sql
mysqldump -u %USER% --password=%PASS% %WORKING_DB% --skip-add-locks --skip-disable-keys --skip-set-charset --skip-triggers --skip-quote-names > %DB_DIR%latest-schema.sql
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR

@echo Seems everything to be fine, end with success
@Goto :END

:ERROR
@echo Error, stopping script...
@rem Pause if the script is run in a window (not from command prompt)
@ping -n 10 localhost > nul
@exit /b 1

:END
@exit /b 0


File db-config.bat contains some SET commands, for example:

@SET MYMYSQLDIR=G:\projects\xxx\etc\db\mysql\
@SET USER=root
@SET PASS=superlongandsecretpassword
@SET WORKING_DB=wb2
@exit /b 0

No comments:

Post a Comment