Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Script to copy File Share to new Server with Error Checking

Status
Not open for further replies.

Galford1

IS-IT--Management
Apr 6, 2004
10
0
0
US
Could use a little help with this one -

I have an older server with our main working share for the company that I need to transfer to the new server. The total data size is roughly around 180GB to be copied to the new server.

This script needs to be able to do the following:
copy all files and folders
error checking/verify with log file? - so if error occurs file name is logged and copy process continues.
preserve current security permissions

Anyone have some ideas on the best way to do this?
 
You could easily right something like this in VBScript. First though I would recommend looking at RoboCopy. It is quite robust and would work admirably for what you are trying to do. It comes with some of the windows distros, but I don't remember which ones right off the top of my head. I suspect you could find somewhere to download it from as well.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I also use Robocopy in combination with vbscript to accomplish this task...

here's what I do

Code:
' Basic steps…
' #0) Get source directory and destination directory
' #1) Verify Source exists
' #2) Use robocopy to move entire project over to destination
' #3) Use dfscmd to remove old link to project and to create new link
' #4) create a folder on server and create a shortcut to the new link

Set objArgs = WScript.Arguments

if objArgs.Count < 1 Then
'   for I = 0 to objArgs.Count - 1
'      WScript.Echo I 
'      WScript.Echo objArgs(I)
'   Next
   WScript.Echo "Insufficient Parameters"
   WScript.Echo "usage:"
   WScript.Echo "    ArchiveProject.vbs project_directory [/r]"
   WScript.Quit(1)
End If

Dim restoreFlag
restoreFlag = false

If objArgs.Count = 2 Then
	If objArgs(1) = "/r" Then
		restoreFlag = true
	End If
End If
	
Dim FSO   ' File System Object
Dim SrcDir
Dim DestDir
Dim WshShell
Dim CmdString
Dim DfsPath
Dim objFolder

Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

' #0) Get source directory and destination directory
SrcDir = "\\server1\projects\" & objArgs(0)
DestDir = "\\server2\Oldprojects\" & objArgs(0)
DfsPath = "\\mydomain\dfsroot\projects\" & objArgs(0)

If restoreFlag = true Then
	Dim temp
	
	' swap the source and destination directories...
	temp = SrcDir
	SrcDir = DestDir
	DestDir = temp
	
End If

	
'WScript.Echo SrcDir
'WScript.Echo DestDir
'WScript.Echo DfsPath

' #1) Verify Source exists
If FSO.FolderExists(SrcDir) Then
	WScript.Echo "Folder " & SrcDir & " located.  Using Robocopy to move it to " & DestDir & "."
	
	' #2) Use robocopy to move entire project over to Nomad5
	CmdString = "robocopy """ & SrcDir & """ """ & DestDir & """ /E /Z /SEC /ETA /MOVE"
	WScript.Echo CmdString
	ReturnVal = WshShell.Run("cmd /C " & CmdString, 1, True)

	WScript.Echo ReturnVal
	
	' #3) Use dfscmd to remove old link to project and to create new link
	CmdString = "dfscmd /unmap """ & DfsPath & """ "
	WScript.Echo CmdString
	ReturnVal = WshShell.Run("cmd /C " & CmdString, 1, True)

	CmdString = "dfscmd /map """ & DfsPath & """ """ & DestDir & """ "
	WScript.Echo CmdString
	ReturnVal = WshShell.Run("cmd /C " & CmdString, 1, True)

	' #4) create a folder on source directory and create a shortcut to the new link
	Set objFolder = FSO.CreateFolder( SrcDir)
	
	Set oShellLink = WshShell.CreateShortcut(SrcDir & "\Click to go to New Location.lnk")
	oShellLink.TargetPath = DestDir
	oShellLink.Description = "Shortcut Script to " & DestDir
	oShellLink.WorkingDirectory =DestDir
	oShellLink.Save

	WScript.Echo "Link Created"
Else
	WScript.Echo "Source Directory does not exist.  Exiting"
	WScript.Quit(1)
End If
 
Thats just what I was looking for - Thanks for the tip guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top