Código vb.net:
Ver originalImports MySql.Data.Common
Imports MySql.Data.MySqlClient
Imports System.IO
Public Class BaseDeDatos
' Genera un backup para el estado actual de la base de datos.
Public Function GenerarBackup(ByVal directorio As String) As Boolean
' -----------------------------------------------------------
Dim NombreBackup As String = "Backup_" & DateTime.Now.ToString("yyyyMMddhhmmss")
Dim Comando As String
Comando = """" & Application.StartupPath & "\mysqldump.exe" & """" & " -u" & UserName & " -p" & PasWord & " --host=" & IpHost & " --routines=TRUE --opt --single-transaction fulmar > " & """" & oWorkDisk & "Backups\" & NombreBackup & ".sql"""
Try
Dim myProcess As New Process
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.WorkingDirectory = oWorkDisk
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.StartInfo.CreateNoWindow = True
myProcess.Start()
Dim myStreamWriter As StreamWriter = myProcess.StandardInput
Dim mystreamreader As StreamReader = myProcess.StandardOutput
myStreamWriter.WriteLine(Comando)
myProcess.Wait For Exit()
Catch ex As MySqlException
oLogWriter.Escribir("Excepción MySQL en GenerarBackup()" & vbNewLine & ex.Message & vbNewLine & ex.StackTrace.ToString)
Return False
Catch ex As Exception
SinDatos = True
oLogWriter.Escribir("Excepción en GenerarBackup()" & vbNewLine & ex.Message & vbNewLine & ex.StackTrace.ToString)
Return False
End Try
Return True
End Function
End Class
Variables declaradas en el Módulo:
Código vb.net:
Ver originalFriend oWorkDisk As String = Environment.GetLogicalDrives(0)
Friend IpHost, UserName, PasWord As String
Este método requiere que en el PATH del sistema esté presente la rut aal /bin de MySQL.
Nota: Tuve que poner en una línea, por separado Wait For Exit porque aparentemente es alguna frase reservada en el funcionamiento de los posts y me la suprime. Obviamente va sin espacios.