+ Post New Thread
Results 1 to 13 of 13
Scripts Thread, Backup Script for NT backup and Robocopy in Coding and Web Development; Heres my script for mark. I have left it pretty much as is and just changed the server names to ...
  1. #1
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Backup Script for NT backup and Robocopy

    Heres my script for mark. I have left it pretty much as is and just changed the server names to something easier to read.
    I havent done the error checking for the folders so you must make sure that the folders are in place first eg:
    server1_
    week1 week2 week3

    just pick out the bits you need this script is backign up three server system partitions and syncing various other data.


    Code:
    'Backup script to handle all Server BackUps
    'V 0.1 
    
    'Use at your own risk!!!
    
    
    'Begin Constant Declaration
    Const Sync_Only = 0
    Const BackUp_Path = "\\backupserver\d$"
    Const Ext_Drive = "\\backupserver\h$"
    Const BackUp_Options = "/v:yes /l:f /snap:on"
    Const Path1= "\\server1\c$"
    Const Path2= "\\server2\c$"
    Const Path3= "\\mailserver\c$"
    Const Robo_Options = "/e /zb /copyall /r:3 /w:15 /purge /xf *.tmp /log+:\\server1\c$\RoboCopyLogs\"
    Const Log1 = "userlog-"
    Const Log2 = "appslog-"
    Const Log3 = "scriptslog-"
    Const Log4 = "websitelog-"
    Const Log5 = "worklog-"
    Const Log6 = "transferlog-"
    
    'Robocopy soucepaths
    Const RPath1 ="\\server1\home$\"
    Const RPath2 ="\\server1\app$"
    Const RPath3 ="\\server1\adm$\scripts"
    Const RPath4 ="\\server1\fmwebsite$"
    Const RPath5 ="\\server1\work$"
    
    'Robocopy Destination Paths
    Const RDPath = "\\backupserver\d$"
    Const RDPath1 ="home"
    Const RDPath2 ="apps"
    Const RDPath3 ="scripts"
    Const RDPath4 ="fmwebsite"
    Const RDPath5 ="work"
    
    
    'Begin Variable Declaration
    Dim StrBuType : StrBuType = ""
    Dim StrDayOftheWeek : StrDayOfTheWeek = ""
    Dim StrCmdLine : StrCmdLine = ""
    Dim StrTheDate : StrTheDate = Date
    
    'Begin Object Declaration
    Set ObjFSO = CreateObject("Scripting.FileSystemObject")
    Set ObjShell = CreateObject("WScript.Shell")
    
    'Begin Main code
     On error resume next ' Prevent errors when week folders are empty
     'Get Day of the Week
     StrDayOfTheWeek = WeekDayName(Weekday(Now))
     
     'Get the date and convert "/" to "-"
    StrTheDate = Replace(StrTheDate,"/","-")
    'Wscript.Echo StrtheDate
     
     'Set BackUp type according to the day of the week
     '
     IF StrDayOfTheWeek = "Friday" Then
     StrBuType = "NORMAL"
     Else
     StrBuType = "INCREMENTAL"
     End IF 'IF StrDayOfTheWeek = "FriDay" Then
     
     If Sync_Only = 0 Then
    
      IF StrDayOfTheWeek = "Friday" Then
      'Delete the oldest backup in week 3
      
      ObjFSO.DeleteFile(BackUp_Path & "\" & "server1\Week3\*.*")
      ObjFSO.DeleteFile(BackUp_Path & "\" & "server2\Week3\*.*")
      ObjFSO.DeleteFile(BackUp_Path & "\" & "mailserver\Week3\*.*")
      
      'and Move week 2 to 3
      
      ObjFSO.MoveFile BackUp_Path & "\" & "server1\Week2\*.*",BackUp_Path & "\" & "server1\Week3\"
      ObjFSO.MoveFile BackUp_Path & "\" & "server2\Week2\*.*",BackUp_Path & "\" & "server2\Week3\"
      ObjFSO.MoveFile BackUp_Path & "\" & "mailserver\Week2\*.*",BackUp_Path & "\" & "mailserver\Week3\"
      '
      'Move Week 1 to 2
      ObjFSO.MoveFile BackUp_Path & "\" & "server1\Week1\*.*",BackUp_Path & "\" & "server1\Week2\"
      ObjFSO.MoveFile BackUp_Path & "\" & "server2\Week1\*.*",BackUp_Path & "\" & "server2\Week2\"
      ObjFSO.MoveFile BackUp_Path & "\" & "mailserver\Week1\*.*",BackUp_Path & "\" & "mailserver\Week2\"
      End IF
    
     
     
     
     
     'Backup server1
     'S:\>ntbackup backup \\server1\c$ /m normal /j "Fmdc1 C Drive BackUp" /f "\\it-cph\
    'backup$\server1\Week 1\FMDC1-18-08-2005.bkf" /v:yes /l:f /snap:on
     
     'BackUp server1
     StrCmdLine = "ntbackup backup " &  Path1 & " " & "/m " & StrBuType & _
     " " & "/j " & Path1 & " " & "/f " & BackUp_Path & "\server1\week1\" & _
     "FMDC1-" & StrTheDate & ".bkf " & BackUp_Options
     
     ObjShell.Run StrCmdLine,1,True
     
     'BackUp server2
     StrCmdLine = "ntbackup backup " &  Path2 & " " & "/m " & StrBuType & _
      " " & "/j " & Path2 & " " & "/f " & BackUp_Path & "\server2\week1\" & _
     "FMDC2-" & StrTheDate & ".bkf " & BackUp_Options
      
    ObjShell.Run StrCmdLine,1,True
     
     'Backup PostOffice
    StrCmdLine = "ntbackup backup " &  Path3 & " " & "/m " & StrBuType & _
      " " & "/j " & Path3 & " " & "/f " & BackUp_Path & "\mailserver\week1\" & _
     "mailserver-" & StrTheDate & ".bkf " & BackUp_Options
      
      ObjShell.Run StrCmdLine,1,True
      
      End If 'If Sync_Only = 0 Then
     
     'Sync Apps and User Areas with Robocopy
     'robocopy \\server1\home$\fmstudent\year7  g:\year7test /s /e /zb /copyall /r:3 /w:15 /purge /xf *.tmp /log:\\it-cph\backup$
    
    'Backup Users Files
    StrCmdLine = "robocopy " & RPath1 & " " & RDPath & "\" & RDPath1 & " " & Robo_Options & Log1 & StrTheDate & ".txt"
    ObjShell.Run StrCmdLine,1,True
    
    'BackUp Apps
    StrCmdLine = "robocopy " & RPath2 & " " & RDPath & "\" & RDPath2 & " " & Robo_Options & Log2 & StrTheDate & ".txt"
    ObjShell.Run StrCmdLine,1,True
    
    'Backup Scripts
    StrCmdLine = "robocopy " & RPath3 & " " & RDPath & "\" & RDPath3 & " " & Robo_Options & Log3 & StrTheDate & ".txt"
    ObjShell.Run StrCmdLine,1,True
    
    'BackUp Website
    StrCmdLine = "robocopy " & RPath4 & " " & RDPath & "\" & RDPath4 & " " & Robo_Options & Log4 & StrTheDate & ".txt"
    ObjShell.Run StrCmdLine,1,True
    
    'Backup work folder
    StrCmdLine = "robocopy " & RPath5 & " " & RDPath & "\" & RDPath5 & " " & Robo_Options & Log5 & StrTheDate & ".txt"
    ObjShell.Run StrCmdLine,1,True 
     
    'RobocopyCopy System Backups to Removable Drive
    StrCmdLine = "robocopy " & BackUp_Path & " " & Ext_Drive & " " & Robo_Options & Log6 & StrTheDate & ".txt"
    ObjShell.Run StrCmdLine,1,True 
     
    'Parse Log files and paste all summarys into summarys-date.txt file
    'Email Summary to Admin.
    
     '******************************************************************
     'Begin Functions
    Watch out for wrapped lines!!!!!
    Attached Files Attached Files
    Last edited by ChrisH; 12th March 2014 at 08:00 PM.

  2. Thanks to ChrisH from:

    kdimakos (17th December 2008)

  3. #2
    mark's Avatar
    Join Date
    Jun 2005
    Posts
    3,966
    Thank Post
    248
    Thanked 49 Times in 45 Posts
    Blog Entries
    2
    Rep Power
    46

    Re: Backup Script for NT backup and Robocopy

    Excellent! You're a star

  4. #3
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Backup Script for NT backup and Robocopy

    hmm looks like I was in a rush as I didnt replace all the server names so there are loads in there and it doesnt make sense I will adjust .

  5. #4
    mark's Avatar
    Join Date
    Jun 2005
    Posts
    3,966
    Thank Post
    248
    Thanked 49 Times in 45 Posts
    Blog Entries
    2
    Rep Power
    46

    Re: Backup Script for NT backup and Robocopy

    Is that why I got lost working through it!!!

  6. #5
    mrtechsystems's Avatar
    Join Date
    Jun 2005
    Location
    Yorkshire
    Posts
    424
    Thank Post
    99
    Thanked 22 Times in 22 Posts
    Rep Power
    25

    Re: Backup Script for NT backup and Robocopy

    lol sorry to say this

    FIND = SERVER1
    REPLACE = Your Servername :-)

  7. #6
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Backup Script for NT backup and Robocopy

    Quote Originally Posted by mrtechsystems
    lol sorry to say this

    FIND = SERVER1
    REPLACE = Your Servername :-)
    I did do that but for some reason textpad didnt pick up the ones in the lower half of the script. I even tried oldserver-

    So shush

  8. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Backup Script for NT backup and Robocopy

    Couldnt you just use the InputBox function to prompt for each specific thing and replace each of the servernames with the variable name ie :

    '----------------

    Dim strInput As String
    Dim strPath As String

    strInput = InputBox("Please enter your server name")

    strPath = "\\" & strInput & "\c$"

    '----------------------

    The above is just an example , that way you would save time for people re entering it each time someone wants to use the script.

  9. #8
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Backup Script for NT backup and Robocopy

    All server names virtually are coded using constants. The only stuff that isnt is the extra server I added and the log names etc I added after the original one I was running.
    I didnt say the script was perfect and it needs some work to be more universal. I posted it at marks request just to give him an idea of the code used hence:

    just pick out the bits you need

  10. #9

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Backup Script for NT backup and Robocopy

    Taking into consideration these 2 quotes :

    Quote Originally Posted by ChrisH
    All server names virtually are coded using constants. The only stuff that isnt is the extra server I added and the log names etc I added after the original one I was running.
    I didnt say the script was perfect and it needs some work to be more universal. I posted it at marks request just to give him an idea of the code used hence:

    just pick out the bits you need
    AND

    Quote Originally Posted by ChrisH
    Quote Originally Posted by mrtechsystems
    lol sorry to say this

    FIND = SERVER1
    REPLACE = Your Servername :-)
    I did do that but for some reason textpad didnt pick up the ones in the lower half of the script. I even tried oldserver-

    So shush
    I already know that you said "Just pick out the bits you need" however they were trying to use replace and find and I was just giving an example on how to alter the code so that it can be a bit more dynamic for other people to use as apposed to having each person use the find and replace within notepad / wordpad or w/e they use

  11. #10
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Backup Script for NT backup and Robocopy

    Its meant to run as a scheduled task so it has to be static. Unless ofc you are talking about the script generating itself which would involve more work. I had planned to do that at a later date.

  12. #11

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Backup Script for NT backup and Robocopy

    when you get the final script done , any chance you can post back with it or email me a copy of it

    Also what do you mean by "the script generating itself"

  13. #12
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Backup Script for NT backup and Robocopy

    I mean use prompt boxes like you said and press generate and it will spit out a script file complete with all the server names in place and the x amount of different tasks you require.

  14. #13

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,807
    Thank Post
    3,320
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    Re: Backup Script for NT backup and Robocopy

    yes I did mean the script generating itself in that case because It would save different people altering the script each time they want to use it , they could just enter there specific info and away you go although I think a better approach would be to use the FSO and read the settings into the script from a text file or an ini file or something to that extent

SHARE:
+ Post New Thread

Similar Threads

  1. SIMs backup script after SQL 2005 migration failing...
    By mullet_man in forum MIS Systems
    Replies: 13
    Last Post: 23rd November 2007, 06:03 PM
  2. *nix Script needed for backup job
    By ICTNUT in forum *nix
    Replies: 2
    Last Post: 14th November 2007, 09:59 AM
  3. Backup PenDrive Script
    By SimpleSi in forum Scripts
    Replies: 9
    Last Post: 18th January 2007, 02:45 PM
  4. Replies: 9
    Last Post: 1st August 2006, 10:25 AM
  5. Backup Perl Script
    By ranj in forum Scripts
    Replies: 1
    Last Post: 30th April 2006, 08:02 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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