The original script was found in the MySQL 5.1 Reference Manual - thanks to Wade Hedgren for posting this.

To use this script, you will need to download gzip (GNU zip) Windows executables (if you haven’t already) and create a new batch file.

You will need to adapt the script to suit your needs, by changing the bkupdir, mysqldir, datadir, logdir, dbuser, dbpass, zip and endtime parameters. I referred to Stack Overflow to figure out how to format the date:

@echo off

:: Set some variables
 set bkupdir=C:backupmysql
 set mysqldir=C:xamppmysql
 set datadir=C:xamppmysqldata
 set logdir=C:xamppmysqllogs
 set dbuser=root
 set dbpass=dbpasswd
 set zip=C:gzip.exe
 set endtime=0

:GETTIME

:: get the date and then parse it into variables
 for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%b-%%a)

:: get the time and then parse it into variables
 for /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)

:: If this is the second time through then go to the end of the file
 if "%endtime%"=="1" goto END

:: Create the filename suffix
 set fn=_%mydate%_%mytime%

:: Switch to the data directory to enumerate the folders
 pushd %datadir%

:: Write to the log file
 echo Beginning MySQLDump Process > %logdir%LOG%fn%.txt
 echo Start Time = %mydate% %mytime% >> %logdir%LOG%fn%.txt
 echo --------------------------- >> %logdir%LOG%fn%.txt
 echo. >> %logdir%LOG%fn%.txt

:: Loop through the data structure in the data dir to get the database names
 for /d %%f in (*) do (

:: Create the backup sub-directory is it does not exist
 if not exist %bkupdir%%%f (
 echo Making Directory %%f
 echo Making Directory %%f >> %logdir%LOG%fn%.txt
 mkdir %bkupdir%%%f
 ) else (
 echo Directory %%f Exists
 echo Directory %%f Exists >> %logdir%LOG%fn%.txt
 )

:: Run mysqldump on each database and compress the data by piping through gZip
 echo Backing up database %%f%fn%.sql.gz
 echo Backing up database %%f%fn%.sql.gz >> %logdir%LOG%fn%.txt
 %mysqldir%binmysqldump --user=%dbuser% --password=%dbpass% --databases %%f --opt --quote-names --allow-keywords --complete-insert | %zip% > %bkupdir%%%f%%f%fn%.sql.gz
 echo Done...
 echo Done... >> %logdir%LOG%fn%.txt
 )

:: Go back and get the end time for the script
 set endtime=1
 goto :GETTIME

:END
 :: Write to the log file
 echo. >> %logdir%LOG%fn%.txt
 echo --------------------------- >> %logdir%LOG%fn%.txt
 echo MySQLDump Process Finished >> %logdir%LOG%fn%.txt
 echo End Time = %mydate% %mytime% >> %logdir%LOG%fn%.txt
 echo. >> %logdir%LOG%fn%.txt

:: Return to the scripts dir
 popd

To have the script run automatically, simply create a new Scheduled Task.

I hope you find this script useful.

Fix Jekyll Layout Build Warnings

I heart Jekyll and Jekyll hearts me. It's a lean and mean static site generator blogging machine that enables you to 'blog like a hacker'...… Continue reading

OS X Terminal nirvana

Published on March 26, 2014

A Holy Grail Flexbox layout

Published on March 20, 2014