Hi all,

I'd like to run the following partial code by you to verify if the coding is correct. To give you some background information: this code should backup 4 files; connect to a cash register to copy the backup file to, if the first cash register (rg001) is not available then it should try to connect to the second cash register (rg002) and if that cash register is also not available then it should connect to cash register 3 (rg003). If none of the cash registers are available it should connect to a network drive and copy the backup file to the specified location on the network drive. I have created the following partial code to achieve this goal:

VB Code:
  1. 'zip the following files: database backup, PLUFILE and PRICENST
  2. LogMessage "TRACE", "Starting zip of backup"
  3. Zipfiles "d:\mssql\backup\GTINRecovery.zip", sBackupfile & _
  4.          " c:\nsb\test\dbase\PLUFILE.idx" & _
  5.          " c:\nsb\test\dbase\PLUFILE.dat" & _
  6.          " c:\nsb\test\dbase\PRICEHST.idx" & _
  7.          " c:\nsb\test\dbase\PRICEHST.dat", 30, "", False, "d:\temp"
  8. LogMessage "TRACE", "copying zip to register"
  9.  
  10. 'get credentials to access rg001
  11. GetCredentialsFromXML "SDwjke&**jkFhjdhfg2g", "sHJHcvbb388h^2##@!@",
  12. APP_INI_FILE, "ClientConfig", _
  13.       "User", "Pwd", gsUser, gsPwd
  14. Dim bMapWorked As Boolean
  15. Dim sRegister As String
  16.  
  17. sRegister = Left(sServer, 5) & "rg001"
  18. bMapWorked = modUtility.MapDrive("\\" & sRegister & "\c$", "", sRegister &
  19. "\" & gsUser, gsPwd, False)
  20. If not bMapWorked Then
  21.  
  22. 'get credentials to access rg002
  23. GetCredentialsFromXML "SDwjke&**jkFhjdhfg2g", "sHJHcvbb388h^2##@!@",
  24. APP_INI_FILE, "ClientConfig", _
  25.       "User", "Pwd", gsUser, gsPwd
  26. Dim bMapWorked As Boolean
  27. Dim sRegister As String
  28.  
  29. sRegister = Left(sServer, 5) & "rg002"
  30. bMapWorked = modUtility.MapDrive("\\" & sRegister & "\c$", "", sRegister &
  31. "\" & gsUser, gsPwd, False)  
  32. ElseIf not bMapWorked Then
  33.  
  34. 'get credentials to access rg003
  35. GetCredentialsFromXML "SDwjke&**jkFhjdhfg2g", "sHJHcvbb388h^2##@!@",
  36. APP_INI_FILE, "ClientConfig", _
  37.       "User", "Pwd", gsUser, gsPwd
  38. Dim bMapWorked As Boolean
  39. Dim sRegister As String
  40.  
  41. sRegister = Left(sServer, 5) & "rg003"
  42. bMapWorked = modUtility.MapDrive("\\" & sRegister & "\c$", "", sRegister &
  43. "\" & gsUser, gsPwd, False)
  44. ElseIf not bMapWorked Then
  45.       Err.Raise 1, , "Cannot map drive to register for copy of DB backup"
  46. End If
  47.  
  48. 'copy the zip file to register 1
  49.       objFSO.CopyFile "d:\mssql\backup\GTINRecovery.zip", "\\" & Left(sServer, 5) &
  50. "rg001" & "\c$\recovery\GTINRecovery.zip", True
  51. If not objFSO.CopyFile Then
  52. 'copy the zip file to register 2
  53.       objFSO.CopyFile "d:\mssql\backup\GTINRecovery.zip", "\\" & Left(sServer, 5) &
  54. "rg002" & "\c$\recovery\GTINRecovery.zip", True
  55. ElseIf not objFSO.CopyFile Then  
  56. 'copy the zip file to register 3
  57.       objFSO.CopyFile "d:\mssql\backup\GTINRecovery.zip", "\\" & Left(sServer, 5) &
  58. "rg003" & "\c$\recovery\GTINRecovery.zip", True
  59. ElseIf not objFSO.CopyFile Then
  60. 'copy the zip file to a mapped network drive
  61.       objFSO.CopyFile "d:\mssql\backup\GTINRecovery.zip", "\\test-server-01\Recovery"
  62. ElseIf not objFSO.CopyFile Then
  63.       Err.Raise 1, , "Unable to copy db backup to register or network drive"
  64. End If

If you have any ideas on whether this will work or whether this code can be improved please let me know.

Thanks very much in advance,

Richard