Autor Tema: Back Up en mysql  (Leído 8101 veces)

0 Usuarios y 1 Visitante están viendo este tema.

javierjava

  • Kilobyte
  • **
  • Mensajes: 69
  • Reputación: +6/-0
    • Ver Perfil
Back Up en mysql
« 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
Código: [Seleccionar]
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.

ssccaann43

  • Moderador
  • Terabyte
  • *****
  • Mensajes: 970
  • Reputación: +97/-58
    • Ver Perfil
    • Sistemas Nuñez, Consultores y Soporte, C.A.
Re:Back Up en mysql
« Respuesta #1 en: Septiembre 23, 2011, 12:14:08 pm »
a ver. Prueba asi...!

Código: [Seleccionar]

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

Miguel Núñez.

javierjava

  • Kilobyte
  • **
  • Mensajes: 69
  • Reputación: +6/-0
    • Ver Perfil
Re:Back Up en mysql
« Respuesta #2 en: Septiembre 23, 2011, 02:06:48 pm »
Gracias por responder prove el codigo pero me dice que no reconoce el comando  :-[

E N T E R

  • Petabyte
  • ******
  • Mensajes: 1062
  • Reputación: +57/-13
  • www.enterpy.com
    • Ver Perfil
    • www.enterpy.com
Re:Back Up en mysql
« Respuesta #3 en: Septiembre 23, 2011, 03:26:06 pm »
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.


Código: [Seleccionar]
@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
CIBER GOOGLE - CONCEPCIÓN PARAGUAY
www.enterpy.com
Primera regla de la programacion, para que vas a hacerlo complicado si lo puedes hacer sencillo

seba123neo

  • Terabyte
  • *****
  • Mensajes: 763
  • Reputación: +88/-5
    • Ver Perfil
Re:Back Up en mysql
« Respuesta #4 en: Septiembre 23, 2011, 09:41:58 pm »
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.

javierjava

  • Kilobyte
  • **
  • Mensajes: 69
  • Reputación: +6/-0
    • Ver Perfil
Re:Back Up en mysql
« Respuesta #5 en: Septiembre 24, 2011, 11:27:24 pm »
Gracias me funciono lo del bat gracias por la ayuda

wolf_kof

  • Visitante
Re:Back Up en mysql
« Respuesta #6 en: Octubre 19, 2011, 01:10:30 pm »

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?

raul338

  • Terabyte
  • *****
  • Mensajes: 894
  • Reputación: +62/-8
  • xD fan!!!!! xD
    • Ver Perfil
    • Raul's Weblog
Re:Back Up en mysql
« Respuesta #7 en: Octubre 19, 2011, 06:31:43 pm »
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
Código: (vb) [Seleccionar]
Call Shell("C:\windows\system32\mysqldump.exe -uroot -p" & "****" & " -h" & "localhost" & " -r " & " C:/Backup.sql " & " miBD")

:D

seba123neo

  • Terabyte
  • *****
  • Mensajes: 763
  • Reputación: +88/-5
    • Ver Perfil
Re:Back Up en mysql
« Respuesta #8 en: Octubre 20, 2011, 12:24:46 pm »

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

Código: [Seleccionar]
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


softmania

  • Bytes
  • *
  • Mensajes: 35
  • Reputación: +4/-0
    • Ver Perfil
Re:Back Up en mysql
« Respuesta #9 en: Octubre 20, 2011, 01:32:57 pm »
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.

Código: [Seleccionar]
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
Solo se que no se nada!!! ;) By Sócrates

E N T E R

  • Petabyte
  • ******
  • Mensajes: 1062
  • Reputación: +57/-13
  • www.enterpy.com
    • Ver Perfil
    • www.enterpy.com
Re:Back Up en mysql
« Respuesta #10 en: Octubre 20, 2011, 03:29:07 pm »
Interesante, vamos a probar...


Gracias por compartir...
CIBER GOOGLE - CONCEPCIÓN PARAGUAY
www.enterpy.com
Primera regla de la programacion, para que vas a hacerlo complicado si lo puedes hacer sencillo