Solved

Robocopying data from one server to three new ones

Posted on 2016-09-15
6
22 Views
Last Modified: 2016-10-05
We've got some Citrix home directories on one server, call it "citrixhome", that are mapped to authenticated users' U:. The new server, "newhome", will now house their home directories and be mapped to H:.
i.e. H: maps to \\newhome\Shares\HomeDirs\username

We wish to move over all of the data in their Citrix home directories (U:) to (H:).
H: already houses containers with identical usernames, but there are some with out Citrix data.
Ideally we could run this command to not move but copy the data to seed it on \\newhome, and then run the copy one last time to synch it before telling Citrix to use those drives instead of on \\citrixhome.
Note: This is one of three new servers for home drives, so really there would be three destinations for the data depending on job role.  This I was thinking robocopy may need a test file to parse of the users and where to send the data.
i.e. \\newhome1\Shares\HomeDirs\username is for one dept
\\newhome2\Shares\HomeDirs\username is for another dept
\\newhome3\Shares\HomeDirs\username is for a third dept

I'm relatively new to using robocopy and I'd figured someone on here would have a quick and simple response.  Thanks very much for any input or direction you can provide.
0
Comment
Question by:machine74
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:NVIT
ID: 41800146
If the folder structure is the same, just use like..

Robocopy /e /dcopy:t /mir /r:3 /w:1 /log:c:\results.txt \\oldhome1\Shares\HomeDirs \\newhome1\Shares\HomeDirs

When you run it a second time, it will just copy what's needed and skip all else
0
 

Author Comment

by:machine74
ID: 41800166
So that will mirror whatever is in the Citrix directories onto the new servers. Cool--but unfortunately the list of people getting data out of their Citrix folders will have to be separated to go to the correct server.  Can you pass robocopy a text file with those parameters?
0
 
LVL 23

Assisted Solution

by:NVIT
NVIT earned 250 total points (awarded by participants)
ID: 41800499
Here's a CopyUserDirs.bat that works.
- Change folder names of the source and target folders set SrcDir and set TgtDir to your needs. Maybe like:

set SrcDir=\\oldhome1\Shares
set TgtDir=\\newhome1\Shares

Open in new window


- It is in test mode, which just echos the commands, for verification reasons. When you are satisfied it should work, remove the ECHO word on line 10
@echo off
setlocal enabledelayedexpansion

set SrcDir=C:\local\test\FROM
set TgtDir=C:\local\test\TO
set FNCopyDirs=c:\local\test\UserDirs.txt

FOR /f "tokens=*" %%A in ('type "%FNCopyDirs%"') DO (
  set Dir=%%A
  ECHO robocopy /mir /copy:datsou /np /ndl /nfl /r:0 /w:0 /dcopy:t "%SrcDir%\!Dir!" "%TgtDir%\!Dir!"
)

Open in new window

- Make a UserDirs.txt file of user folder names.
- As a test, just do 1 or 2 user folders. When satisfied, you can add the rest on another run.
- Mine looks like:
userHasFull
userHasRead

Open in new window


My source folder has 3 folders: userNoCopy, userHasFull, and userHasRead
When I ran it, it just copied folders: userHasFull, and userHasRead. Also, the correct Security permissions are applied to the files and folders.

Open a CMD window.
Type: CopyUserDirs.bat to run it.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:machine74
ID: 41800516
Hmph, interesting. I'm going to give this a go, thanks very much!
0
 
LVL 83

Accepted Solution

by:
oBdA earned 250 total points (awarded by participants)
ID: 41801102
So you want to distribute the home folders from one old server to three new ones? This will do it all in one go.
It needs a "user to server" mapping file build like "<UserName><Blank><NewHomeServer>":
User1	NewHome1
User2	NewHome2
User3	NewHome3
User4	NewHome1

Open in new window

It will create one robocopy log file per user in a log folder, and a summary log file in csv format.
It's in test mode and will only echo the robocopy commands it would normally run; remove the uppercase ECHO in line 17 to run it for real.
@echo off
setlocal enabledelayedexpansion
set Source=\\OldServer\Shares\HomeDirs
set NewShare=Shares\HomeDirs
set MapFile=C:\Temp\Map.txt
set LogFolder=C:\Temp\Logs
set LogFile=%LogFolder%\summary.log
set RobocopyOptions=/mir /copyall /dcopy:t /ndl /nfl /r:0 /w:0

for /f "tokens=1,2" %%a in ('type "%MapFile%"') do set NewServer[%%~a]=%%~b
if not exist "%LogFolder%" md "%LogFolder%"
set /a ErrorCount=0
for /d %%a in ("%Source%\*.*") do (
	set User=%%~nxa
	if defined NewServer[!User!] (
		echo [!Date!][!Time: =0!] Processing '!User!' --^> '!NewServer[%%~nxa]!' ...
		ECHO robocopy.exe "%%~a" "\\!NewServer[%%~nxa]!\%NewShare%\!User!" %RobocopyOptions% /np /log+:"%LogFolder%\!User!.log"
		set EL=!ErrorLevel!
		if !EL! LSS 4 (
			echo [!Date!][!Time: =0!] ... OK.
			set Result=OK
		) else (
			echo [!Date!][!Time: =0!] ... ERROR: !EL!
			set Result=ERROR !EL!
			set /a ErrorCount += 1
		)
	) else (
		echo [!Date!][!Time: =0!] ERROR: '!User!' has no server mapping.
		set Result=NO SERVER MAPPING
		set /a ErrorCount += 1
	)
	>>"%LogFile%" echo "!Date!","!Time: =0!","!User!","!Result!"
)
echo.
echo [!Date!][!Time: =0!] Done; there were %ErrorCount% error^(s^)
echo See the summary log file '%LogFile%'

Open in new window

0
 
LVL 23

Expert Comment

by:NVIT
ID: 41829533
Question is answered.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now