JSI Tip 8587. How can I transfer a folder structure, shares, and permissions?


I have scripted XFR.bat to transfer a drive or folder structure, its' permissions, and shares to another computer, or to restore it to the source computer. The transfer medium can be a network share, a local folder, a CD-ROM, or even a single floppy disk.

The syntax for using XFR.bat is one of the following:

XFR C FolderPath XFRMedium

XFR R FolderPath XFRMedium

Where:

C           creates the transfer medium.

R           restores the drive or folder, its' permissions, and shares.

FolderPath  is the drive or folder to enumerate.

XFRMedium   is the path to the transfer medium.
NOTE: XFR.bat uses the SubInACL.EXE and RMTShare.EXE public domain software.

Example:

If you wanted to create the same folder structure for the D: drive on other PCs, transferring the information via a floppy disk:

To create the floppy disk:

XFR C D: A:

To create the D: drive structure on another PC:

XFR R D: A:

NOTE: No data is transferred, just the folder structure, folder permissions, shares, and share permissions. The administrative shares are NOT transferred. Before running the restore, you must create the same local accounts and groups that are permissioned on the source PC. You can use AddUsers.exe from the Windows 2000 Resource Kit to dump the source accounts, and add them to the destination PC.

XFR.bat contains:

@echo off
setlocal
If \{%3\}==\{\} goto err
set CorR=%1
if /i "%CorR%" EQU "C" goto Create
if /i "%CorR%" EQU "R" goto Restore
goto err
:Create
set fp=%2#
set fp=%fp:"=%
set fp=%fp:\#=%
set fp=%fp:#=%
if not exist "%fp%" goto err
set log=%3#
set log=%log:"=%
set log=%log:\#=%
set log=%log:#=%
if not exist "%log%" goto err
for /f "Tokens=1* Delims=:" %%a in ('@echo %fp%') do (
 set name=%%a%%b
 set drv="%%a$"
)
set name=%name:\=_%
if exist "%log%\Parent_*.txt" del /q "%log%\Parent_*.txt"
if exist "%log%\Folder_*.txt" del /q "%log%\Folder_*.txt"
if exist "%log%\ShareN_*.txt" del /q "%log%\ShareN_*.txt"
if exist "%log%\ShareD_*.txt" del /q "%log%\ShareD_*.txt"
set namef="%log%\Folder_%name%.txt"
set namep="%log%\Parent_%name%.txt"
subinacl /noverbose /outputlog=%namep% /subdirectories  "%fp%" /display
subinacl /noverbose /outputlog=%namef% /subdirectories=directoriesonly  "%fp%\*.*" /display
set forf=findstr /L /I /C:"%fp%"
set forn=findstr /V /L /I /C:"The command completed" /C:%drv% /C:"ADMIN$" /C:"IPC$" /C:"print$"
set fors=findstr /L /I /C:"Path " /C:"Remark " /C:"Maximum users "
for /f "Tokens=1*" %%a in ('rmtshare \\%ComputerName%^|%forf%^|%forn%') do (
 set shr=%%a
 call :sharename
)
endlocal
goto :EOF
:sharename
set names="%log%\ShareN_%shr%.txt"
subinacl /noverbose /outputlog=%names% /share %shr% /display
if exist %names% del /q %names%
for /F "Tokens=*" %%s in ('rmtshare \\%ComputerName%\%shr% ^|%fors%') do (
 set shrline=%%s
 call :sharedetail
)
goto :EOF
:sharedetail
set data=%shrline:~18%
if "%shrline:~0,1%" EQU "P" @echo P%data%>>%names%
if "%shrline:~0,1%" EQU "R" @echo R%data%>>%names%
if "%shrline:~0,1%" EQU "M" @echo M%data%>>%names%
goto :EOF
:err
@echo Syntax:
@echo XFR C FolderPath LogPath
@echo XFR R FolderPath LogPath
endlocal
goto :EOF
:Restore
set fp=%2#
set fp=%fp:"=%
set fp=%fp:\#=%
set fp=%fp:#=%
set log=%3#
set log=%log:"=%
set log=%log:\#=%
set log=%log:#=%
if not exist "%log%" goto err
for /f "Tokens=1* Delims=:" %%a in ('@echo %fp%') do (
 set name=%%a%%b
)
set name=%name:\=_%
set namep="%log%\Parent_%name%.txt"
if not exist %namep% goto err
set namef="%log%\Folder_%name%.txt"
if not exist %namef% goto err
for /f "Tokens=1*" %%a in ('type %namep%^|findstr /I /L /C:"+File"') do (
 if not exist "%%b" MD "%%b"
)
for /f "Tokens=1*" %%a in ('type %namef%^|findstr /I /L /C:"+File"') do (
 if not exist "%%b" MD "%%b"
)
@echo subinacl /playfile %namep%
subinacl /playfile %namep%
@echo subinacl /playfile %namef%
subinacl /playfile %namef%
if not exist "%log%\ShareD_*.txt" goto :EOF
for /f "Tokens=*" %%a in ('dir "%log%\ShareD_*.txt" /b') do (
 set shr=%%a
 call :makeshr
)
goto :EOF
:makeshr
set shr=%shr:ShareD_=%
set shr=%shr:.txt=%
for /f "Tokens=*" %%s in ('type "%log%\ShareD_%shr%.txt"') do (
 set shrline=%%s
 call :makeshr1
)
goto :EOF
:makeshr1
if "%shrline:~0,1%" EQU "P" set sp="%shrline:~1%"&goto :EOF
if "%shrline:~0,1%" EQU "R" set rm="%shrline:~1%"&goto :EOF
if "%shrline:~0,1%" EQU "M" set lm="%shrline:~1%"
set rshr=\\%computerName%\%shr%=%sp% /
if %lm% EQU "No limit" set rshr=%rshr%UNLIMITED&goto makeshr2
set rshr=%rshr%USERS:%lm%
:makeshr2
if %rm% EQU "" set rm=" "
set rshr=%rshr% /REMARK:%rm%
@echo rmtshare %rshr%
rmtshare %rshr%
@echo subinacl /playfile "%log%\shareN_%shr%.txt"
subinacl /playfile "%log%\shareN_%shr%.txt"



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish