Page 1 of 1 1
Topic Options
#190005 - 2008-10-02 10:26 PM automatipm of MySQL backup via kix
selormquarshie Offline
Getting the hang of it

Registered: 2006-12-24
Posts: 85
fellow learned folks-
is itpossible to script kix to run nighly Mysql backups on windows platform and if so, how may i do this? ur help is appreciated





Edited by NTDOC (2008-10-03 01:53 AM)
Edit Reason: Removed PHP code tags

Top
#190006 - 2008-10-02 10:57 PM Re: automatipm of MySQL backup via kix [Re: selormquarshie]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
I think you can use the MysqlDump tool but I'm not a MySQL guru. You can easily call external apps from a kix script as long as they are scriptable with com or have a command line interface.

Have a look at this link.
mysqldump — A Database Backup Program
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#190007 - 2008-10-03 01:51 AM Re: automatipm of MySQL backup via kix [Re: Mart]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
I run a script on the Main KiXtart.org website that backs up MySQL and the SystemState of the OS.

I can post those scripts if you like.

Top
#190008 - 2008-10-03 02:05 AM Re: automatipm of MySQL backup via kix [Re: NTDOC]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Okay here is a modified version of the script used on Korg for backups.

You need to modify certain names and paths to work for your environment.


If Not @LogonMode
Break On
Else
Break Off
EndIf
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption('WrapAtEOL','On')


