concept phrase in category sql

appears as: Phrases, phrase
SQL Server MVP Deep Dives

This is an excerpt from Manning's book SQL Server MVP Deep Dives.

  • Phrases placed in the thesaurus have a maximum of 512 characters.
  • Listing 5. Batch file (restoreLOG.vbs) calls the backup and cleanup scripts
    'This script does a custom log shipping job using ROBOCOPY and VBScript 'with FileSystemObject querying the specified folder for files created 'within the past 15 minutes or less and generates a TSQL RESTORE LOG 'command which is executed after the ROBOCOPY script 'Syntax: restoreLOG.vbs folder databaseName On Error Resume Next Dim sFolder, sFolderTarget, strParentFolder, strDatabaseName Dim fso, folder, files, strFileNameResults, objShell Set fso = CreateObject("Scripting.FileSystemObject") Set objFSO = CreateObject("Scripting.FileSystemObject") strParentFolder=Wscript.Arguments.Item(0) strDatabaseName=Wscript.Arguments.Item(1) sFolder = strParentFolder & strDatabaseName Set folder = fso.GetFolder(sFolder) Set files = folder.Files SET objShell = CreateObject("Wscript.Shell") For each itemFiles In files a=sFolder & "\" & itemFiles.Name 'retrieve file extension b = fso.GetExtensionName(a) 'check if the file extension is TRN If uCase(b)="TRN" Then 'check for DateCreated attribute of file and compare with current 'date/time If (DateDiff("N", itemFiles.DateCreated, Now) <=15) Then 'Create the file to contain the script If (objFSO.FileExists("E:\LogShipFolder\scripts\SQL\" & strDatabaseName & ".sql")) Then objFSO.DeleteFile ("E:\LogShipFolder\scripts\SQL\" & strDatabaseName & ".sql") End If Set objMyFile = objFSO.CreateTextFile("E:\LogShipFolder\scripts\SQL\" & strDatabaseName & ".sql", True) str1="RESTORE LOG " & strDatabaseName str2="FROM DISK='" & a & "'" str3="WITH STANDBY='E:\LogShipFolder\UNDO\UNDO_" & strDatabaseName & "_ARCHIVE.DAT'," str4="DBO_ONLY" objMyFile.WriteLine (str1) objMyFile.WriteLine (str2) objMyFile.WriteLine (str3) objMyFile.WriteLine (str4) objMyFile.Close Set objFSO = Nothing Set objMyFile = Nothing 'Run an OSQL command that uses a RESTORE LOG WITH MOVE, STANDBY objShell.Run("sqlcmd -S<STANDBYINSTANCENAME> -E -iE:\LogShipFolder\scripts\SQL\" & strDatabaseName & ".sql -oE:\LogShipFolder\scripts\SQL\" & strDatabaseName & "-results.txt") 'Call subroutine to read the results file for RESTORE errors strFileNameResults="E:\LogShipFolder\scripts\SQL\" & strDatabaseName & "-results.txt" Call CheckforErrors(strFileNameResults, strParentFolder, strDatabaseName) End If End If Next objFile.Close SET objFile = NOTHING SET fso = NOTHING SET folder = NOTHING SET files = NOTHING SET objShell = NOTHING SET objFSO = NOTHING SET objMyFile = NOTHING 'SUBROUTINE - used to read the results of the SQLCMD query to check for 'errors Sub CheckforErrors(fileNameResults,parentFolder,databaseName) strFileNameResults=fileNameResults strParentFolder=parentFolder strDatabaseName=databaseName Const ForReading = 1 SET objShell = CreateObject("Wscript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFileNameResults, ForReading) strContents = objFile.ReadAll 'The value=0 means that it cannot find the phrase RESTORE LOG successfully 'processed and thus means an error If Instr(strContents,"RESTORE LOG successfully processed")=0 then objShell.Run(strParentFolder & "scripts\sendEmailSMTP.vbs " & strDatabaseName & " RESTORE ") End If objFile.Close Set objFSO=NOTHING Set objFile=NOTHING Set objShell=NOTHING End Sub