Solved

Robocopying data from one server to three new ones

Posted on 2016-09-15
6
31 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 24

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 24

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
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 

Author Comment

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

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 24

Expert Comment

by:NVIT
ID: 41829533
Question is answered.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

687 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