Tuesday, May 12, 2009

Update to Compressing Files

Through the awesome energy that pours forth from POWERSHELL, and help from the internet, I was able to get a very simple script to do exactly what I needed to do.

I installed Powershell 1.0 onto the Windows Storage Server 2003 that has all the BAK files sync to it from source. Then my script goes through and creates a ZIP file of every BAK file. The author of the script above also wrote a quick script to delete all the BAK files once I was done.

Here is a run down of the script:

get-childitem -recurse |
where { $_.extension -match "bak" -and -not (test-path ($_.fullname -replace "bak", "zip")) } |
foreach { C:\7zip\7z.exe a ($_.fullname -replace "bak", "zip") $_.fullname }

get-childitem -recurse |
where { $_.extension -match "bak" -and (test-path ($_.fullname -replace "bak", "zip")) } |
foreach { del $_.fullname }


I choose a small font so the you can see the whole line as it would be in the script. Please keep in mind line breaks vs word wrap.
So here is what its doing:
  1. Give me all the files in the current directory recursively
  2. Filter out the files names that end in BAK that dont have a ZIP as well. ei: If File1.bak doesnt have a File1.zip, Grab it.
  3. Take the BAK file I just grabbed and ZIP it.

The second part of the script does the same thing as above with two minor changes:
  1. Grab files that DO have the same name as ZIP
  2. Then delete the Grabbed file.

While this script has been modified from its original, this is not my work. Credit goes to http://sradack.blogspot.com

THANKS SRADACK!!!

Tuesday, May 5, 2009

Compressing Files Independently in Script

Have an interesting issue today.

We have moved away from a 3rd party backup tool to SQL 2005 native. We have hundreds if not little over thousand DB files that now need to be compressed so we can save time on copying them to DEV.

This has nothing to do with Backup procedures or security. Simply put we dont want the dev department killing the bandwidth and time waiting for DBs to copy over to their environment. We want to automate this as much as possible.

I have been looking at the WinZIP CLI. I need to write a script that will take every individual BAK file and place them into their own zip file (or any compression format, personally I dont care). Its the seperation of every file that I am trying to work around. I am not the greatest Windows Script writer in the world. I try to avoid it of I can. However I need to do this. Possible a VB script can pull each file independently, compress it and them move onto the next. I might use an app that will do the copy and compress at the same time. Trying to do this on the cheap if I can.

Lets see what I come up with.

-Boston Tech Guy