Results 1 to 4 of 4

Thread: VBS Backup Script

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    1

    VBS Backup Script

    Hi guys i was wondering if you could help

    Im looking to make a VBS backup script that would allow me to run a sheduled task and backup specific files from the C Drive to a network path. i would also like the script to check the target path and update existing backed up files if they are a week or older.

    I would like to backup the folder C:\Winner\Projects but only the .prj files that are stored in this folder to \\NetworkName\Backup

    How would i go about this as every script i look at seems to be different.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VBS Backup Script

    The VB.NET forum is not the place to ask VBScript questions. The best place for VBScript questions is the forum with VBScript in the name. I've already asked the mods to move this thread.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBS Backup Script

    Thread Moved
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: VBS Backup Script

    Is there any particular reason why you want to use VBS? I created a small program that runs as part of a scheduled task. It ZIPs up a dated sub-directory and then send it via FTP to a server at our corporate office. Either way, it should give you some ideas.

    [vbcode] Code:
    1. Imports System
    2. Imports System.IO
    3. Imports System.Web
    4. Imports System.Net
    5. Imports System.Net.WebClient
    6. Imports System.Net.Configuration
    7.  
    8. Module Module1
    9.  
    10.     Sub Main()
    11.         Dim date1 As New Date(2008, 8, 29, 19, 27, 15, 18)  '
    12.         Dim date2 As String                                 'Sets date to string
    13.         date1 = Now()                                       'Sets date1 to now()
    14.         date1 = DateAdd(DateInterval.Day, -1, date1)        'Subtracts one day
    15.         date2 = (date1.ToString("yyyyMMdd"))                'Puts date in Aloha dated sub format
    16.  
    17.         Dim StoreID As String
    18.         StoreID = My.Computer.FileSystem.ReadAllText("D:\VBS-AUTOCOPY\STOREID.INI")                 'checks storeid.ini for store id
    19.         Console.WriteLine("Store ID: " & StoreID)                                                   'writes out store id
    20.  
    21.         For Each filetdx As String In IO.Directory.GetFiles("D:\Aloha\" & date2 & "\", "*.TDX")     'deletes tdx files
    22.             IO.File.Delete(filetdx)
    23.         Next
    24.         Console.WriteLine("Deleting TDX files.")
    25.  
    26.         For Each filecdx As String In IO.Directory.GetFiles("D:\Aloha\" & date2 & "\", "*.CDX")     'deletes cdx files
    27.             IO.File.Delete(filecdx)
    28.         Next
    29.         Console.WriteLine("Deleting CDX files.")
    30.  
    31.         My.Computer.FileSystem.CreateDirectory("D:\XFER\" & date2)                                  'creates a directory for xfer
    32.         Console.WriteLine("Created dated sub-dir for transfer.")
    33.         Try
    34.             My.Computer.FileSystem.CopyFile("D:\Aloha\EDC\FIFTH THIRD PROCESSING SOLUTIONS\" & date2 & ".stl", "D:\xfer\" & date2 & "\" & date2 & ".STL") 'copies STL file to Aloha dated-sub
    35.             My.Computer.FileSystem.CopyFile("D:\Aloha\EDC\edc.ini", "D:\xfer\" & date2 & "\EDC.INI") 'copies edc.ini to dated-sub
    36.             Console.WriteLine("Copied settlement file.")
    37.             Console.WriteLine("Copied EDC.INI")
    38.         Catch ex As Exception
    39.             Console.WriteLine("Copying of settlement file/EDC.INI failed.")
    40.         End Try
    41.         My.Computer.FileSystem.CopyDirectory("D:\aloha\" & date2, "D:\xfer\" & date2) 'copies all files to xfer dir
    42.         Console.WriteLine("Copied files to transfer directory successfully.")
    43.         Try
    44.             Dim NewZip As New ICSharpCode.SharpZipLib.Zip.FastZip                       'zips up files
    45.             NewZip.CreateZip("D:\xfer\" & date2 & ".zip", "D:\xfer\" & date2, False, Nothing, Nothing)
    46.             Console.WriteLine("ZIP file created successfully.")
    47.         Catch ex As Exception
    48.             Console.WriteLine("ZIP file creation failed.")
    49.             MsgBox("ZIP File Creation Error! Call the Briad Helpdesk 602-567-5050", MsgBoxStyle.Critical)
    50.         End Try
    51.         Try
    52.             Console.WriteLine("Starting FTP transfer.")
    53.             Dim uriString As String = "ftp://10.100.1.80/" & StoreID & "/" & date2 & ".ZIP"
    54.             Dim myWebClient As New WebClient()
    55.             Dim DatedSub As String = "D:\XFER\" & date2 & ".ZIP"
    56.             Dim responseArray As Byte() = myWebClient.UploadFile(uriString, DatedSub)
    57.             Console.WriteLine("Upload completed successfully.")
    58.         Catch ex As Exception
    59.             Console.WriteLine("An error has occured while uploading the file.")
    60.             Console.WriteLine("No garbage collection has been performed.")
    61.             MsgBox("Please call the Helpdesk immediately! Upload failed.", MsgBoxStyle.Critical)
    62.         End Try
    63.         Try
    64.             Dim DirectoryToDelete2 As String
    65.             DirectoryToDelete2 = "d:\xfer\" & date2
    66.             If System.IO.Directory.Exists(DirectoryToDelete2) = True Then
    67.                 System.IO.Directory.Delete(DirectoryToDelete2, True)
    68.                 Console.WriteLine("Performing cleanup.")
    69.                 Console.WriteLine("Backup folder delted.")
    70.             Else
    71.                 If System.IO.Directory.Exists(DirectoryToDelete2) = False Then
    72.                     Console.WriteLine("Could not find backup directory in D:\XFER.")
    73.                 End If
    74.             End If
    75.             My.Computer.FileSystem.DeleteFile("d:\xfer\" & date2 & ".ZIP", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
    76.             Console.WriteLine("Deleted transferred file.")
    77.             Console.WriteLine("Backup complete.")
    78.         Catch ex As Exception
    79.             Console.WriteLine("Garbage collection failed.")
    80.             Console.WriteLine("End of program.")
    81.         End Try
    82.     End Sub
    83.  
    84. End Module

    Quote Originally Posted by pimpcat View Post
    Hi guys i was wondering if you could help

    Im looking to make a VBS backup script that would allow me to run a sheduled task and backup specific files from the C Drive to a network path. i would also like the script to check the target path and update existing backed up files if they are a week or older.

    I would like to backup the folder C:\Winner\Projects but only the .prj files that are stored in this folder to \\NetworkName\Backup

    How would i go about this as every script i look at seems to be different.
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

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