mysqldump vc8NZvzcDx62E7fY @echo off :: USE THIS SCRIPT AT YOUR OWN RISK! :: Set some variables set backupdir="D:\Backup" set mysqldir="D:\xampp\mysql" set mysqldatadir="D:\xampp\mysql\data" set logdir="D:\Backup\logs" set dbuser=root set dbpass=vc8NZvzcDx62E7fY set zip="C:\Program Files\WinRAR" set endtime=0 :DODIR :: Do DIR of backupdir to establish network DIR %backupdir% :GETTIME :: get the date and then parse it into variables for /F "tokens=2-4 delims=/ " %%i in ('date /t') do ( set mm=%%i set dd=%%j set yy=%%k ) :: get the time and then parse it into variables for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do ( set hh=%%i set ii=%%j set ss=%%k ) :: 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=_%dd%-%mm%-%yy%_%hh%-%mm%-%ss% :: Switch to the data directory to enumerate the folders pushd %mysqldatadir% :: Write to the log file echo Beginning mysqldump Process > %logdir%\MySQL_LOG%fn%.txt echo Start Time = %yy%-%mm%-%dd% %hh%:%ii%:%ss% >> %logdir%\MySQL_LOG%fn%.txt echo --------------------------- >> %logdir%\MySQL_LOG%fn%.txt echo. >> %logdir%\MySQL_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 %backupdir%\%%f\ ( echo Making Directory %%f echo Making Directory %%f >> %logdir%\MySQL_LOG%fn%.txt mkdir %backupdir%\%%f ) else ( echo Directory %%f Exists echo Directory %%f Exists >> %logdir%\MySQL_LOG%fn%.txt ) :: Run mysqldump on each database and compress the data by piping through gZip echo Backing up database %%f%fn%.sql echo Backing up database %%f%fn%.sql >> %logdir%\MySQL_LOG%fn%.txt %mysqldir%\bin\mysqldump.exe --user=%dbuser% --password=%dbpass% --databases %%f --opt --quote-names --allow-keywords --complete-insert --ignore-table=Territorial_rp.gw_gamelog > %backupdir%\%%f\%%f%fn%.sql :: RAR result echo Compressing Backing %%f%fn%.rar echo Compressing Backing %%f%fn%.rar >> %logdir%\MySQL_LOG%fn%.txt cd c: %zip%\RAR.exe a -pgw -df %backupdir%\%%f\%%f%fn%.rar %backupdir%\%%f\%%f%fn%.sql cd d: echo Done... echo Done... >> %logdir%\MySQL_LOG%fn%.txt ) :: Write to the log file :: echo. >> %logdir%\MySQL_LOG%fn%.txt :: echo --------------------------- >> %logdir%\MySQL_LOG%fn%.txt :: echo Analyzing, optimising and repairing databases :: echo Analyzing, optimising and repairing databases >> %logdir%\MySQL_LOG%fn%.txt :: %mysqldir%\bin\mysqlcheck.exe --all-databases --medium-check --auto-repair --force --use-frm --optimize --analyze --check-only-changed --user=%dbuser% --password=%dbpass% :: echo Done... :: echo Done... >> %logdir%\MySQL_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%\MySQL_LOG%fn%.txt echo --------------------------- >> %logdir%\MySQL_LOG%fn%.txt echo MySQLDump Process Finished >> %logdir%\MySQL_LOG%fn%.txt echo End Time = %yy%-%mm%-%dd% %hh%:%ii%:%ss% >> %logdir%\MySQL_LOG%fn%.txt echo. >> %logdir%\MySQL_LOG%fn%.txt :: Return to the scripts dir :: popd :: Send the log file in an e-mail :: %mailer%\blat.exe %logdir%\MySQL_LOG%fn%.txt -to %to% -f %from% -server %server% :: EXIT