VBScript to run a mySQL Backup Command
I’ve decided to start sharing the litle snipets of insight I might have into programming and system management. I finally had time to sit down and actually write this code to start backing up my mysql databases using the windows scheduler.
Now obviously there are other, more efficient ways to do your backups, but this is the way I have chosen for now.
Enjoy!
‘ backup of all mysql databases
option explicit
‘*******************************************
‘ Declare Variables for script use
‘*******************************************
const DIVISOR = 7
dim fso, WshShell, WshSysEnv, mySqlBackupCommand
dim backupPath, mySqlBackupPath
call doBackup
‘*******************************************
‘ Folder/File Declarations
‘*******************************************
‘*******************************************
‘ FUNCTIONS
‘*******************************************
function doBackup
‘*******************************************
‘ Create script Objects
‘*******************************************
set fso = CreateObject("Scripting.FileSystemObject")
set WshShell = Wscript.CreateObject("Wscript.Shell")
set WshSysEnv = WshShell.Environment("Process")
‘ Set them
mySqlBackupPath = "%PATH-TO-BACKUP-FOLDER%\mysql-wk-"
mySqlBackupPath = mySqlBackupPath & Round(Day(Now) / DIVISOR) & ".sql"
mySqlBackupCommand = "cmd /c %PATH-TO-MYSQL-INSTALL-DIRECTORY%\bin\mysqldump.exe –add-drop-table –add-locks -e -f -u%USER% -p%PASSWORD% –all-databases > " & mySqlBackupPath
‘ msgbox mySqlBackupCommand
WshShell.Run mySqlBackupCommand
end function
Tags: Software