Tuesday, 5 February 2008

Vista reparse shenanigans with rsync

As part of my backup script overhaul, I have switched to using rsync. The main reason is I now have to support Windows XP, Vista, Linux and maybe Mac in future; and I don't fancy re-doing all this backup stuff each time.

The good news first: rsync works a treat on Linux (well duh!) and XP (via cygwin). I was extremely happy with how easy to configure and quick to run the Linux and XP backup's were. But it seems I was fooled into a false sense of security...

I tried running exactly the same rsync script (that worked on XP) on Vista and was greeted with a slew of errors, the most confusing being:
rsync: /cygdrive/X/your-file-here: Permission denied (13)
Initially I thought it was the old Vista UAC playing up. But I confirmed that I had disabled UAC. The "permission denied" in this case, was a red herring. The real problem was the reparse points. These little symbolic links are available in XP, but not used much. But in Vista they really went to town, and scattered them all about the file system like the Easter Bunny hiding eggs.

rsync (well more likely the way it works with cygwin) is not too happy about reparse points, and after more careful inspection of my "Permission denied" errors, it turns out they were all on reparse points.

My hack to get around this is pretty simple. The backup script, just before running rsync, generates a list of all the reparse points and tells rsync to exclude them. Thus rsync never encounters a scary directory it doesn't know how to deal with.


VER | findstr /i "6.0.6000" > nul
IF %ERRORLEVEL% EQU 0 GOTO backup_vista

...rest of script...


backup_vista:
REM (dir) build a list of all the reparse directories
REM (sed) swap around the path separators

REM append to a file to use in rsync

dir c:\Users /A:LD /S /B | sed "s/c\:\\/\//;s/\\/\//g" >> exclude.local.list

dir c:\ProgramData /A:LD /S /B | sed "s/c\:\\/\//;s/\\/\//g" >> exclude.local.list
rsync options --exclude-from=exclude.local.list /cygdrive/c/ destination
...rest of script...


It's not pretty, but (to quote Mr C. Monster) "it's good enough for me".

For bonus points, you could keep a copy of the reparse point list, and for a restore resurrect them all. I don't need this.

Friday, 25 January 2008

readynas is smokin' hot

I bought an Infrant ReadyNAS NV+ a little while back to "delay" (I dare not say "solve") some of our storage problems. It has worked perfectly for over 10 months and was, without doubt, the simplest computer equipment I have ever set up.

Unfortunately last weekend (after being out of the house all day, on a hot day) the expensive scent of burning plastic started to waft through the office. A brief nasal inspection of all the computer equipment revealed the fault was with the ReadyNAS. The stench of death lasted another 10 minutes before the unit switched off, never to return.

Fortunately it's still under warranty and should be RMA'd within the week, but it made me question my choice of the ReadyNAS. When I bought it, I was under the impression it was one of the most full featured and reliable home NAS devices you could get (I'm not a fan of Buffalo - dunno why).

After calming down, I remembered I was warned about this situation (and emailed) from Infrant way back in the cool of winter. I remember thinking "yeah - that's a good idea, I will do that..."

(so you know what that means)

I didn't, and now it's toast.

So tip of the day: If you have a ReadyNAS that needs the temperature patch and is not in an air conditioned office, apply the patch now.

It's still a great home NAS box and I would recommend it. But it's not quite as bullet-proof (when it comes to heat) as I hoped.

Thursday, 24 January 2008

(song ends) ... Mono!

Lanley: And so, "mono" means "one." And "rail" means "rail." And that concludes our intensive three week course. [Marge vs. the Monorail]
Recently, I've been trying to offload a lot of scheduled processing from my desktop computer to a Linux (ubuntu in this case) server. One task that I thought might cause me some pain was XMLTV generation.

The general idea of the daily XMLTV task is:
  1. Suck down the latest program listings with (the excellent) shepherd script. Unfortunately this is a necessary evil, since Australian copyright laws are pretty strange for television programming.
  2. Augment the description field for each programme with the extra information shepherd provides. These are things like release year, episode name, director, actors, user ratings, etc. MythTV shows these extra details in the UI, but the MediaPortal UI does not currently show all this extra info. So the workaround is to cram it all into the description element (which is shown in the UI).
The old way to achieve this was to perform (1) on a ubuntu virtual machine (now no longer required as I have a real machine), and perform (2) on my desktop computer (Windows) via a little .Net 2.0 console program I cobbled together. Now that little program (or the logic it contained) needs to run on a real ubuntu machine.

I knew about the mono project already, but I had never actually tried to run it from scratch on existing code. The end result, after an easy 5 minutes was my existing code working perfectly on ubuntu.
  1. Install the core mono package (mono) and the .Net 2.0 compiler (mono-gmcs)
    sudo apt-get install mono mono-gmcs
  2. Run my existing (compiled in Visual Studio on Windows) executable on ubuntu with no recompilation or any other screwing around.
    mono xmltvAugment.exe
So easy.

This example was of course with a trivial .Net 2.0 console program. The program only used standard assemblies. But regardless, I was still impressed.

Wednesday, 23 January 2008

Ubuntu bits : System shutdown by power button


Simple enough problem: the headless server is sitting under the desk, the electricity needs to go off now (and you forgot to plug in the ups). You press the power button, nothing happens (as is normal).

Sure, you could just hold down the power button (or pull the plug). the file system will likely survive. Or you could fire up an ssh client and do a graceful shutdown. But if only that power button worked.


Well turns out the solution (for the next time it happens) is simple:

  1. Make sure your ACPI support is all happy.

    dmesg | grep 'ACPI:'

    If it's not - then you need to enable it in the kernel.
  2. Make sure ACPI has detected your power button.

    dmesg | grep 'ACPI: Power Button'

    If you have no luck, there's a kernel module you can load easily enough. Load it up, and check that it actually got loaded.

    sudo modprobe button
    lsmod | grep button

    Assuming all is well, add it to the boot time module list in /etc/modules
  3. Use acpid to monitor ACPI events and shutdown when the power button is pressed.

    sudo apt-get install acpid

    That's it. The default acpid scripts will intercept the power button and force an immediate halt.
  4. Optional : If you are really keen. Reboot, then:

    tail -f /var/log/syslog

    Then press the power button and enjoy the graceful shutdown.
  5. Bonus Points: If you don't the default event handler, tweak /etc/acpi/powerbtn.sh till your content.

Friday, 21 September 2007

Visual Studio Auto-Attach Macro

Although using the debugger to attach to your running code to inspect things can be considered "a bad thing" in some circumstances (i.e.: why aren't you using Debug.Assert() to enforce the internal state you are examining with the debugger? why aren't you using unit tests to enforce the exit state you are examining with the debugger?); sometimes you just got to do it. Well I do at least.

For ASP.NET development (IIS, Development Server, Cassini, or whatever) this can be a pain. You need to:
  1. Open the "Attach to..." window.
  2. Find the process (web server) you are interested in.
  3. Attach, wait and close the window.
As an alternative, I've been using a small macro to do these three steps and bound it to a little icon in the toolbar. Very easy: click the gears icon (my personal choice) and you're attached. Click the detach icon (default) and you're out of debug mode.



Of course you will need to alter the name of the process to look for depending on your web server (IIS 5 will typically need "aspnet_wp.exe", IIS 6 depends on the process mode you choose to run in).

I must apologise, the idea for this macro was taken from a source I can't locate anymore. The code is slightly modified, but the idea is the same.

' This subroutine attaches to the first Development Web Server found.
Sub AttachToFirstDevWebServer()
Dim process As EnvDTE.Process

For Each process In DTE.Debugger.LocalProcesses
If (Path.GetFileName(process.Name) = "UltiDevCassinWebServer2a.exe") Then
process.Attach()
Exit Sub
End If
Next

MsgBox("No ASP.NET Development Server found")
End Sub

Tuesday, 18 September 2007

It just made sense at the time...



After several weeks of ignoring Google Reader, I was playing catchup, and this one stuck a chord. It's so easy to pay out on advertising or marketing; but this one just seems right.

Tuesday, 24 April 2007

My friends and co-workers are just smurfs

I can remember back when I was young, having a fascination with collecting Smurfs. I don't remember the exact details, but I think you collected them at petrol/gas/service stations (maybe BP?). I had a fair amount (about 20+ I recall). I'd try and force my parents to constantly stop at the service station so I could get more. More, more, MORE!

Then one day (maybe a year or two later), I was sitting around looking at my box full of small blue bits of plastic, and I realised: I never really liked Smurfs anyway. Sure it was something to collect. But there were better things to collect. Things that I actually liked. Transformers comes to mind. :-)

So I had one of my first experiences of feeling tricked into collecting something that I didn't actually like, by clever marketing and snappy logos.

Time moves on, and now I'm starting to get the same feeling with LinkedIn. At the start, it seemed like a good idea (join a network of my friends and colleagues, find old workmates, get access to the "inside" job offerings). Inside the website you notice little "meters" that let you know "if you invite x more people, you will reach 90% complete". Mini-nags to remind you that you should spread LinkedIn to all your friends. Which is fine - it's viral marketing, I should know - I work for a company that does the same sort of thing.

But today I had a similar epiphany to the Smurfs (does that make it smurf-tacular?): I hate receiving emails along the lines of "join this website so you can do x". I get enough in spam, I don't want to receive the same thing from my friends. Yet here I am, sending emails to some of my closest friends, asking them to join a website they may never have heard of, just so I can get an extra little mark on my progress meter.

I'm not so disgruntled that I will immediately quit LinkedIn, and ask all my friends to do that same (besides, that's up to them). But I think I might leave it alone for a while (say a month or two) and see if I still feel as annoyed with myself (after all, it's me that sends the invites, not LinkedIn) as I do today.