Results 1 to 4 of 4

Thread: How to backup files using VB6 code

  1. #1

    Thread Starter
    New Member Rich69's Avatar
    Join Date
    May 2005
    Posts
    7

    How to backup files using VB6 code

    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

  2. #2
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Re: How to backup files using VB6 code

    Hello Rich69,
    why cant you use simple code to copy files?

    VB Code:
    1. Dim SourceFile, DestinationFile
    2.  
    3. On Error GoTo FileCopyFailed
    4.    
    5.     SourceFile = "c:\MyTestFile.txt"   ' Define source file name.
    6.     DestinationFile = "c:\MyNewTestFile.txt"   ' Define target file name.
    7.     FileCopy SourceFile, DestinationFile   ' Copy source to target.
    8.     Exit Sub
    9.  
    10. FileCopyFailed:
    11.     MsgBox Err.Number & " " & Err.Description & " " & Err.Source
    12.     Err.Clear
    13.     Resume Next

    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  3. #3

    Thread Starter
    New Member Rich69's Avatar
    Join Date
    May 2005
    Posts
    7

    Re: How to backup files using VB6 code

    Hi Eran,

    Most of the code is part of a conversion script, so that's why I left most of it intact and added some ElseIf statements to ensure the copy process of the backups succeed if one of the registers is offline to either the next register or a network drive..

    The rest of the conversion script stops all running jobs on a SQL server before making a backup copy of various databases. Once that is done; it will run SQL-scripts to convert various fields on various tables from 12-digits to 14 digits and once all that's complete re-enable jobs again...that's what it comes down to in a nutshell

  4. #4
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: How to backup files using VB6 code

    You're backing up SQL Data files? You may want to research a backup option with SQL Server itself.

    This may be beyond the scope of what you're looking for. But I'll say it anyway

    Convert the program from using local SQL Servers, to a centralized server. Add a field to indicate which register is responsible for the record. Then utilize SQL Server's backup features.

    This will probably seem like a big task. But should yeild you much stronger results for backing up the data. SQL Server has some pretty nifty features regarding data backup. You can automatically backup on whatever time scale you want, and restore data to a specific minute of the database's time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width