Script to backup and restore NTFS Permission

 

Cool script to backup and restore NTFS permission.

Example

You need to backup NTFS permission of a folder in c:\Test and restore the same permission to another folder in D:\TestRST. Follow the steps below.

Create a batch file in the name NTFSBKP using the lines below.

———————————–

@echo off

If {%3}=={} @echo Syntax: NTFSBKP DriveOrFolder DestinationFolder BKP^|RST&goto :EOF

if not exist %1 @echo NTFSBKP – %1 NOT FOUND.&goto :EOF

if not exist %2 @echo NTFSBKP – %2 NOT FOUND.&goto :EOF

if /i {%1}=={%2} @echo Syntax: NTFSBKP DriveOrFolder DestinationFolder BKP^|RST&goto :EOF

if /i {%3}=={BKP} goto OK

if /i {%3}=={RST} goto OK

@echo Syntax: NTFSBKP DriveOrFolder DestinationFolder BKP^|RST&goto :EOF

:OK

setlocal

set DorF=%1#

set DorF=%DorF:”=%

set DorF=%DorF:\#=%

set DorF=%DorF:#=%

set Fld=%2#

set Fld=%Fld:”=%

set Fld=%Fld:\#=%

set Fld=%Fld:#=%

set Sw=%3

set F1=%DorF%

set F1=%F1::\=_%

set F1=%F1:\=_%

set F2=”%Fld%\%F1%_ALL.log”

set F1=”%Fld%\%F1%.log”

if /i “%Sw%” EQU “RST” goto Restore

set D1=”%DorF%”

set D2=”%DorF%\*.*”

if exist %F1% del /q %F1%

if exist %F2% del /q %F2%

subinacl /noverbose /nostatistic /outputlog=%F1% /subdirectories %D1% /display

subinacl /noverbose /nostatistic /outputlog=%F2% /subdirectories %D2% /display

endlocal

goto :EOF

:Restore

if not exist %F1% goto :Rest1

if not exist %F2% goto :Rest2

subinacl /nostatistic /playfile %F1%

subinacl /nostatistic /playfile %F2%

endlocal

goto :EOF

:Rest1

@echo NTFSBKP %1 %2 %3 – %F1% NOT FOUND.

endlocal

goto :EOF

:Rest2

@echo NTFSBKP %1 %2 %3 – %F2% NOT FOUND.

endlocal

————————————————

Now to backup the NTFS permission follow the steps below.

  • Download SUBINACL from http://www.microsoft.com/downloads/details.aspx?familyid=e8ba3e56-d8fe-4a91-93cf-ed6985e3927b&displaylang=en
  • Now copy the file subinacl from this to a folder called Script in C:\
  • Copy the NTFSBKP.bat file to c:\script along with subinacl
  • Create a folder as C:\Restore.(this will have the backup logs for the ntfs permission)
  • Now run the command NTFSBKP c:\test c:\restore BKP
  • Wait till the logs are created. There will be 2 files named c_Test & C_test_all in the C:\RESTORE folder.
  • When you edit the files you can see the details about the NTFS Permissions.

To Restore the NTFS permission to D:\TestRST follow the steps below.

  • Now edit the files in c:\restore folder
  • Open it with Wordpad as some times the file size will be large.
  • Now find for C:\test and Replace it with D:\testRST and replace all < This makes sure that the permissions of c:\test is restored to D:\testRST.>
  • Now save the files.
  • Now rename the C_Test to D_TestRST & c_Test_all to D_TestRST_all
  • The logic is it should be renamed as it matches the destination folder name.
  • Now run the command NTFSBKP D:\testRST c:\restore RST
  • This will do the magic.

Enjoy.

Source :http://www.ntfs.com/ntfs-permissions-restoring.htm