; ===========================================================================================
;
; Script Information
;
; Title: MySQL 5.1 Dump
; Author: Wim Rotty
; Description: Backup (Dump) all databases on a MySQL 5.1 server to separate files
; MySQLDump is used with --add-drop-table
;
; ===========================================================================================
;Script Options
If Not @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $RC
$RC = SetOption("Explicit", "On")
$RC = SetOption("NoMacrosInStrings", "On")
$RC = SetOption("NoVarsInStrings", "On")
If @SCRIPTEXE = "KIX32.EXE"
$RC = SetOption("WrapAtEOL", "On")
EndIf
;Declare variables
Dim $MySQLData
Dim $MySQLDump
Dim $INI
Dim $UserName, $Password
Dim $BZip
Dim $BackupPath
Dim $MySQLDumpBatchJob
Dim $Dirs, $Dir
Dim $Handle
;Initialize variables
$MySQLData=ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB\MySQL Server 5.1","DataLocation")+"data\"
If @error
Exit @error
EndIf
$MySQLDump=ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB\MySQL Server 5.1","Location")+"bin\mysqldump.exe"
If @error
Exit @error
EndIf
$INI = @SCRIPTDIR+'\'+Join(Split(@SCRIPTNAME,'.'),'.',UBound(Split(@SCRIPTNAME,'.')))+'.ini'
If Exist($INI) = 0
Exit 2
EndIf
$UserName=ReadProfileString($INI,'MySQL','UserName')
If @ERROR
Exit @ERROR
EndIf
$Password=ReadProfileString($INI,'MySQL','Password')
If @ERROR
Exit @ERROR
EndIf
$BackupPath=ReadProfileString($INI,'MySQL','BackupPath')
If $BackupPath = ''
$BackupPath=@SCRIPTDIR+'\'
Else
If Not Right($BackupPath,1) = '\'
$BackupPath=$BackupPath+'\'
EndIf
If Not Exist($BackupPath)
$BackupPath=@SCRIPTDIR+'\')
EndIf
$BZip=ReadProfileString($INI,'MySQL','BZip')
If Not Exist($BZip)
$BZip = ''
EndIf
$MySQLDumpBatchJob=$BackupPath+Join(Split(@SCRIPTNAME,'.'),'.',UBound(Split(@SCRIPTNAME,'.')))+'.cmd'
If Exist($MySQLDumpBatchJob)
Exit 5
EndIf
;Code
$Dirs = DIRPlus($MySQLData, '/AD')
$Handle = FreeFileHandle()
$RC = Open($Handle,$MySQLDumpBatchJob,5)
For Each $Dir in $Dirs
If Not $BZip = ''
$RC=WriteLine($Handle,'"'+$MySQLDump+'" --add-drop-table -u"'+$UserName + '" -p"'+$Password+
'" "'+$Dir.Name+'" | "'+ $BZip + '" -c > "'+$BackupPath+$Dir.Name+'.sql.bz2"'+@CRLF)
Else
$RC=WriteLine($Handle,'"'+$MySQLDump+'" --add-drop-table -u"'+$UserName + '" -p"'+$Password+
'" "'+$Dir.Name+'" > "'+$BackupPath+$Dir.Name+'.sql"'+@CRLF)
EndIf
Next
$RC=Close($Handle)
$Dirs=''
$Dir=''
Shell '"%ComSpec%" /C "'+$MySQLDumpBatchJob+'"'
Del $MySQLDumpBatchJob /h /s /c /f
;Personal UDF Section
;UDF Section
;Don't forget to add the DirPlus() UDF