0 Replies Latest reply on Jun 5, 2009 3:51 PM by philmodjunk

    Using System Scripts with FMS

    philmodjunk

      Title

      Using System Scripts with FMS

      Your post

      I'd like to use this thread as a "clearing house" where forum participants can post examples of their system scripts. I'm posting a VB Script here for use on a windows machine. Feel free to post any script example in any language for any platform.

       

      The following script enables me to move backed up files to a different computer across the network. The destination folder happens to be the folder of another machine with FMS installed and copies the files into the other server's "Alternate database location folder". This machine serves as an emergency back up for the main server. Should the main server suffer a catastrophic failure, I will be able to bring the system back up very quickly, simply by opening the server console on the back up server and opening the files. (The files on the backup server will always be kept closed unless such an emergency occurs.)

       

      This script is NOT run as an FMS schedule. Instead, it is triggered from the Windows Task Scheduler a safe time interval after the scheduled back up that generates and verifies the files.

       

      Note: The destination folder has been made accessible in a very simplistic manner. This IS a security risk. I've judged it manageable in this case because it's a small business with a very small number of users and the files in question represent copies of back up files and can thus be easily replaced if something were to happen to one of the files. I plan to tighten this up once I learn a bit more about scripting, the Windows OS and possibly how to create/modify domains.

       

      To use all or part of this script, copy from the text below the line of asterisks, paste it into notepad and save it with a .vbs suffix.

       

      ***********************************************

      'Send Backups to Z: drive
      'Created By Phil Caulkins
      '06/04/2009

       

      'This script copies all backed up filemaker files from today's backup folder to networked folder mapped as drive 'z:'
      'File operations are logged to a text file that will be found in the same folder as this file
      'This log file is overwritten each time the script runs

       

      On Error Resume Next

       

      'Put the name of your back up schedule here:
      ScheduleName = "Daily"

       

      'Put the back up schedule's scheduled time here in 24hr format: (10:30 PM = 2230)
      BTime = "2230"

       

      'To copy from yesterday's backup folder instead of today's, change day(date) to day(date) - 1 in the following expression
      Bfolder = ScheduleName & "_" & Year(date) & "-" & right("0" & month(date),2) & "-" & right("0" & day(date),2) & "_" & BTime

       

      'Put the filepath (without drive letter) to the folder that contains your backed up files here
      'with double backslashes between folder names
      FolderPath = "\\BackUps\\" & Bfolder & "\\FM Server Files\\"

       

      strComputer = "."

       

      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objtxtfile = objFSO.CreateTextFile("SendToZLog.txt")

       

      objtxtFile.Writeline (Bfolder)

       

      'Delete current copy of file

       

      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

       

      If Err then
         LogErrorInfo
      Else
        objtxtFile.Writeline ("No Error: Connect to root")
      End If

       

      'z: is a mapped to the network folder where these files will be copied.
      'Permissions on this drive have to be set to allow creation and deletion of files from the server user account


      Set colFiles = _
          objWMIService.ExecQuery("Select * From CIM_DataFile Where drive = 'z:' and Extension = 'FP7'")

       

      If Err then
        logErrorInfo
      Else
        objtxtFile.Writeline ("No Error: Query Shared Folder")
      End If

       

      For Each objFile in colFiles

          objtxtFile.Writeline (objFile.filename & " Deleted")

          objFile.Delete
         
          If Err then
             LogErrorInfo
          End If

      Next

       

      'copy most recent back up files

       

      Set colFiles = _
          objWMIService.ExecQuery("Select * From CIM_DataFile Where Path = '" & FolderPath & "' and Extension = 'FP7'")

      If Err Then
        LogErrorInfo
      Else
        objtxtFile.Writeline ("No Error: Query Back Up Folder")
      End If

       

      For Each objFile in colFiles
          strNewFile = "Z:" & objFile.FileName & ".FP7"
          objFile.Copy strNewFile
          If Err THen
             LogErrorInfo
          Else
             objtxtFile.Writeline ("Copied " & objfile.filename)
          End If
      Next

       

      objtxtfile.close

       

      Sub LogErrorInfo

       

         objtxtFile.Writeline (Err & "  " & Err.source & ", " & Err.Description)
         err.Clear

       

      End Sub