Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2018
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.51 KB | None | 0 0
  1. 'ValidateRestoreFolderDSS
  2. productname = Session.Property("ProductDisplay")
  3. product_version = Session.Property("ProductVersion")
  4. restore_folder = Session.Property("RESTORE_FOLDER")
  5. DSS_installFolder = Session.Property("INSTALLDIR")
  6.  
  7. 'Open global log file for append, in Unicode format
  8. Set fso = CreateObject("Scripting.FileSystemObject")
  9. Set GlobalLogFile = fso.OpenTextFile(DSS_installFolder + "ValidateBackup.log", 8, True, -1)
  10. GlobalLogFile.WriteLine(CStr(Now()) + " --- Validate installation directory starting")
  11.  
  12.  
  13.  
  14. ' Size of DSS backup folder
  15. RestoreFolderSizeMB = 0
  16. ' Free space partition of DSS
  17. GetPartitionFreeSpaceMB = 0
  18.  
  19. ' Free space of SQL database partition
  20. GetPartitionFreeSpaceDbLocationMB = 0
  21. ' Size of database (.bak file)
  22. DataBaseBackupSize = 0
  23.  
  24.  
  25. Public SQLServer
  26. Public SQLDBName
  27. Public SQLConnection
  28. Public SQLConnectionString
  29.  
  30.  
  31.  
  32. drive = Mid(restore_folder, 1, 2)
  33.  
  34.  
  35. If drive = "\\" Then
  36. description = "Restoring from a UNC path is not supported." + chr(13) + "Please copy your backup folder locally and try again."
  37. EventLoggerErrorAndMessage(description)
  38. Session.Property("VALID_RESTORE_FOLDER") = Empty
  39. End If
  40.  
  41.  
  42. strComputer = "." ' Local Computer
  43. Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  44. Set colDrives = objWMI.ExecQuery("select * from Win32_MappedLogicalDisk")
  45.  
  46. For Each objDrive In colDrives
  47. If drive = objDrive.DeviceID Then
  48. description = "Restoring from a mapped network drive is not supported." + chr(13) + "Please copy your backup folder locally and try again."
  49. EventLoggerErrorAndMessage(description)
  50. Session.Property("VALID_RESTORE_FOLDER") = Empty
  51. End If
  52. Next
  53.  
  54. If Not BackupPackageIsValid Then
  55. description = "Backup Package is not vald! Cannot proceed."
  56. EventLoggerErrorAndMessage(description)
  57. Session.Property("VALID_RESTORE_FOLDER") = Empty
  58. Else
  59. backup_id = restore_folder + "backup.txt"
  60. import_data = ""
  61. mssql_version_from_backup = ""
  62. raw_data_string = ""
  63. pattern = "mssql_version"
  64. If fso.FileExists(backup_id) Then
  65. Set backup_file = fso.OpenTextFile(backup_id, 1, False, 0)
  66. backup_version = backup_file.ReadLine
  67. backup_product = "unknown"
  68. If InStr(backup_version,"-") > 0 Then
  69. backup_product = Left(backup_version, InStr(backup_version,"-")-1)
  70. backup_version = Mid(backup_version, InStr(backup_version,"-")+1)
  71. End If
  72. If Not backup_file.AtEndOfStream Then
  73. Session.Property("RESTOREFQDN") = backup_file.ReadLine
  74. Session.Property("RESTOREIPADDRESS") = backup_file.ReadLine
  75. End If
  76. If Not backup_file.AtEndOfStream Then
  77. raw_data_string = backup_file.ReadLine
  78. separated_data_string = Split(raw_data_string, "=")
  79. If Trim(separated_data_string(0)) = pattern Then
  80. mssql_version_from_backup = Trim(separated_data_string(1))
  81. Else
  82. import_data = raw_data_string
  83. Session.Property("IMPORT_DATA") = import_data
  84. arr = Split(import_data, ".")
  85. Session.Property("IMPORT_DATA_SHORT") = arr(0) & "." & arr(1)
  86. backup_version = product_version
  87. End If
  88. Else
  89. Session.Property("IMPORT_DATA") = Empty
  90. Session.Property("IMPORT_DATA_SHORT") = Empty
  91. End If
  92. backup_file.Close()
  93. product_build = Mid(product_version, InStrRev(product_version, ".") + 1)
  94. backup_build = Mid(backup_version, InStrRev(backup_version, ".") + 1)
  95. backup_release = Mid(backup_version, 1, InStrRev(backup_version, ".") - 1)
  96. If backup_product <> "DSS" Then
  97. description = "Cannot verify folder located at " + restore_folder + chr(13) + "Cannot proceed."
  98. EventLoggerErrorAndMessage(description)
  99. Session.Property("VALID_RESTORE_FOLDER") = Empty
  100. Elseif Not ComparePV(product_version, backup_version) = 0 Then
  101. description = "The backup located at " + restore_folder + " is from a different release (" + backup_release + ")" + chr(13) + "Cannot proceed."
  102. EventLoggerErrorAndMessage(description)
  103. Session.Property("VALID_RESTORE_FOLDER") = Empty
  104. Elseif mssql_version_from_backup <> "" And CStr(GetMSSQLVersion) <> mssql_version_from_backup Then
  105. description = "The database backup version located at " + restore_folder + " is different from the database version you are trying to restore." + "Cannot proceed."
  106. EventLoggerErrorAndMessage(description)
  107. Session.Property("VALID_RESTORE_FOLDER") = Empty
  108. Elseif product_build <> backup_build And import_data = "" Then
  109. y = MsgBox("The backup located at " + restore_folder + " is from the same release but from a different build (" + backup_build + ")" + chr(13) + "Proceed?", 256+48+4, productname)
  110. If y <> 6 Then
  111. Session.Property("VALID_RESTORE_FOLDER") = Empty
  112. End If
  113. End If
  114. Else
  115. description = "Cannot verify folder located at " + restore_folder + chr(13) + "Cannot proceed."
  116. EventLoggerErrorAndMessage(description)
  117. Session.Property("VALID_RESTORE_FOLDER") = Empty
  118. End If
  119. End If
  120.  
  121. If BackupPackageIsValid Then
  122. ' Calculate free disk space where DSS installed before restoring system backup
  123. CalculateFolderSize restore_folder
  124. CalculatePartitionFreeSpace
  125.  
  126. GlobalLogFile.WriteLine(CStr(Now()) + " --- DLP system backup folder size = " & RestoreFolderSizeMB & " MB")
  127. GlobalLogFile.WriteLine(CStr(Now()) + " --- DLP system available space = " & GetPartitionFreeSpaceMB & " MB")
  128. If RestoreFolderSizeMB > GetPartitionFreeSpaceMB Then
  129. description = "There is not enough disk space to restore the Forcepoint DLP system. You must have at least " & CInt(RestoreFolderSizeMB) & " MB free."
  130. EventLoggerErrorAndMessage(description)
  131. Session.Property("VALID_RESTORE_FOLDER") = Empty
  132. End If
  133.  
  134. ' Calculate free disk space where Database located before restoring Database backup
  135. GetDBPartitionFreeSpace
  136. GlobalLogFile.WriteLine(CStr(Now()) + " --- Forcepoint database backup size = " & CInt(RestoreFolderSizeMB) & " MB")
  137. GlobalLogFile.WriteLine(CStr(Now()) + " --- Forcepoint database partition available space = " & GetPartitionFreeSpaceDbLocationMB & " MB")
  138.  
  139. If DataBaseBackupSize > GetPartitionFreeSpaceDbLocationMB Then
  140. description = "There is not enough disk space to restore the Forcepoint database. You must have at least " & CInt(RestoreFolderSizeMB) & " MB free."
  141. EventLoggerErrorAndMessage(description)
  142. Session.Property("VALID_RESTORE_FOLDER") = Empty
  143. End If
  144. End if
  145.  
  146. Set fso = Nothing
  147. GlobalLogFile.Close
  148.  
  149. Function ComparePV(x, y)
  150. a = Split(x, ".")
  151. b = Split(y, ".")
  152. For k = 0 To UBound(a) - 1
  153. If CLng(a(k)) > CLng(b(k)) Then
  154. ComparePV = 1
  155. Exit For
  156. ElseIf CLng(a(k)) < CLng(b(k)) Then
  157. ComparePV = 2
  158. Exit For
  159. Else
  160. If k = 2 Then
  161. ComparePV = 0
  162. End If
  163. End If
  164. Next
  165. End Function
  166.  
  167. Function GetMSSQLVersion()
  168. Set shell = CreateObject("WScript.Shell")
  169. On Error Resume Next
  170. shell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Websense\Data Security\INSTALLDIR")
  171. If Err.Number = 0 Then
  172. Wow6432Node = "Wow6432Node\"
  173. Else
  174. Wow6432Node = ""
  175. End If
  176.  
  177. Set SQLConnection = CreateObject("ADODB.Connection")
  178. SQLDBName = shell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\" & Wow6432Node & "Websense\Data Security\DBNAME")
  179. SQLServer = Session.Property("WISESQLSERVERNAME")
  180. SQLConnectionString = "Provider=sqloledb;Data Source="& SQLServer & ";" &_
  181. "Initial Catalog=" & SQLDBName
  182.  
  183.  
  184. If Session.Property("WISESQLAUTH") = "NT" Then
  185. SQLConnectionString = SQLConnectionString & ";Integrated Security=SSPI"
  186. End If
  187.  
  188. SQLUser = Session.Property("WISESQLUSER")
  189. SQLPass = Session.Property("WISESQLPASS")
  190. On Error Resume Next
  191. SQLConnection.Open SQLConnectionString, SQLUser, SQLPass
  192. If Err.Number <> 0 Then
  193. WScript.Echo "Failed connecting to SQL"
  194. ' GlobalLogFile.WriteLine(CStr(Now()) + " --- Cannot Connection to SQL-Server using connection string " + SQLConnectionString + _
  195. ' ". Error: " + Err.Description )
  196. End If
  197. On Error Goto 0
  198. query = "SELECT @@MICROSOFTVERSION / POWER(2,24)"
  199. Set recordSet = SQLConnection.Execute(query)
  200. GetMSSQLVersion = recordSet(0)
  201.  
  202. End Function
  203.  
  204. Function BackupPackageIsValid()
  205. status = FALSE
  206. backup_files_list_fn = "dss_backup_files_list.txt"
  207. Set fso = CreateObject("Scripting.FileSystemObject")
  208. backup_files_list_path = restore_folder & backup_files_list_fn
  209. If fso.FileExists(backup_files_list_path) Then
  210. Set f = fso.OpenTextFile(backup_files_list_path)
  211. If BackupPackageFilesAreValid(f) Then
  212. status = TRUE
  213. End If
  214. f.Close
  215.  
  216. End If
  217. BackupPackageIsValid = status
  218. End Function
  219.  
  220. Function BackupPackageFilesAreValid(f)
  221. Set fso = CreateObject("Scripting.FileSystemObject")
  222. files_status = TRUE
  223. Do Until f.AtEndOfStream OR files_status = FALSE
  224. raw_text_arr = split(f.ReadLine, "")
  225. file_path = restore_folder & Trim(raw_text_arr(0))
  226. file_size = Trim(raw_text_arr(1))
  227. If (fso.FileExists(file_path)) Then
  228. Set file_obj = fso.GetFile(file_path)
  229. If file_obj.size <> CLng(file_size) Then
  230. files_status = FALSE
  231. End If
  232. Else
  233. files_status = FALSE
  234. End If
  235. Loop
  236. BackupPackageFilesAreValid = files_status
  237. End Function
  238.  
  239. Function CalculateFolderSize (sInstallFolder)
  240.  
  241. dataBaseFullPath = restore_folder & "MngDB\wbsn-data-security.bak"
  242.  
  243. If FSO.FolderExists(sInstallFolder ) Then
  244. Set objFolder = FSO.GetFolder(sInstallFolder)
  245. If FSO.FileExists(dataBaseFullPath) Then
  246. Set objFile = FSO.GetFile(dataBaseFullPath)
  247. DataBaseBackupSize = objFile.Size / (1024 * 1024)
  248. End If
  249. RestoreFolderSizeMB = RestoreFolderSizeMB + (objFolder.Size / (1024 * 1024)) - (objFile.Size / (1024 * 1024))
  250.  
  251. Else
  252. GlobalLogFile.WriteLine(CStr(Now()) + "--- Restore folder not found")
  253. End If
  254.  
  255.  
  256. End Function
  257.  
  258.  
  259. Function CalculatePartitionFreeSpace
  260.  
  261. ' Calculate free space on the destination backup partition
  262. Set FSO = CreateObject("Scripting.FileSystemObject")
  263. Set Partition = FSO.GetDrive(Left(DSS_installFolder,2))
  264. GetPartitionFreeSpaceMB = Partition.FreeSpace / (1024 * 1024)
  265. End Function
  266.  
  267. Function GetDBPartitionFreeSpace
  268.  
  269. ' Connection to the SQL server is already opened
  270. On Error Resume Next
  271. On Error Goto 0
  272. query = "SELECT physical_name AS current_file_location FROM sys.master_files Where name='" & SQLDBName & "'"
  273. Set recordSet = SQLConnection.Execute(query)
  274. dbLocation = recordSet(0)
  275.  
  276. Set DbPartition = FSO.GetDrive(Left(dbLocation,2))
  277. GetPartitionFreeSpaceDbLocationMB = DbPartition.FreeSpace / (1024 * 1024)
  278.  
  279. End Function
  280.  
  281. Sub EventLoggerErrorAndMessage(description)
  282. Set shell = CreateObject("WScript.Shell")
  283. cmd = "EventCreate /T ERROR /L Application /ID 264 /SO ""Forcepoint AP-DATA"" /D ""BACKUP FAILED - " & description & """"
  284. rc = shell.Run(cmd, 0, True)
  285. MsgBox description, 16, productname
  286. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement