[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 507
  • Last Modified:

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
0
JimMead
Asked:
JimMead
  • 9
  • 9
1 Solution
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now