Dim $Folder,$Cleaned,$File,$WebData,$WebBackupFolder
$WebData = 'C:\Data\MyWebsite'
$WebBackupFolder = 'C:\backups\MyWebsite\Web\'
$Folder = 'C:\backups\systemstate\'
If GetFileAttr($Folder) & 16
;Folder found do nothing
Else
MD $Folder
If @ERROR
Quit @ERROR
EndIf
EndIf
;Remove old backup copies
$Cleaned=CleanDirectory('C:\backups\MyWebsite\MySQL\','*.sql',10)
$Cleaned=CleanDirectory($Folder,'*.bkf',10)
$Cleaned=CleanDirectory($WebBackupFolder,'*.bkf',10)
;Change the 10 to the number of days you want to save the backup files
;If you only want to delete 30 days or older then change to 30
;Note though that each backup takes about 500MB of disk space for SystemState alone
;So 30 days of backups would take about 15GB of disk space storage.
BackupMySQL()
BackupSystemState($Folder)
BackupWebFiles($WebData,$WebBackupFolder)


Function BackupMySQL()
Dim $BackupName
$BackupName = Trim(Join(Split(@DATE,'/'),'-'))+'_'+Trim(Join(Split(@TIME,':'),''))+'_ubbt7.sql'
SHELL '%comspec% /c c:\mysql\bin\mysqldump.exe --add-drop-table --host=localhost --user=myusername --password=mypassword mydatabase >c:\backups\MyWebsite\MySQL\'+$BackupName
Exit @ERROR
EndFunction

Function BackupSystemState($Folder)
Dim $Job
If Not InStr(Right($Folder,1),'\') Exit 3 EndIf
$Job = Trim(Join(Split(@DATE,'/'),'-'))+'_'+Trim(Join(Split(@TIME,':'),''))+'-SystemState'
SHELL 'ntbackup backup systemstate /j '+ $Job +' /f ' + $Folder + $Job+'.bkf'

Exit @ERROR
EndFunction

Function BackupWebFiles($WebData,$WebBackupFolder)
Dim $Job
If Not InStr(Right($WebBackupFolder,1),'\') Exit 3 EndIf
$Job = Trim(Join(Split(@DATE,'/'),'-'))+'_'+Trim(Join(Split(@TIME,':'),''))+'_website'
SHELL 'ntbackup backup ' +$WebData+' /j "Website Backup " /f '+$WebBackupFolder+$Job+'.bkf'
Exit @ERROR
EndFunction

Function CleanDirectory($directories, $filter, optional $olderas, optional $countonly)
Dim $rc, $timediff, $filename, $filefilter, $tempdir
Dim $filecount, $dircount
$dircount=0
$filecount=0
$olderas=IIf(Val($olderas)>0,Val($olderas),0)
$countonly=IIf(Val($countonly),1,0)
If Not (VarType($directories) & 8192)
$directories=Split($directories,'')
EndIf
If Not (VarType($filter) & 8192)
$filter=IIf(Trim($filter),$filter,'*.*')
$filter=Split($filter,'')
EndIf
For Each $tempdir In $directories
If $tempdir<>'' And Exist($tempdir)
For Each $filefilter In $filter
If $filefilter<>''
$filefilter=fullfile($tempdir,$filefilter)
$filename=Dir($filefilter,1)
While $filename<>'' And @ERROR = 0
If $filename<>'.' And $filename<>'..'
$filename=fullfile($tempdir,$filename)
If GetFileAttr($filename) & 16
$rc=cleandirectory($filename,$filter,$olderas,$countonly)
If InStr($rc,',')
$rc=Split($rc,',')
$dircount=$dircount+$rc[0]
$filecount=$filecount+$rc[1]
EndIf
$rc=SetFileAttr($filename,128)
If Not $countonly
RD $filename
If Not @ERROR
$dircount=$dircount+1
EndIf
EndIf
Else
$timediff=datemath(@DATE,Left(GetFileTime($filename),10))
If $timediff>=$olderas
If $countonly
$filecount=$filecount+1
Else
$rc=SetFileAttr($filename,128)
Del $filename /c /f /h
If Not @ERROR
$filecount=$filecount+1
EndIf
EndIf
EndIf
EndIf
EndIf
$filename=Dir('',1)
Loop
EndIf
Next
EndIf
Next
$cleandirectory=''+$dircount+','+$filecount
EndFunction

Function FullFile($path1, optional $path2)
Dim $a, $path3
$a=UBound($path1)
if $a>0
$path3=$path1[$a]
ReDim Preserve $path1[$a-1]
$path1=fullfile($path1,$path3)
EndIf
If UBound($path1)=0
$path1=$path1[0]
EndIf
If Right($path1,1)='\'
$path1=Left($path1,Len($path1)-1)
EndIf
If $path2
If Left($path2,1)='\'
$path2=Right($path2,Len($path2)-1)
EndIf
$fullfile=LCase($path1+'\'+$path2)
Else
$fullfile=$path1
EndIf
EndFunction

Function DateMath($ExpD1,$ExpD2)
Select
Case InStr($ExpD1,'/') And InStr($ExpD2,'/')
; two date passed - return daysbetween integer
$DateMath=SerialDate($ExpD1)-SerialDate($ExpD2)
If $DateMath<0
$DateMath=$DateMath*-1
EndIf
Case InStr($ExpD1,'/') and 1-InStr($ExpD2,'/')
; date and a number passed - return date
$ExpD2=0+$ExpD2
$Datemath=SerialDate(SerialDate($ExpD1)+$ExpD2)
Case 1 ; incorrect parameters passed
EndSelect
EndFunction

Function SerialDate($ExpD)
Dim $z,$h,$a,$b,$c,$y,$m,$d
If InStr($ExpD,'/') ; date passed
$y=Val(SubStr($ExpD,1,4))
$m=Val(SubStr($ExpD,6,2))
$d=Val(SubStr($ExpD,9,2))
If $m<3
$m=$m+12
$y=$y-1
EndIf
; return an integer
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
Else ; integer passed
$z=0+$ExpD+306 ; cast numeric
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
If $m>12
$y=$y+1
$m=$m-12
EndIf
$m=Right('0'+$m,2)
$d=Right('0'+$d,2)
; return a string date
$SerialDate=''+$y+'/'+$m+'/'+$d
EndIf
EndFunction


Top
#190011 - 2008-10-03 01:01 PM Re: automatipm of MySQL backup via kix [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Keep in mind this will not work on W2K8 systems, as NTBackup is no longer available. In fact, file backups are no longer possible with standard tools, only full disk images. \:\(

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#190014 - 2008-10-03 08:05 PM Re: automatipm of MySQL backup via kix [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Yeah I tried Server 2008 for a couple of days and it had too many new issues that I just didn't want to take the time to work out so I put the system back on Server 2003.

I suppose some day I'll have to bite the bullet and go with it or 7 or what ever but dang, they fix one thing and screw the pooch on other things.

Another requirement for this script to work correctly is the Volume Shadow Copy Service so if you're running or wanting to run this on some Windows OS that does not have it then it won't work well.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 320 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.056 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org