How to copy junction as-is instead of the folder it points to?

7k Views Asked by At

I copy set of folders from server 1 to server 2. Amongst files I also have junction: folder with set of config files: on server 1 this junction points to... let's say c:\Config (that contains config1.cfg, config2.cfg)

On server 2 I also have c:\Config with the same set of files, but of course they contains their own settings that I do not want to overwrite.

So what I want to do is to copy junction AS-IS. Instead, I get copies of config1.cfg and config2.cfg from server 1 :(

How to solve this problem??

p.s.1. it's long to explain, but I cannot avoid of using junctions here (it has something to do with limitation of where configuration must be placed (subfolder-'junction' points to 'outside' folder))

p.s.2. OS is Windows Server 2003

3

There are 3 best solutions below

2
On BEST ANSWER

Copying junctions don't make any sense from drive to drive - a junction points to a specific node on disk. What you really want is a Symlink, which points to a specific path in the filesystem, but unfortunately this doesn't exist on Server 2003. You're out of luck here, you'll have to just fix this up in a post-copy script.

0
On

You can recreate a list of junction points using the scripts.

https://github.com/andry81/contools/tree/HEAD/Scripts/Tools/admin/Junction

list-junction-points.bat

@echo off

for /F "usebackq eol= tokens=* delims=" %%i in (`@dir /A:L /B %* 2^>nul`) do echo.%%i
list-junction-points.bat /S c:\ > junction-points.lst

Then get junction points paths:

read-junction-points.bat

@echo off

for /F "usebackq eol= tokens=* delims=" %%i in ("%~1") do for /F "usebackq eol= tokens=4,* delims= " %%j in (`dir /A:L "%%i\.." 2^>nul ^| findstr /R /C:"\[.*\]"`) do if "%%~ni" == "%%j" ( set "J=%%k" & call echo.%%i*%%J:~1,-1%%)
read-junction-points.bat junction-points.lst > junction-paths.lst

Then recreate junction points (needs administrator privileges):

create-junction-points.bat

@echo off

for /F "usebackq eol= tokens=1,* delims=*" %%i in ("%~1") do ( echo."%%i" -^> "%%j" & mklink /j "%%i" "%%j" )
create-junction-points.bat junction-paths.lst 

Warning: The eol= actually is not empty and contains the 04 code character.

Junction point connection is required only on creation which requires administrator privileges.

1
On

FastCopy is a small program that does.