Share via


Robocopy file compression attribute

Question

Wednesday, January 11, 2012 2:47 PM

Hi,
I am trying to migrate my clustered file server from a server 2003 cluster to a new server 2008 R2 cluster.
I have the new cluster all set up and ready to go but I am having trouble copying the data accross.

On my file server there is a mix of compressed and uncompressed files and folders.   When I run the following robocopy script all files and folders are copied with their permissions but the files and folders that have been compressed lose this attribute after copied.

robocopy "SourceServer" "DestinationServer" /sec /b /copyall /r:1 /w:5 /E

Has anyone come accross this before and found a solution to it?

Regards
John

All replies (1)

Wednesday, January 11, 2012 7:21 PM âś…Answered

Hi.

I can say I get the same result, but as I really hate compression I haven't thought about it before. The problem as I guess, not seeing the code of robocopy.

From Microsoft KB251186 Best practices for NTFS compression in Windows:
When you copy or move a compressed NTFS file to a different folder, NTFS decompresses the file, copies or moves the file to the new location, and then recompresses the file. This behavior occurs even when the file is copied or moved between folders on the same computer.

Also the /Sec is redundant as it is implied via /copyall

But back to what you wanted to do, the following function will go down through a directory structure and report all compressed files and directories.

 

function DiscoverCompressedDirectory
{
  param(
    [parameter(Mandatory=$True, HelpMessage="Where will the function look")]
    [string]
    [ValidateScript({Test-Path -PathType Container -Path $_})]
    $DiscoveryPath
  )
  Process
  {
    Get-ChildItem $DiscoveryPath | ForEach {
      if ($_.attributes -band [io.fileattributes]::compressed) {
        $_ | Select-Object FullName,Attributes
      }
      if ($_.attributes -band [io.fileattributes]::Directory) {
        DiscoverCompressedDirectory -DiscoveryPath $_.FullName
      }
    }
  }
}

Then run it by

 

$toBeCompressed = DiscoverCompressedDirectory D:\Folder\With\CompressedIn

It will return a table that you can then export/import or just pipe to the compact command. I tried to do it in powershell but Set-ItemProperty wont allow editing of the compressed attribute.

So to "restore the compression run the following:

$toBeCompressed | ForEach {compact /c $_.FullName}

I believe this is a solution to your problem.

Oscar Virot