Home | Firestreamer | Downloads | Support | About Us My Account | Site Map | Search | Cristalink RSS Feed  
Firestreamer-RM Getting Started Guide Firestreamer-RM Home

Sample Prolog Script

Below is a sample prolog script that performs a full backup of a database on a Microsoft SQL Server. To use the script, follow the steps below.

  1. Save the script as Prolog.wsf, for example, into C:\MyScripts.
  2. Edit the script to change the SQL server name, database name and authentication settings.
  3. On the Media Type page of the Firestreamer-RM Wrapper for a scheduled task, enter cscript.exe //B //Nologo C:\MyScripts\Prolog.wsf into the Prolog textbox.
<?xml version="1.0" encoding="utf-8" ?>
<
package>

<
job id="Prolog">

<
runtime>

<
description>
Prolog.wsf  Version: 1.0
Copyright (c) Cristalink Limited, 2006. All rights reserved.

Prolog script for a Firestreamer-RM Wrapper task.
Backs up an SQL database to a file.

Command line: cscript.exe //B //Nologo Prolog.wsf
</description>

</
runtime>

<
script language="VBScript">
   option explicit
   on error goto 0

  
dim sError
  
dim sApplicationName, sDestFile
  
dim sServer, bLoginSecure, sLogin, sPassword
  
dim sDatabase, nBackupAction, sBackupSetName

  
'
   ' Script parameters.
   '
   sApplicationName        = "Prolog Script"       ' Application name used to connect to the SQL Server.
   sServer                 = "MyPC\sqlexpress"     ' SQL Server name.
   bLoginSecure            = true                  ' Use Windows Authentication.
   sLogin                  = "username"            ' Login.
   sPassword               = "password"            ' Password.
   sDatabase               = "Commerce"            ' Database name.
   nBackupAction           = 0                     ' 0: SQLDMOBackup_Database, 1: SQLDMOBackup_Incremental.
   sDestFile               = sDatabase + ".bak"    ' Backup file name.
   sBackupSetName          = sDatabase + " Full Backup"  ' Backup set name.

   '
   ' Get the environment variables.
   '
   dim oShell, oEnvironment, sResultFile
  
set oShell = WScript.CreateObject("WScript.Shell")
  
set oEnvironment = oShell.Environment("PROCESS")
   sResultFile = oEnvironment(
"FSRMTASK_RESULT")   ' Script result file name.

   if sResultFile = "" then
      sResultFile = "Result.txt"   ' This may be handy for testing the script.
   end if

   '
   ' Create the script result file.
   '
   dim oFileSystem, oResultFile
  
set oFileSystem = WScript.CreateObject("Scripting.FileSystemObject")
  
set oResultFile = oFileSystem.CreateTextFile(sResultFile, true, true)   ' Overwrite, UNICODE.
   oResultFile.WriteLine("[Result]")

  
'
   ' Connect to the SQL Server.
   '
   dim oSrv
  
set oSrv = CreateObject("SQLDMO.SQLServer")
   oSrv.ApplicationName = sApplicationName
   oSrv.LoginSecure     = bLoginSecure
   oSrv.Login           = sLogin
   oSrv.Password        = sPassword
  
  
on error resume next
   oSrv.Connect sServer
  
if Err.Number &lt;&gt; 0 then
      sError = Hex(Err.Number) &amp; " " &amp; Err.Description &amp; " " &amp; Err.Source
      Err.Clear
     
on error goto 0
      oResultFile.WriteLine(
"message=Unable to connect to SQL Server: " &amp; sError )
      oResultFile.WriteLine(
"status=warning")
      Wscript.Quit( 0 )
  
end if
   on error goto 0

  
'
   ' Back up the database.
   '
   dim oBkp
  
set oBkp = CreateObject("SQLDMO.Backup")
   oBkp.Action          = nBackupAction
   oBkp.Database        = sDatabase
   oBkp.Files           = sDestFile
   oBkp.BackupSetName   = sBackupSetName
   oBkp.Initialize =
true     ' Overwrite old backup sets.

   on error resume next
   oBkp.SQLBackup oSrv
  
if Err.Number &lt;&gt; 0 then
      sError = Hex(Err.Number) &amp; " " &amp; Err.Description
      Err.Clear
     
on error goto 0
      oResultFile.WriteLine(
"message=Unable to back up the " &amp; sDatabase &amp; " database: " &amp; sError )
      oResultFile.WriteLine(
"status=warning")
      Wscript.Quit( 0 )
  
end if
   on error goto 0

  
'
   ' Verify the backup set.
   '
   set oBkp = CreateObject("SQLDMO.Restore")
   oBkp.Action       = 0     
' 0: SQLDMORestore_Database
   oBkp.Database     = sDatabase
   oBkp.Files        = sDestFile

  
on error resume next
   oBkp.SQLVerify oSrv
  
if Err.Number &lt;&gt; 0 then
      sError = Hex(Err.Number) &amp; " " &amp; Err.Description
      Err.Clear
     
on error goto 0
      oResultFile.WriteLine(
"message=Backup verification failed for the " &amp; sDatabase &amp; " database: " &amp; sError )
      oResultFile.WriteLine(
"status=warning")
      Wscript.Quit( 0 )
  
end if
   on error goto 0

  
'
   ' Done.
   '
   oResultFile.WriteLine("message=The " &amp; sDatabase &amp; " database is backed up")
   oResultFile.WriteLine(
"status=ok")
   WScript.quit(0)

</script>

</
job>

</
package>

 

Terms of Use | Privacy Policy This page is protected by Secure Sockets Layer (SSL) © Cristalink Pty Ltd, 2023. ABN 97615040027