Compress .svn folders on Windows Server 2003

Hi,

We are using Subversion repos for versioning our websites, and I have recently been looking into disk space usage and noticed that we currently have 1,279 .svn folders containing a total of 10,232 folders, 26,266 files and using 2.26GB of disk space, and there are roughly another 50 sites to add as we migrate them from another location and add them to the repository so this is likely to increase dramatically.

I do not have file compression enabled as I believe this slows down file processing/serving, however I would like to enable compression on all .svn folders, but can see no way of doing this automatically based on directory name.

I could do it manually by searching for .svn and setting the compress flag under advanced attributes, however this is a hassle and I would rather it could be done on a schedule.

Is there an application that can find all folders with a certain name and recursively set that directories compress flag (not the archive flag).

Thanks
JimMeadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kruger_monkeyCommented:
compact.exe ?

I know you can compress folders from the command line using compact.exe.  This will possibly do it for you.  See the following for more details.

http://pubs.logicalexpressions.com/pub0009/LPMArticle.asp?ID=427

http://technet.microsoft.com/en-us/library/cc726045(WS.10).aspx
0
Chris DentPowerShell DeveloperCommented:

Would you explore PowerShell as a means to do this?

I was thinking of something along these lines...

Chris
Get-ChildItem "SomePath" -Filter ".svn" -Recurse | ?{ $_.PsIsContainer } | %{
  If (($_.Attributes -BAnd [IO.FileAttributes]::Compressed) -eq 0)
  {
    $WMIItem = [WMI]"Win32_Directory.Name='$($_.FullName)'"
    $Return = $WMIItem.Compress()
  
    If ($Return["ReturnValue"] -eq 0)
    {
      Write-Host "Success: Compressed $($_.FullName)"
    }
    Else
    {
      Write-Host "Failed: $($_.FullName) $($Return["ReturnValue"])"
    }
  }
  Else
  {
    Write-Host "Skipped: Already Compressed $($_.FullName)"
  }
}

Open in new window

0
JimMeadAuthor Commented:
That PowerShell script looks good, but it doesnt seem to work for me, I have tried running it with some extra Write-Host llines in it to trace how far it it getting, and it seems to skip over the entire get block as it is printing
Hello 1
Hello 4

I dont know enough about PowerShell to do more than that unfortunately
Any ideas?

Thanks

Write-Host "Hello 1"
Get-ChildItem "G:\Test\" -Filter ".svn" -Recurse | ?{ $_.PsIsContainer } | %{
Write-Host "Hello 2"
  If (($_.Attributes -BAnd [IO.FileAttributes]::Compressed) -eq 0)
  {
Write-Host "Hello 3"
    $WMIItem = [WMI]"Win32_Directory.Name='$($_.FullName)'"
    $Return = $WMIItem.Compress()
  
    If ($Return["ReturnValue"] -eq 0)
    {
      Write-Host "Success: Compressed $($_.FullName)"
    }
    Else
    {
      Write-Host "Failed: $($_.FullName) $($Return["ReturnValue"])"
    }
  }
  Else
  {
    Write-Host "Skipped: Already Compressed $($_.FullName)"
  }
}
Write-Host "Hello 4"

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Chris DentPowerShell DeveloperCommented:

It'll be this bit then, I wasn't sure quite what I was looking for:

Get-ChildItem "G:\Test\" -Filter ".svn" -Recurse | ?{ $_.PsIsContainer }

We're starting at test, filtering to anything named (exactly) .svn, and then filtering down to only folders. I suspect I'm simply filtering too much.

How does it all appear in your directory structure?

Chris
0
JimMeadAuthor Commented:
Hope this is what you are asking for.

svnstruct.jpg
0
Chris DentPowerShell DeveloperCommented:

Well that should work, that should have got it as far as "Hello 2".

Would you mind running this on its own and see if it gives you anything back?

Get-ChildItem "G:\Test\" -Filter ".svn" -Recurse

Chris
0
JimMeadAuthor Commented:
Doesnt seem to do anything, no errors either
Just a thought, but maybe assign it to a variable
$dirstruct = Get-ChildItem "G:\Test\" -Filter ".svn" -Recurse
Or something like that?
0
Chris DentPowerShell DeveloperCommented:

No good if it doesn't return anything, we need to see why it's not returning anything before we go there.

Try:

Get-ChildItem "G:\Test" -Recurse | ?{ $_.Name -Like "*.svn*" }

See if that one gives you the folders?

Chris
0
JimMeadAuthor Commented:
No, nothing

Should I be running this under powershell 1 or 2
I am currently using 1 as 2 is not installed
0
Chris DentPowerShell DeveloperCommented:

Either is fine. I only test under 2, but we're not doing anything that requires it.

How about just this:

Get-ChildItem "G:\Test" -Recurse

Does it actually pop up any of your svn folders?

Chris
0
JimMeadAuthor Commented:
Aah, yes, that seems to list all folders except the .svn folders
Just had a quick look and they are hidden so that might explain it
0
Chris DentPowerShell DeveloperCommented:

Ahhh it will :)

Back to the top... we need the -Force parameter.

Does it display a few more of the hello's now?

Chris
Write-Host "Hello 1"
Get-ChildItem "G:\Test\" -Filter ".svn" -Recurse -Force | ?{ $_.PsIsContainer } | %{
Write-Host "Hello 2"
  If (($_.Attributes -BAnd [IO.FileAttributes]::Compressed) -eq 0)
  {
Write-Host "Hello 3"
    $WMIItem = [WMI]"Win32_Directory.Name='$($_.FullName)'"
    $Return = $WMIItem.Compress()
  
    If ($Return["ReturnValue"] -eq 0)
    {
      Write-Host "Success: Compressed $($_.FullName)"
    }
    Else
    {
      Write-Host "Failed: $($_.FullName) $($Return["ReturnValue"])"
    }
  }
  Else
  {
    Write-Host "Skipped: Already Compressed $($_.FullName)"
  }
}
Write-Host "Hello 4"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JimMeadAuthor Commented:
Looks good, thanks

Hello 1
Hello 2
Hello 3
Success: Compressed G:\Test\mastertiles.www.co.uk\.svn
Hello 2
Hello 3
Success: Compressed G:\Test\mastertiles.www.co.uk\datasources\.svn
...
Success: Compressed G:\Test\mastertiles.www.co.uk\www\_CustomErrors\includes\.svn
Hello 2
Hello 3
Success: Compressed G:\Test\mastertiles.www.co.uk\www\_SiteConfig\.svn
Hello 4
0
Chris DentPowerShell DeveloperCommented:

Excellent, that looks a lot better. You should find it tells you it's skipping those if you run it again.

Chris
0
JimMeadAuthor Commented:
One thing to note, it doesnt do the Already Compressed bit
0
Chris DentPowerShell DeveloperCommented:
Really? Hmm can you run:

(Get-Item G:\Test\mastertiles.www.co.uk\datasources\.svn -Force).Attributes

See if it has the Compressed flag there? It "should"...

Chris
0
JimMeadAuthor Commented:
Its OK, I think it was me being stupid, just did it again and its saying Already Compressed
0
Chris DentPowerShell DeveloperCommented:

Phew :) I thought I'd tested that bit.

Chris
0
JimMeadAuthor Commented:
Works perfectly, just need to remove the lines that say
Write-Host "Hello #"

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Utilities

From novice to tech pro — start learning today.