Galera,
Peguei a idéia de vcs e montem meu backup para MYSQL com HWGUI!
#Include "hwgui.ch"
STATIC Thisform
FUNCTION Backup( ... )
RETURN _Backup( HB_AParams() )
FUNCTION _Backup( )
Local oDlg, oGroup1, oGroup2, oLabel1, oLabel2, oLabel3, oButtonex1, oButtonex2, oButtonex3
Private vPasta := "", oArqRet, oFonte, vArquivoDestino := SEM(DOW(date())) + '.sql', oLabel4
PREPARE FONT oFonte NAME "Verdana" WIDTH 0 HEIGHT -13 WEIGHT 700 charset 255
INIT DIALOG oDlg TITLE "BACKUP" ;
AT 100,186 SIZE 656,330 NOEXIT CLIPPER ;
FONT HFont():Add( 'Verdana',0,-13,400,,,) ;
STYLE WS_POPUP+WS_CAPTION+WS_SIZEBOX+DS_CENTER
Thisform := oDlg
//
@ 012,012 GROUPBOX oGroup1 CAPTION " Backup base de dados - Banco MySql " SIZE 632,99 ;
FONT oFonte ;
STYLE BS_CENTER
@ 021,038 SAY oLabel1 CAPTION "Pasta Destino" SIZE 107,21 ;
FONT oFonte
@ 021,060 GET oArqRet VAR vPasta SIZE 578,24 ;
ON CHANGE {|| habilitaConfirma(vPasta,oButtonex2) }
@ 604,060 BUTTONEX oButtonex1 CAPTION "..." SIZE 29,22 ;
ON CLICK {|| ProcuraPasta( oButtonex2 ) } ;
STYLE WS_TABSTOP
//
@ 012,120 GROUPBOX oGroup2 CAPTION "" SIZE 632,99 ;
FONT oFonte ;
STYLE BS_CENTER
@ 021,140 SAY oLabel2 CAPTION "Arquivo Destino" SIZE 107,21 ;
FONT oFonte
@ 021,160 SAY oLabel3 CAPTION vArquivoDestino SIZE 220,40 ;
COLOR 16711680 ;
FONT HFont():Add( '',0,-32,700,,,)
@ 021,230 SAY oLabel4 CAPTION "" SIZE 350,30 ;
COLOR 255 ;
FONT HFont():Add( '',0,-22,700,,,)
//
@ 192,270 BUTTONEX oButtonex2 CAPTION "&Confirma" SIZE 98,32 ;
ON CLICK {|| Confirma(oButtonex2, oButtonex3, oArqRet) } ;
STYLE WS_TABSTOP + WS_DISABLED
@ 323,270 BUTTONEX oButtonex3 CAPTION "&Fecha" SIZE 98,32 ;
ON CLICK {|| EndDialog() } ;
STYLE WS_TABSTOP
aDd STATUS oStatusPrincipal TO oDlg ;
ON INIT {|this| this:SETtextPanel(1, time() ) } ;
Font HFont():Add( 'Arial',0,-13,700,,,)
SET TIMER oTimer OF oDlg VALUE 1000 ACTION {|| AtualizaClock(oStatusPrincipal) }
ACTIVATE DIALOG oDlg
RETURN oDlg:lresult
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
Function AtualizaClock(This)
This:SETtextPanel(1, time() )
Return nil
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
STATIC FUNCTION ProcuraPasta( hbBotao )
Local varbuf
Local curpath := DISKNAME()+':\'+curdir()
varbuf := SelectFolder(curpath)
If !Empty(varbuf)
oArqRet:Value := varbuf
hbBotao:Enable()
hbBotao:SetFocus()
Endif
dirchange( curpath )
RETURN Nil
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
Static Function habilitaConfirma(var, botao)
If !Empty( var )
botao:enable()
Else
botao:Disable()
Endif
botao:refresh()
Return .t.
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
Function Confirma(bot1, bot2, GetDes)
Local nHandle
Local arquivo := vPasta + If( right( AllTrim(vPasta),1 ) = "\", "", "\" ) + vArquivoDestino
Local ArqBat := "backupPDV.bat"
Local Usuario := "usuario"
Local Senha := "senha"
Local aIni := HB_ReadIni('c:\CriaSoftWare\PafCriaSoftWare.ini')
Local aSecaoIni := aIni['Config']
Local IpServidor := Upper( aSecaoIni['Servidor'] )
If IpServidor = "LOCAL"
IpServidor = "localhost"
Endif
If !File( "mysqldump.exe" )
MsgStop("ARQUIVO 'mysqldump.exe' NÃO ESTA PRESENTE")
Return .t.
Endif
If !MsgYesNo("CONFIRMA BACKUP?")
Return .t.
Endif
//
bot1:disable()
bot2:disable()
GetDes:disable()
oLabel4:caption := "Deletando backup anterior"
Delete File( arquivo )
Delete File( ArqBat )
oLabel4:caption := "Criando script de backup"
nHandle := fCreate( ArqBat , 0 )
fWrite( nHandle , 'mysqldump --host=' + IpServidor + ' -u ' + Usuario + ' -p' + Senha + ' -x -e SeuBancoDados > ' + arquivo + HB_OSNewLine() )
fClose(nHandle) // Fecha o arquivo para que ele possa ser executado mais adiante.
Millisec(500)
oLabel4:caption := "Fazendo backup. Aguarde..."
MyRun( ArqBat ) // Executo
Millisec(500)
oLabel4:caption := ""
Delete File( ArqBat )
MsgInfo("BACKUP EFETUADO COM SUCESSO!")
EndDialog()
Return .t.
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
FUNCTION Sem(n_sem)
LOCAL semana:={"Domingo","Segunda","Terca","Quarta","Quinta", "Sexta","Sabado"}
RETURN(semana[n_sem])
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------*/
function MyRun( cComando )
**************************
local oShell, RET
oShell := CreateObject( "WScript.Shell" )
RET := oShell:Run( "%comspec% /c " + cComando, 0, .T. )
oShell := NIL
return iif( RET = 0, .T., .F. )