Visual Basic Foro
Programación => Bases de Datos => Mensaje iniciado por: javierjava en Septiembre 22, 2011, 06:33:24 pm
-
Que tal disculpen la molestia estoy tratando de sacar un backup en mysql y esto usando este codigo
ShellAndWait "cmd /c c:\windows\system32\mysqldump.exe -u" & "root" & " -p" & "****" & " -h" & "localhost" & " > " & aqui pongo la ubicacion donde guardar
nome funciona me saca el archivo en blanco no se si alguien me puede ayudar en como hacerlo o que estoy haciendo mal.
gracias.
-
a ver. Prueba asi...!
Private Sub Command1_Click()
Set comando1 = CreateObject("WSCript.shell")
comando1.run "cmd /K C:\windows\system32\mysqldump.exe -u " & "root" & " -p" & "****" & " -h" & "localhost" & " > " & " C:/Backup.sql "
Set comando1 = Nothing
End Sub
-
Gracias por responder prove el codigo pero me dice que no reconoce el comando :-[
-
Yo también estaba con este problema la verdad no pude solucionar desde VB6, pero encontré otro método. Creando un archivo .bat
En verdad este es para crear la BD. Pero vas a poder adatar a lo que necesitas.
@echo off
title=Espere un momento creando la base Datos...
color 47
echo Espere un momento creando la base Datos...
Ping -n 6 localhost >nul
cd C:\wamp\bin\mysql\mysql5.5.8\bin
mysql --user=root --password=root < c:\bdhotel\control_hotel.sql
-
no tenes que llamar a la ventana de comandos de windows ahi esta el error en el "cmd /c", simplemente llamas al mysqldump y listo el se encarga de todo en segundo plano.
saludos.
-
Gracias me funciono lo del bat gracias por la ayuda
-
no tenes que llamar a la ventana de comandos de windows ahi esta el error en el "cmd /c", simplemente llamas al mysqldump y listo el se encarga de todo en segundo plano.
saludos.
Seba como seria el codigo ese?
-
para tirarlo a un archivo, se usa el parametro -r
Yo tuve que hacerlo tambien, y bueno, leyendo un poco la ayuda del mysqldump.. queda
Call Shell("C:\windows\system32\mysqldump.exe -uroot -p" & "****" & " -h" & "localhost" & " -r " & " C:/Backup.sql " & " miBD")
:D
-
no tenes que llamar a la ventana de comandos de windows ahi esta el error en el "cmd /c", simplemente llamas al mysqldump y listo el se encarga de todo en segundo plano.
saludos.
Seba como seria el codigo ese?
es algo asi
vCadena = "C:\windows\system32\mysqldump.exe -u root -p" & passwordRoot & " " & vBaseDeDatos & " -h " & vServidor & " --result-file=" & vNombreBackup
esa cadena se la pasas a una funcion que se llama ShellandWait que la podes encontrar por ahi, que ejucuta ese comando en la consola de forma oculta y cuando termina devuelve el control a la aplicacion.
saludos
-
Una opción elegante de backup que nos da el colega
Evitando mysqldump!!! (Ojo,No porque sea mala la Opción!!!)
Se tomo el trabajo de hacer lo que los programers en algún momento
pensamos hacer y no hicimos nunca ... asi que por respeto al colega,
si usan estas funciones ... Los Créditos
Funciones: dbMakeBackup y dbRestoreBackup
Nos permite hacer un backup en un archivo plano
Condiciones:
Debe existir una variable global llamada "cn" del tipo ADODB.Connection
la cual está apuntando a la base de datos que se quiere respaldar
PARAMETROS:
(obligatorio)strFileName >>> Nombre del archivo plano donde se desea dejar el Backup
IncludeCreateDB >>> Incluye en el Backup los comandos DROP DATABASE y el CREATE DATABASE
IncludeStructure >>> Incluye en el Backup la creación de las estructuras de tablas de la base de datos.
IncludeData >>> Incluye en el Backup los datos de cada tabla.
AUTOR: Williams Castillo - will@eduven.com
FECHA ULTIMA MODIFICACION: 24/01/2006
POR HACER: Está desarrollado para versiones anteriores a la 5.0 Falta incluir los stored procedures y triggers para hacerla 100% compatible con MySQL 5.0 y posteriores.
Public Sub dbMakeBackup(ByVal strFileName As String, Optional IncludeCreateDB As Boolean = True, Optional IncludeStructure As Boolean = True, Optional IncludeData As Boolean = True)
Dim rss As ADODB.Recordset
Dim rssAux As ADODB.Recordset
Dim x As Long, i As Integer
Dim strTableName As String
Dim strCurLine As String
Dim strBuffer As String
Dim strDBName As String
'On Error Resume Next
x = FreeFile
Open strFileName For Output As x
Print #x, ""
Print #x, "#"
Print #x, "# Respaldo creado por: "; App.Title & " v" & App.Major & "." & App.Minor & "." & App.Revision
strDBName = Mid$(cn.ConnectionString, , InStr(cn.ConnectionString, "DATABASE=") + 9)
strDBName = Left(strDBName, InStr(strDBName, ";") - 1)
Print #x, "# Base datos: " & strDBName
Set rss = New ADODB.Recordset
Set rssAux = New ADODB.Recordset
'Print #X, "# Fecha/Hora: " & Format(Now, "DD/MM/YYYY HH:MM:SS")
rss.Open "SHOW VARIABLES LIKE 'version';", cn
If Not rss.EOF Then
Print #x, "# DBMS: MySQL v" & rss.Fields(1)
End If
rss.Close
Print #x, "#"
If IncludeData Then
Print #x, ""
Print #x, "SET FOREIGN_KEY_CHECKS=0;"
End If
Print #x, ""
If IncludeCreateDB Then
Print #x, "DROP DATABASE IF EXISTS `" & strDBName & "`;"
Print #x, "CREATE DATABASE `" & strDBName & "`;"
End If
Print #x, "USE `" & strDBName & "`;"
strTableName = ""
With rss
.Open "SHOW TABLE STATUS", cn
Do While Not .EOF
strTableName = .Fields.Item("Name").Value
If IncludeStructure Then
With rssAux
.Open "SHOW CREATE TABLE " & strTableName, cn
Print #x, ""
Print #x, "#"
Print #x, "# Estructura de la tabla " & strTableName & ""
Print #x, "#"
If Not IncludeCreateDB Then
Print #x, "DROP TABLE IF EXISTS `" & strTableName & "`;"
End If
Do While Not .EOF
Print #x, .Fields.Item(1).Value & ";"
.MoveNext
Loop
.Close
End With
End If
If IncludeData Then
With rssAux
.Open "SELECT * FROM " & strTableName & "", cn
Print #x, ""
Print #x, "#"
Print #x, "# Datos de la tabla " & strTableName & ""
Print #x, "#"
' Print #X, "LOCK TABLES `" & strTableName & "` write;"
If Not .EOF Then
Print #x, "INSERT INTO `" & strTableName & "` VALUES "
Do While Not .EOF
strCurLine = ""
For i = 0 To .Fields.Count - 1
strBuffer = .Fields.Item(i).Value
' If IsNull(.Fields.Item(I).Value) = True Then
' If strCurLine <> "" Then
' strCurLine = strCurLine & ", "
' End If
' strCurLine = strCurLine & "Null"
' Else
' strBuffer = .Fields.Item(I).Value
If .Fields.Item(i).Type = 131 Then
strBuffer = Replace(Format(strBuffer, "0.00"), ",", ".")
End If
strBuffer = Replace(strBuffer, "\", "\\")
strBuffer = Replace(strBuffer, "'", "\'")
strBuffer = Replace(strBuffer, Chr(10), "")
strBuffer = Replace(strBuffer, Chr(13), "\r\n")
If strCurLine <> "" Then
strCurLine = strCurLine & ", "
End If
strCurLine = strCurLine & "'" & strBuffer & "'"
'End If
Next
.MoveNext
strCurLine = "(" & strCurLine & ")"
If .EOF Then
Print #x, strCurLine & ";"
Else
Print #x, strCurLine & ","
End If
Loop
End If
' Print #X, "UNLOCK TABLES;"
.Close
End With
Print #x, "#--------------------------------------------"
End If
.MoveNext
Loop
Print #x, ""
Print #x, "SET FOREIGN_KEY_CHECKS=1;"
Print #x, ""
' Print #X, "# Fin del Respaldo: " & Format(Now, "DD/MM/YYYY HH:MM:SS")
.Close
End With
Close #x
End Sub
Public Sub dbRestoreBackup(ByVal strFileName As String)
Dim TotalBytes As Long, CurrentBytes As Long
Dim x As Integer, strCurLine As String, strAux As String
Dim blnPassLines As Boolean
Dim blnAnalizeIt As Boolean
x = FreeFile
On Error GoTo ErrorsDrv
' Call dbBeginTX
cn.BeginTrans
Open strFileName For Input As #x
TotalBytes = LOF(x)
blnPassLines = False
Do While Not EOF(x)
Line Input #x, strCurLine
CurrentBytes = CurrentBytes + LenB(strCurLine)
' #If IS_A_PLUGGIN = 0 Then
' Call UpdateProgressBar(TotalBytes, CurrentBytes)
' Call MyDoEvents
' #End If
blnAnalizeIt = True
strCurLine = Trim(strCurLine)
If Not blnPassLines Then
If Left(strCurLine, 1) = "#" Then
blnAnalizeIt = False
ElseIf Left(strCurLine, 2) = "/*" Then
blnAnalizeIt = False
blnPassLines = True
End If
ElseIf Right(Trim(strCurLine), 2) = "*/" Then
blnPassLines = False
blnAnalizeIt = False
End If
If blnAnalizeIt And strCurLine <> "" Then
While Mid(strCurLine, Len(strCurLine), 1) <> ";"
strAux = strCurLine
Line Input #x, strCurLine
CurrentBytes = CurrentBytes + LenB(strCurLine)
strCurLine = Trim(strCurLine)
' #If IS_A_PLUGGIN = 0 Then
' Call UpdateProgressBar(TotalBytes, CurrentBytes)
' Call MyDoEvents
' #End If
strCurLine = strAux & strCurLine
Wend
' Call dbExecuteSQL(strCurLine)
cn.Execute strCurLine
End If
' #If IS_A_PLUGGIN = 0 Then
' Call MyDoEvents
' #End If
Loop
Close #x
' #If IS_A_PLUGGIN = 0 Then
' Call UpdateProgressBar(TotalBytes, TotalBytes)
' #End If
' Call dbCommitTX
cn.CommitTrans
Exit Sub
ErrorsDrv:
' Call dbRollbackTX
cn.RollbackTrans
MsgBox "ERROR:" & Err.Number & vbNewLine & Err.Description & vbNewLine, vbCritical
Err.Clear
Exit Sub
Resume 'Debugging purpouses...
End Sub
-
Interesante, vamos a probar...
Gracias por compartir...