Server Management - Systems Insight Manager
1752592 Members
3119 Online
108788 Solutions
New Discussion

Re: Backing up SQl express DB that is installed with HP SIM Server 6.3

 
Jamie Curran
Advisor

Backing up SQl express DB that is installed with HP SIM Server 6.3

Just wondering what  utilities or Scripts are used to backup the MS SQL 2008 Express DB??  Looking for what others are using???

1 REPLY 1
shocko
Honored Contributor

Re: Backing up SQl express DB that is installed with HP SIM Server 6.3

I run a very simple backup schedule against my CMS as I only need to be able to roll back to a specific day. I run this script:

 

Const SQL_SERVER= "."


Dim sTSQL,sDB,sBackupDir,sBackupName,sBackupDesc

'Don't bother with checking arguments, just assume they are passed

sDB = WScript.Arguments.Item(0)
sBackupDir = WScript.Arguments.Item(1)
sBackupDesc = WScript.Arguments.Item(2)

'Build TSQL
sBackupName = convertDay(weekDay(Date))
sTSQL = "BACKUP DATABASE [" & sDB & "] TO  DISK = N'" & sBackupDir & sBackupName & "' WITH NOFORMAT, NOINIT,  NAME = N'" & sBackupDesc& "', SKIP, NOREWIND, NOUNLOAD,  STATS = 10" & vbnewline  & "GO"

loginfo "Started script"
logInfo "TSQL generated:" & sTSQL

Dim WshShell,ofso,ofile,sfile,oCMD,sCMD

set WshShell = CreateObject("wscript.Shell")
sfile = WshShell.ExpandEnvironmentStrings("%TMP%") & "\SQL_SCRIPT_.sql"


Set ofso = CreateObject("scripting.filesystemobject")
Set ofile = ofso.OpenTextFile(sfile,2,True)
ofile.WriteLine(sTSQL)
ofile.Close
logInfo "Generating temp .sql file"
logInfo "Generated SQL script file:" & sfile
logInfo "Executing SQL script"

sCMD = "%COMSPEC% /C SQLCMD.EXE -S " & SQL_SERVER & " -i " & Chr(34) & sfile & Chr(34)
Set oCMD = WshShell.Exec(sCMD)
While oCMD.Status = 0
 WScript.StdOut.write(".")
 WScript.Sleep(2000)
Wend
WScript.StdOut.writeline(".")

logInfo "Exit Code:" & oCMD.ExitCode
logInfo "Output Below:"
WScript.StdOut.WriteLine(String(25,"*"))
WScript.StdOut.WriteLine(oCMD.StdOut.ReadAll)
WScript.StdOut.WriteLine()
WScript.StdOut.WriteLine(oCMD.StdErr.ReadAll)
WScript.StdOut.WriteLine(String(25,"*"))

Set ofso = Nothing
Set WshShell = nothing

Function convertDay(intD)
 Select Case intD
  Case vbsunday convertDay = "Sunday"
  Case vbmonday convertDay = "Monday"
  Case vbtuesday convertDay = "Tuesday"
  Case vbwednesday convertDay = "Wednesday"
  Case vbthursday convertDay = "Thursday"
  Case vbfriday convertDay = "Friday"
  Case vbSaturday convertDay = "Saturday"
  Case Else convertDay = "Bad Argument!"
 End select
End Function

Sub logInfo(strMsg)
 WScript.StdOut.WriteLine(Time & " Info - " & strMsg)
End Sub

Sub logErr(strMsg,bQuit,bClear,bRunTime)
 WScript.StdOut.WriteLine(Time & " Error - " & strMsg)
 If bRunTime Then
  WScript.StdOut.WriteLine(vbtab & " Err    - " & Err.Number)
  WScript.StdOut.WriteLine(vbtab & " Source - " & Err.Source)
  WScript.StdOut.WriteLine(vbtab & " Desc   - " & Err.Description)
 End if
 
 If bQuit Then WScript.Quit Err.Number
 If bClear then Err.Clear
End Sub

 

 

If my post was helpful please award me Kudos! or Points :)