ArticlesArticles Most Helpful ArticlesMost Helpful Articles Language SettingsLanguage Settings LoginLogin
RSS Feeds
DrillDown Icon Table of Contents
DrillDown Icon MX
DrillDown Icon MANUALS and Other Info for SQL MANEX Client Server
DrillDown Icon Customer Relationship Management (CRM)
DrillDown Icon ManEx Minute
DrillDown Icon ManEx Component Exchange
DrillDown Icon ManEx Supplier Directory & Rankings
  Email This ArticlePrint PreviewPrint Current Article and All Sub-Articles
 
TRIGTIMER - Is there a Script that could be used to auto stop the trigtimer to help with Backup process?
To help with the backup process the below script information has been used to close the Trigtimer and restart it automatically on a daily basis.  Along with this and the attached utility "Logoutallusersloader.zip" to logout all users you should be able to write script that will help with your nightly backup routines.  .    
 
NOTE:  This article is just a guideline, not an actual complete script.   In the article we have two approaches; one to kill TrigTimer and then re-start after the backup is done and the second one is to skip the TrigRun.dbf and copy all the files without stopping TrigTimer.  
 

Using VBScripting to kill the trigger timer

The following function will kill any active trigger on the local computer

  function killTrigger
  '---------------------------------------------------------------------
    set WshShell = CreateObject("WScript.Shell")
    call wshshell.run("taskkill /f /im trigtimer.exe")
  '---------------------------------------------------------------------
  end function
 
 
This function will NOT log anyone out.  If there was someone logged in using these files the script will not be able to have complete access to the files.  This function ONLY kills the trigger timer allowing the trigrun.dbf  file to become unlocked

 to restart the trigger create a bat file scheduled in the task scheduler to start the trigger timer back up

 start c:\ManEx\trigtimer.exe

If you start the trigger timer in this manner you do not have to be logged on to the server in order for it to run.  This alleviates the security risk of always being logged on to your server in order for the trigger timer to run.

The task scheduler will ask you what credentials you want the task to run under and if you want to run if logged off.  If you enter the Administrator credentials and allow to run if logged off.  Schedule it to run at system start up every time the computer reboots it wall automatically start the trigger timer running under the Administrator's credentials.  Multiple scheduled times are used one to start at startup and one to start it at 4:00AM every day.

The following script will actually copy the dbfs files without the need to kill the trigger.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

'This script will copy the Manex database files with out the need of killing the trigger timer

'--------------------------------------------------------------------------------------------------------------------------------

Set WshShell = CreateObject("WScript.Shell")
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")

'This is the folder where you want to copy the files to

foldername = "\\server-2003\manex_server_backups\dbfs"
if FSO.folderexists(foldername) then FSO.deletefolder(foldername)
call FSO.CreateFolder(foldername)
foldername = foldername & "\"


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
 ("SELECT * FROM CIM_DataFile WHERE Path = '\\ManEx\\dbfs\\'")
For Each objFile in colFiles
  if objFile.Name = "c:\manex\dbfs\trigrun.dbf" then wscript.sleep 10 else call FSO.copyfile(objfile.name, foldername)
Next


function getDate()
'--------------------------------------------------------
  'get date and format it to yymmdd_hhHmmM
  DateTime =  now()
  YearTime = year(DateTime) - 2000
  if YearTime < 0 then YearTime = YearTime + 100
  if len(YearTime) = 1 then YearTime = "0" & YearTime
  monthTime = month(DateTime)
  if len(MonthTime) = 1 then monthTime = "0" & monthTime
  DayTime = day(DateTime)
  if len(DayTime) = 1 then DayTime = "0" & DayTime
  hourTime = hour(DateTime)
  if len(hourTime) = 1 then hourTime = "0" & hourTime
  minTime = Minute(DateTime) 
  if len(minTime) = 1 then minTime = "0" & minTime
  getDate = yearTime & monthTime & dayTime & "_" & hourTime & "h" & minTime & "m"
'--------------------------------------------------------
end Function

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 Here is another approach to create a script, which will skip trigrun.dbf in case the trigger is running but nothing else is going on.
 
Public Sub ManexBackup()
 
Dim sBackupFoldername As String
Dim sComputer As String
Dim colFiles
Dim objFile
Dim sManexPath As String
Dim WshShell
Dim FSO
Dim objWMIService
Dim WScript
sManexPath = "d:"manex"
    Set WshShell = VBA.CreateObject("WScript.Shell")
    Set FSO = CreateObject("Scripting.FileSystemObject")
    'Name of backup folder
    sBackupFoldername = "D:"Backups"Manex"
    If Not (FSO.folderexists(sBackupFoldername)) Then
        Call FSO.CreateFolder(sBackupFoldername) 

    End If
    sBackupFoldername = sBackupFoldername & """ & getDate()
    Call FSO.CreateFolder(sBackupFoldername)
    sBackupFoldername = sBackupFoldername & """
    sComputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!""" & sComputer & ""root"cimv2")
    Set colFiles = objWMIService.ExecQuery("SELECT * FROM CIM_DataFile WHERE Drive = 'D:' AND Path = '""Manex""dbfs""'")

 

    For Each objFile In colFiles
        If objFile.Name = sManexPath & ""dbfs"trigrun.dbf" Then
            Sleep 10
        Else
            Call FSO.copyfile(objFile.Name, sBackupFoldername)
        
         End If
             Next
 
End Sub
 
 
Attachments
Article ID: 2910