FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Backup/Restore MySQL data when build BAT file
Posts: 866
Joined: Tue Oct 16, 2007 08:57 AM
Backup/Restore MySQL data when build BAT file
Posted: Sun Sep 03, 2017 02:16 AM
Hi All
I use this code below:
Code (fw): Select all Collapse
  
METHOD RunDatabaseBackup() CLASS TWinCraneErp
LOCAL fp
LOCAL chost      := GetServer()
LOCAL names      := 'utf8'
LOCAL nport      := 3306
LOCAL db         := GetLoginDataBase()
LOCAL cDriver    := CurDrive()
LOCAL cDriverDir := GetCurDir()
LOCAL cdir       := cDriverDir + "\BackUpData\"      // cDriver + ":\" + cDriverDir + "\BackUpData\"
LOCAL cfile      := 'BackupDatabase.sql'

          fp:=FCREATE("bak.bat")
      WRITE(fp,"@ECHO OFF")
          FWRITE(fp,CRLF+"mysqldump.exe --host "+AllTrim(chost)+" --default-character-set="+names+" --port="+cvaltochar(nport)+" -u root -p1234 "+AllTrim(db)+" > "+alltrim(cdir)+iif(right(alltrim(cdir),1)=="\","","\")+alltrim(cFile))
          FCLOSE(fp)
          WaitRun("call bak.bat",0)

RETURN NIL



WaitRun("call bak.bat",0) => run it not work. If I windows file work fine.
Any solution be welcome!!
Best Regards,



Richard



Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 32bit

MySQL v8.0

Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: Backup/Restore MySQL data when build BAT file
Posted: Sun Sep 03, 2017 08:54 AM

Hi Richard,

Can you try it without "call"

WaitRun("bak.bat",0)

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: Backup/Restore MySQL data when build BAT file
Posted: Sun Sep 03, 2017 09:00 AM
Richard,

I use ShellExecute.
In your case it will be someting like this :
Code (fw): Select all Collapse
ShellExecute( 0, 'OPEN', "cmd" ,"/c .\mysqldump.exe --host "+AllTrim(chost)+" --default-character-set="+names+" --port="+cvaltochar(nport)+" -u root -p1234 "+AllTrim(db)+" > "+alltrim(cdir)+iif(right(alltrim(cdir),1)=="\","","\")+alltrim(cFile), , 1 )
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 866
Joined: Tue Oct 16, 2007 08:57 AM
Re: Backup/Restore MySQL data when build BAT file
Posted: Sun Sep 03, 2017 03:22 PM
Horizon wrote:Hi Richard,

Can you try it without "call"

WaitRun("bak.bat",0)


HI Hakan,

You're right, work fine.
Thaks a lot.
Best Regards,



Richard



Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 32bit

MySQL v8.0

Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit
Posts: 866
Joined: Tue Oct 16, 2007 08:57 AM
Re: Backup/Restore MySQL data when build BAT file
Posted: Sun Sep 03, 2017 03:23 PM
Marc Vanzegbroeck wrote:Richard,

I use ShellExecute.
In your case it will be someting like this :
Code (fw): Select all Collapse
ShellExecute( 0, 'OPEN', "cmd" ,"/c .\mysqldump.exe --host "+AllTrim(chost)+" --default-character-set="+names+" --port="+cvaltochar(nport)+" -u root -p1234 "+AllTrim(db)+" > "+alltrim(cdir)+iif(right(alltrim(cdir),1)=="\","","\")+alltrim(cFile), , 1 )


Hi Marc,
you suggestion it and work fine.
Thanks a lot.
Best Regards,



Richard



Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 32bit

MySQL v8.0

Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Backup/Restore MySQL data when build BAT file
Posted: Tue Sep 05, 2017 04:56 AM

FWH oCn:BackUp() is simple to use and works fast and well.

Regards



G. N. Rao.

Hyderabad, India
Posts: 866
Joined: Tue Oct 16, 2007 08:57 AM
Re: Backup/Restore MySQL data when build BAT file
Posted: Tue Sep 05, 2017 05:29 AM
nageswaragunupudi wrote:FWH oCn:BackUp() is simple to use and works fast and well.


Mr.Rao,

Yes, I think so. But now I use TMySQL 3rd
I have a idea. I can use TMySQL and FWH MariaDb/MySql Backup and Restore Together run it?

Code (fw): Select all Collapse
//TMySQL

     oServer:= TMySQLServer():New( GetServer(), GetLoginId(), GetLoginPass() )
     IF oServer:NETERR()
         oServer:End()
         oServer:= TMySQLServer():New( GetServer(), "mysql", "" )
         IF oServer:NETERR()
            MsgStop( "MySQL伺服器未開或者伺服器有防火牆或網路不通!", "停止" )
            lOK := .F.
            RETURN lOK
         ELSE
            MsgStop( "MySQL伺服器已有啟動中,但有其它問題導致無法連上!", "停止" )
            lOK := .F.
            RETURN lOK
         ENDIF
      ENDIF
      cLoginTable := GetLoginDataBase()
      oServer:SelectDB(cLoginTable)

//FWH MariaDb/MySql Backup and Restore

   oCn := mysql_Connect( cHost, cUsr, cPsw)
   ? cResult:=oCn:Backup('prova','c:\pp\prova.sql')
   ? oCn:Restore("c:\pp\prova.sql",NIL,NIL,"prueba")
Best Regards,



Richard



Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 32bit

MySQL v8.0

Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Backup/Restore MySQL data when build BAT file
Posted: Tue Sep 05, 2017 05:55 AM
I can use TMySQL and FWH MariaDb/MySql Backup and Restore Together run it?

Yes, you can.

In fact you can use FWH mariadb functionality in addition to TMySql in your programs without any conflict with TMySql.

Your above program works.

However you can totally simplify the backup program and run it silently in the nights as a scheduled task and forget about it.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Backup/Restore MySQL data when build BAT file
Posted: Tue Sep 05, 2017 06:22 AM
You can use a simple program like this:
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oCn
   local cBackUpFolder  := "c:\pp\"  // should end with a backslash
   
   FWCONNECT oCn HOST GetServer() USER GetLoginId() PASSWORD GetLoginPass() DATABASE GetLoginDataBase()
   if oCn == nil
      FWLOG "Connect fail"
   else
      oCn:BackUp( nil, cBackUpFolder )
      oCn:Close()
      oCn   := nil
   endif
   
return nil

// functions like GetServer() etc.

Make sure that the program does not contain any screen I/O.
Now add this to the scheduled tasks on the server (with user as SYSTEM) to run every night at your convenient time.

Assuming that your database name is "prova", this program will save backups each day in a different folder with weekday's name.
On Sunday night it saves backup as "c:\pp\Sunday\prova.sql". On Monday night it saves backup as "c:\pp\Monday\prova.sql" and so on. After one week, it overwrites that weekdays backup. This way we have 7 backups at any time.
Regards



G. N. Rao.

Hyderabad, India
Posts: 866
Joined: Tue Oct 16, 2007 08:57 AM
Re: Backup/Restore MySQL data when build BAT file
Posted: Tue Sep 05, 2017 07:18 AM
nageswaragunupudi wrote:You can use a simple program like this:
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oCn
   local cBackUpFolder  := "c:\pp\"  // should end with a backslash
   
   FWCONNECT oCn HOST GetServer() USER GetLoginId() PASSWORD GetLoginPass() DATABASE GetLoginDataBase()
   if oCn == nil
      FWLOG "Connect fail"
   else
      oCn:BackUp( nil, cBackUpFolder )
      oCn:Close()
      oCn   := nil
   endif
   
return nil

// functions like GetServer() etc.

Make sure that the program does not contain any screen I/O.
Now add this to the scheduled tasks on the server (with user as SYSTEM) to run every night at your convenient time.

Assuming that your database name is "prova", this program will save backups each day in a different folder with weekday's name.
On Sunday night it saves backup as "c:\pp\Sunday\prova.sql". On Monday night it saves backup as "c:\pp\Monday\prova.sql" and so on. After one week, it overwrites that weekdays backup. This way we have 7 backups at any time.


Mr.Rao
Nice good job. Try it and add my plan code.
Best Regards,



Richard



Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 32bit

MySQL v8.0

Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit

Continue the discussion