so leute
nach langer zeit, hab ich da wieder was zum präsentieren..
würde mich freuen wenn es jemand bei sich testen könnte und würde mich auf feedbacks freuen.
[autoit]
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=icon\database.ico
#AutoIt3Wrapper_Res_Fileversion=1.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <_sql.au3>
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.0.0
Author: Gianni
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
;
_SQL_RegisterErrorHandler()
;
;************************ GUI ************************************
#Region ### START Koda GUI section ### Form=c:\backupsql\form1.kxf
$Form1 = GUICreate("SQL-Database Backup", 276, 274, 202, 113)
$inputServer = GUICtrlCreateInput("", 136, 24, 121, 21)
$inputDatabase = GUICtrlCreateInput("", 136, 56, 121, 21)
$inputUsername = GUICtrlCreateInput("", 136, 88, 121, 21)
$inputPassword = GUICtrlCreateInput("", 136, 120, 121, 21)
$inputFile = GUICtrlCreateInput("", 136, 152, 121, 21)
$labelServer = GUICtrlCreateLabel("SQL-Server:", 16, 24, 93, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Arial")
$labbelDatabase = GUICtrlCreateLabel("Database:", 16, 56, 74, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Arial")
$labelUsername = GUICtrlCreateLabel("Username:", 16, 88, 80, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Arial")
$labelPass = GUICtrlCreateLabel("Password:", 16, 120, 77, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Arial")
$labelFile = GUICtrlCreateLabel("File:", 16, 152, 34, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Arial")
$btnBrowse = GUICtrlCreateButton("Browse..", 184, 176, 75, 17)
$btnBackup = GUICtrlCreateButton("Backup", 16, 216, 75, 25)
$Checkbox1 = GUICtrlCreateCheckbox("Create SQL-File", 16, 192, 97, 17)
$btnAbort = GUICtrlCreateButton("Abort", 184, 216, 75, 25)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
_GUICtrlStatusBar_SetText ($StatusBar1, "Ready")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;************************ GUI ************************************
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $btnAbort
Exit
Case $btnBrowse
$fileName = FileSaveDialog("Save as..", @ScriptDir, "Bak (*.bak)", 2 + 16)
If Not @error Then GUICtrlSetData($inputFile, $fileName)
Case $btnBackup
Select
Case GuiCtrlRead($inputServer) = ""
MsgBox(48, "Failure", "Please insert a server")
Case GuiCtrlRead($inputDatabase) = ""
MsgBox(48, "Failure", "Please insert a database")
Case GuiCtrlRead($inputFile) = ""
MsgBox(48, "Failure", "Please insert the filename")
Case Else
$server = GUICtrlRead($inputServer)
$db = GUICtrlRead($inputDatabase)
$username = GUICtrlRead($inputUsername)
$password = GUICtrlRead($inputPassword)
$fileName = GUICtrlRead($inputFile)
_controlExt()
_backupSQL()
ContinueLoop
EndSelect
EndSwitch
WEnd
Func _controlExt() ; funktion - dateiendung wird konntrolliert (falls nicht vorhanden, dann eingefügt (*.bak))
Dim $szDrive, $szDir, $szFName, $szExt
_PathSplit($fileName, $szDrive, $szDir, $szFName, $szExt)
If $szExt = "" Then $fileName = $szDrive & $szDir & $szFName & ".bak"
EndFunc
Func _backupSQL()
_GUICtrlStatusBar_SetText ($StatusBar1, "Backup...")
$sStart = _SQL_Startup() ; starte sql verbindung
$sConn = _SQL_Connect($sStart, $server, $db, $username, $password) ; anmeldung zum server mit der sql verbindung
If $sConn = $SQL_ERROR then
Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) ; bei einem fehler mit dem verbindung, gib die fehlermeldung zurück
_SQL_Close() ; schliesse die sql verbindung
Else
If _SQL_Execute($sStart,"BACKUP DATABASE [" & $db & "] TO DISK= N'" & $fileName & "' WITH NOFORMAT, NOINIT, NAME = N'" & $db & "-FULL', SKIP, NOREWIND, NOUNLOAD, STATS = 10;") = $SQL_ERROR then
Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) ; bei einem fehler mit dem sichern der datenbank
Else
If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then _createSQLFile() ; falls sicherung erfolgreich, kontrolliere ob sql datei erstellt werden soll
MsgBox(0, "Success", "Backup successful") ;gib meldung zurück
EndIf
EndIf
_SQL_Close() ; schliesse die sql verbindung
_GUICtrlStatusBar_SetText ($StatusBar1, "Ready")
EndFunc
Func _createSQLFile()
Dim $szDrive, $szDir, $szFName, $szExt
$fileNameSplit = _PathSplit($fileName, $szDrive, $szDir, $szFName, $szExt) ; fileendung der bak datei wird ausgelesen
$fileNameSQL = $szDrive & $szDir & $szFName & ".sql" ; filendung der bak datei mit sql (*.sql) ersetzt
$fileOpenSQL = FileOpen ( $fileNameSQL, 2) ; sql datei wird erstellt
$fileWrite = FileWrite($fileOpenSQL, "BACKUP DATABASE [" & $db & "] TO DISK = N'" & $fileName & "' WITH NOFORMAT," & @CRLF _
& "NOINIT, NAME = N'" & $db & "-Fullbackup', SKIP, NOREWIND, NOUNLOAD, STATS = 10" & @CRLF _
& "GO") ; befehl wird in der sql datei geschrieben
If $fileWrite = 1 Then
MsgBox(0, "Success", "SQL-File created successful") ; erfolgreich
Else
MsgBox(0, "Error", "SQL-File not created") ; nicht erfolgreich
EndIf
FileClose($fileWrite) ; schliesse handle (sql datei)
EndFunc
grüsse
gianni