Skip to content

Instantly share code, notes, and snippets.

@koma5
Created May 18, 2012 11:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save koma5/2724822 to your computer and use it in GitHub Desktop.
Save koma5/2724822 to your computer and use it in GitHub Desktop.
automated mysql dumps on windows - dumps all dbs which user sees
set MYSQLUSER=username
set MYSQLPASS=password
set BATCHFILE=C:\Temp\auto_built_sql_dump.bat
set DUMPPATH=Z:\
set DRIVE=Z:
net use %DRIVE% \\somehost\some\networkdrive /user:domain\user password
rem building time stamp
set tmp_time=%time:~-11,2%.%time:~-8,2%.%time:~-5,2%
set tmp_time=%tmp_time: =0%
set mydate=%date:~-4,4%.%date:~-7,2%.%date:~-10,2%-%tmp_time%
echo @echo off > %BATCHFILE%
echo cd %DUMPPATH% >> %BATCHFILE%
echo %DRIVE% >> %BATCHFILE%
mysql -u%MYSQLUSER% -p%MYSQLPASS% -AN -e"SELECT CONCAT('mysqldump -u%MYSQLUSER% -p%MYSQLPASS% --routines --triggers ',schema_name,' > ',schema_name,'-dump-%mydate%.sql') FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema','performance_schema','mysql')" >> %BATCHFILE%
type %BATCHFILE%
%BATCHFILE%
del %BATCHFILE%
net use Z: /d /yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment