| Join | Help

February 2008 - Posts

Saturday, February 16, 2008 5:01 AM

Powershell is addicting

It's been a while since my last tech post, but I couldn't help this one... 

Recently I have more or less fallen into the role of maintaining the infrastructure at our company. We recently got decent server to run a few Virtual Machines on. I've had mixed feelings on VMs, but that is a story for another day. We decided to go with VMWare ESX, which after 3 VM's is humming along smoothly. One of the things we needed to do was make sure our VMs were backed up properly. I am aware that ESX has this baked into it, but we aren't interested in backing up the whole VM, just a single folder in most cases. We recently accomplished this with a somewhat complex BAT script.   I decided to see if PowerShell could make things easier.

At first, I found powershell a bit frustrating. After a while though, I found it a very effective way to get something done. For instance, I needed to loop through several SVN repositories, run svnadmin hotcopy on them, then copy that across a network. That was really a breeze with powershell, whereas it would be a bit more difficult in a BAT script, if not hard to maintain and read. This is how I accomplished the task:

$repositoriesPath = "C:\source\repositories\"$backupPath = "C:\backups\"$repositories = get-ChildItem $repositoriesPath | where {$_.PsIsContainer}foreach($repository in $repositories){$repositoryDirectory = $backupPath + $repositoryif (Test-Path $repositoryDirectory){Remove-Item -path $repositoryDirectory -recurse -force}New-Item $repositoryDirectory -type directoryecho "Hotcopying repository $repository"svnadmin.exe hotcopy ($repositoriesPath + $repository) $repositoryDirectory}

The reason for the hotcopy is that it is generally a bad idea to read the SVN repositories directly. If you attempt to backup a repository during a transaction, you might end up with a wedged Berkley DB or even a corruption.

This script makes sense to me, it's easy to maintain and change if needed. And since we have full access to the .NET BCL, we can easily newup a MailMessage object and send a confirmation email that the backup was successful, or that it failed and needs to be fixed.

For a 1.0 release of powershell, I am very impressed. This was actually my first time using powershell, and wanted to see how practical it was.

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones with no comments
Filed under:
Thursday, February 14, 2008 9:12 PM

Roanoke Valley Code Camp

It's that season again... Code Camps! Anyone in the Roanoke Valley area I would encourage to come out to the code camp on March 1st, as always there will be goodies to give away at the end, not to mention a good lineup of speakers. There's bound to be something that you'll find interesting. Check out the schedule here: http://www.rvnug.org/CodeCamp2008Schedule.html .

I will be doing a presentation on SQL CLR, which I think will be interesting. Bryce Covert, a co-worker I work with will be doing a presentation on Spring .NET, which I am looking  forward to.

Share this post: | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Kevin Jones with no comments