ChrisH Posted October 18, 2005 Posted October 18, 2005 (edited) 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. '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!!!!!serverbackup.vbs Edited March 12, 2014 by ChrisH 1
ChrisH Posted October 19, 2005 Author Posted October 19, 2005 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 .
mrtechsystems Posted October 19, 2005 Posted October 19, 2005 lol sorry to say this FIND = SERVER1 REPLACE = Your Servername :-)
ChrisH Posted October 19, 2005 Author Posted October 19, 2005 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
mac_shinobi Posted October 19, 2005 Posted October 19, 2005 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.
ChrisH Posted October 19, 2005 Author Posted October 19, 2005 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
mac_shinobi Posted October 19, 2005 Posted October 19, 2005 Taking into consideration these 2 quotes : 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 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
ChrisH Posted October 19, 2005 Author Posted October 19, 2005 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.
mac_shinobi Posted October 19, 2005 Posted October 19, 2005 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"
ChrisH Posted October 20, 2005 Author Posted October 20, 2005 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.
mac_shinobi Posted October 20, 2005 Posted October 20, 2005 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now