Great Script to tidy Up our Photos

I was looking for a way to tidy up out photos on the NAS at home and have tried a number of things that just did not fit the bill.

they were either just to difficult or completely wrong.

i then stumbled upon this blog post

What a gem. if you can install ruby on a machine you have to sort your photos this is it.

The post is from 2009 and so I had to update some of the gems it uses as well as change some of the code. but it was not much work.

Thanks to Falesafe for making it available it had another bonus in that I found out that we have 76000 photos.

I feel some culling is needed.


I had to work with the script a bit as the EXIF attribute it was using was causing my photos to be sorted incorrectly namely (date_time).
So I have updated the script to use the (date_time_original) atribute and this has now sorted my photos properly for me. The original post that was written has comments that are closed so I will upload the adjusted script here if you want to use it.

# == Synopsis
# This script examines a source directory for photos and movie files and moves them to
# a destination directory.  The destination directory will contain a date-hierarchy of folders.
# == Usage
# ruby photo_organizer.rb [ -h | --help ] source_dir destination_dir
# == Author
# Doug Fales, Falesafe Consulting, Inc.
# == Change Log
# LANCE HAIG = changed the EXIF attribute used to determine photo date taken to .date_time_original
# == Copyright
# Copyright (c) 2009 Doug Fales.
# Licensed under the same terms as Ruby.
require 'rubygems'
require 'exifr'
require 'find'
require 'logger'
require 'optparse'
require 'pathname3'
require 'digest/sha3'

STDOUT.sync = true

#$log ="photo_organizer.log", 3, 20*1024*1024)  # Log files up to 20MB, keep at least three around
#$"Photo organizer started...")

def log
	@log ||="photo_organizer.log", 3, 20*1024*1024)  # Log files up to 20MB, keep at least three around
end"Photo organizer started...")

def usage()
puts < e
			if(f =~ /.DS_Store/)"Skipping .DS_Store")
			elsif (e.message =~ /malformed JPEG/)"Malformed JPEG: #{f}")

		if(time.nil?)"WARNING: No EXIF time for: #{f}.  Will skip it.")

		was_moved = move_image(f, time)
		increment_counter if was_moved

	when"Processing directory: #{f}")
	else "?""Non-dir, non-file: #{f}")

puts "\nFinished."

Quest NDS Migrator LogFile Parser

I am currently helping a customer migrate from Novell to Microsoft and they are using the Quest migrator product to move their data to new DFS servers.
They currently have a large amount of data stored on a number of volumes. The sheer number of volumes and data have required that they deploy a large number of the copy engine servers.
The copy engine does not utilize a central logging facility, it stores the logfiles in a folder alongside the copy engine.
This unfortunately has a side affect, that there are now quite a few log files and some are reaching over 1.5GB in size.
Trying to load these files into a text editor as proven impossible and unworkable and another way was needed.

I decided that the best way to achieve this was to use a script that would parse the log files and extract the errors from the files into another file that would be smaller and easier to work with.

I decided to use Powershell as the scripting language as it would run on the new infrastructure and could be run on a copy engine server with enough disk space.

I undertook quite a bit of research and trial and error but eventually I have a working script.

This script is not signed so you will either need to sign the script to run it or elevate the privileges with set-Executionpolicy on the system you are going to be using.

The script uses two files the main script file and a csv file with the volume names and copy engine server names.

Below you will find a copy of both. I have also created a git repository that you can find on GitHub if you would like to help make it better

Original PowerShell Script

[codebox 1]

Original CSV File

[codebox 2]

Building the new Bongo Admin UI

A while ago Alex (so_solid_moo to the IRC channel) created a php binding for the Bongo API. He also created the start of the new UI that we are working towards.

We started with the admin ui for now as we have created a user interface with the roundcube project that Alex also integrated with.

I stared porting the current Dragonfly assets into the project and I tried to stick to the old design style as much as possible as I really loved it’s look and feel.

After a bout a week I was done and submitted it to the git repo of the new project.

Although I was glad that we had stared the project and that I had done as well as I could on the pretty bits I was not quite happy with the quality of the work.

I was going through my git repo’s this weekend and found the twitter git repo where they have open sourced all their CSS (Cascading Style Sheets) this inspired me to see if I could use this as it was MUCH better quality CSS that what I could come up with.

So I started work on the migration as an experiment and from the word go it was so much easier. Their default styles just make sense and to alter or add my customisation took only a very few lines of CSS code.

I was extremely grateful for this as it will enable us to improve our UI as we go along. you can find the new webui in Alex’s github project here.

Thanks twitter

My interesting way to end a week.

This is an account of Thursday the 29th of September 2011 when my cynical view on Londoners only thinking of themselves and not wanting to get involved with other peoples troubles was blown completely out of the water thanks to some really amazing people who I don’t have names for but would really love to thank from the depths of my heart for everything they did for me.

The story begins as I am making my way from Hertfordshire down to Camden on my commute to get to the office.

At about 08:22 in the morning I was driving down Hawley Road on my motorcycle and stopped for a Red traffic light at the junction with Jeffrey’s and Camden Street after a short while the light turned orange and then green for us. As this is normally when a load of cyclists jump the red light on the Kentish Town Road part of this junction I made sure to check that none had done so and then started to travel across the junction, once I had reached about ¾ of the way across the junction I felt the most unbelievable pain on my left side, felt myself hit the road surface on my right hand side and heard my self screaming. (and no it was not like a girl but close though)

The pain was something that was indescribable and all I could see was my bike over my left shoulder and the smell petrol that was leaking out of the petrol tank around me. I looked up to see if any cars were coming and unable to stop but thankfully none were.

(This is where people who I have never known stepped into my life to my eternal thanks)

Almost immediately I gentleman in a dark suite was leaning over me looking through my visor and asking if I was ok, All I could feel at the time was the screaming pain in my left foot and answered yes. I looked over my shoulder and saw another gentleman talking to a young lad in a grey helmet all I could hear was did you not see the red light.

Out of the corner of my eye I saw another gentleman in a black helmet and a white shirt (I think) take off his helmet and say “are you ok mate?”, “Do you know your Name?” I tried to answer him as best I could. I then realised that I had not hurt my head or hands or arms so decided to take off my helmet so I could see and hear better as I use earplugs in my ears to protect them from the motorway sounds.

After taking off my helmet and taking out my ear plugs the intense loads sounds flooded into my brain and I realised that my helmet had cut off my ability to realise that there were so many more people who had stopped on there way to work to help me.

I looked behind me and could see the young chap who had ridden into me sitting against the railings on the pavements clearly in a great deal of shock and I became worried for him as he was really pale. A bit further over I looked at what was left of his Vespa and thought Bloody hell how am I still conscious and he sitting there.

A wonderful vision in dayglo yellow cyclists gear was a lady who promptly informed me that she had called the ambulance and the police and that they would soon be here.

My attention was grabbed by a tapping on my Right hand shoulder another man in motorcycle helmet leaned in and said “I was right behind you and saw it all, here is my business card I will be a witness for you”, and with that he was off and climbed on his bike and road off. I did not even have time to say thanks.

All this time the gentlemen in the dark suite and white shirt kept talking to me asking me if I still felt ok. He asked me if I would like to get out of the road to which I agreed but then I realised that at 118 kgs and being over 6feet would make things difficult for them so I crawled towards the pavement.

I remained calm which I was pleasantly surprised about and this helped I think everyone around me to keep focussed on what they needed to do to help me.

For some reason I was worried about my laptop that was in the storage on the back of my bike and so asked the gentleman in the white shirt if he would mind getting it out for me. He duly did and I can only thank him for that. I was after my mobile phone so I could call my wife as I did not want anyone calling her first and scaring her. The gentleman in the white shirt said just use mine I don’t mind.

It was about 3 minutes later that the first ambulance arrived on the scene and two lady ambulance paramedics climbed out and started to do there work on me.

After a short while I was in the ambulance and through the open door I could see the man in the suite and the one in the white shirt smile at each other and then as if to say well no one else will do this they shrugged their shoulders and these wonderful people physically righted motorbike and wheel it onto the pavement.

The ambulance staff (I wish I had taken their names) then closed the door and started going through their procedures Blood pressure finger pricks blood oxygen levels etc… and they did this with a smile on their faces and in their voices. To anyone who ever says anything bad about the NHS ambulance staff I think you are completely mistaken.

We then heard the police siren and a Metropolitan police officer PC Barker knocked on the door and entered again these guys were the nicest people to talk to and were a credit to their profession.

After a few more questions and answers we were free to go and I was taken to the Royal Free Hamsted hospital where I was taken to the Minors 4 cubical where some really great medical staff came to my aid and scanned and prodded and x-rayed me whilst some learner Dr’s etc.. looked on and I am glad I could add one more addition to their education a RTC between two motorcycles.

The orthopedic staff determined that I had a fractured ankle and would not need screws etc.. (whew) and a cast would be all that is needed to med these broken bones.

My wonderful wife then walked in to the cubical and I relaxed quite a bit as I knew that my day could only get better from then on. After getting a back slab plaster cast and with strict instructions not to walk on my leg and a booked appointment for the fracture clinic next Thursday We dutifully made our way out of the hospital. I had not used crutches in a very long time so it was slow going.

The wonderful people at the company I work for help arrange transport home from the hospital to home where I was happy to sit on the couch with my foot up. My motor mechanic friend woke up at 4am and went to pick up my motorbike on Friday I can’t that Duncan enough.

So to all you wonderful people

  • Gentleman in the Dark suite
  • Gentleman in the White Shirt
  • Lady cyclist dressed in dayglo yellow
  • Gentleman who gave me his business card.
  • The people who helped roll my motorbike to the pavement
  • The two ladies who drove the ambulance
  • PC Barker and his partner
  • The medical staff at the Royal Free Hamstead hospital
  • Duncan from Bikers realm

I wish I had had the forethought to get all your names so I could thank you in person all I can do unfortunately is thank you from the bottom of my heart and on behalf of my Mother, Father,Wife and kids thank you for helping to get me safely home.

How to copy custom attributes when migrating vmware vcenter to new database

I recently had to move hosts and guests to a new vcenter server as the old server had become corrupt and full of issues.
The current vcenter has a few custom attributes and notes that would not be transferred as part of the move.
So I wanted to use powercli to read the attributes out and put them back.

To export the attributes I used the script below.
You will need to add as many Key Value pairs as you have custom attributes

#load Vmware Module
Add-PSSnapin VMware.VimAutomation.Core

Connect-VIServer -User 'VMUSER' -Password 'USerPasswd221' -Server 'vcenter1'

$vmlist = get-vm
$Report =@()
foreach ($vm in $vmlist) {
$row = "" | Select Name, Notes, Key, Value, Key1, Value1, Key2, Value2, Key3, Value3
$ = $vm.Name
$row.Notes = $vm | select -ExpandProperty Notes
$customattribs = $vm | select -ExpandProperty CustomFields
$row.Key = $customattribs[0].Key
$row.Value = $customattribs[0].value
$row.Key1 = $customattribs[1].Key
$row.Value1 = $customattribs[1].value
$row.Key2 = $customattribs[2].Key
$row.Value2 = $customattribs[2].value
$row.Key3 = $customattribs[3].Key
$row.Value3 = $customattribs[3].value
$Report += $row

$report | Export-Csv "c:\vms-with-notes-and-attributes.csv" -NoTypeInformation

It should produce a csv file that looks something like this


Once you have exported the file you need to import it into the new vCenter
again adding Key Value pairs as needed.

#load Vmware Module
Add-PSSnapin VMware.VimAutomation.Core

Connect-VIServer -User 'VMUSER' -Password 'USerPasswd221' -Server 'vcenter2'

$NewAttribs = Import-Csv "C:\vms-with-notes-and-attributes.csv"

foreach ($line in $NewAttribs) {
set-vm -vm $line.Name -Description $line.Notes -Confirm:$false
Set-CustomField -Entity (get-vm $line.Name) -Name $line.Key -Value $line.Value -confirm:$false
Set-CustomField -Entity (get-vm $line.Name) -Name $line.Key1 -Value $line.Value1 -confirm:$false
Set-CustomField -Entity (get-vm $line.Name) -Name $line.Key2 -Value $line.Value2 -confirm:$false
Set-CustomField -Entity (get-vm $line.Name) -Name $line.Key3 -Value $line.Value3 -confirm:$false


Hope this helps someone.

Creating a Two Node Mysql Cluster On Ubuntu With DRBD Part 2

This blog is a follow on from a blog post I wrote ages ago and have eventually got round to finishing it off

In this part of the process we will create the disks and setup the DRBD devices
First we need to connect to the Virtual Machines from a terminal session as it makes life much easier and quicker when you connect remotely.
You will need to make sure that your servers have static IP addresses.
For this document I will be using the following IP addresses for my servers.

drbdnode1 =
drbdnode2 =
drbdmstr = (clustered IP address)
Subnet Mask =
Gateway =
DNS Servers = and

So to set the IP address as fixed you need to do the following.
Connect to the console of drbdnode1 and login
now we need to edit the file that contains the IP address of the network card
enter the following command and press return

sudo nano /etc/network/interfaces

enter the password for the user you are logged in as
You should see the following screen

now use your arrow keys on your keyboard and move the white cursor to the section that starts with iface eth0
press Ctrl K to remove the line then add the lines below with your IP address details

auto eth0
iface eth0 inet static

It should end up looking like this

Now press Ctrl X to exit
Then Y
Then press Enter to save
Now type in the following

sudo /etc/init.d/networking restart

Do the same for drbdnode2
Now that we have given each server a static Ip address we can connect via ssh to the server to do the admin remotely.
To do this you need to have a machine that has an ssh client installed most linux and osx clients have one already installed if you are on windows look for putty and use that.
So open a terminal on your machine and the in the following

ssh cluster@ and press enter.

You need to substitute the username you created on your server when setting it up for the word cluster in the above command.
You will be prompted to accept a key for the server. Type yes and press enter.
Now enter the password for the user and press enter.
You should see a screen like this

Connect to both cluster nodes to make sure you are not stopped down the line to fix the problem.
You are now ready to work on your cluster.
First we need to create host records for the two servers
type the following into your terminal session

sudo nano /etc/hosts

and add a record for each server it should look something like this

Save the file as before and do the same for node2 but swap the names and ipadresses
Now we need to install a few packages that will allow us to use drbd
in the terminal on drbdnode1 type

apt-get install heartbeat drbd8-utils

and press enter you should have a screen like this

Press Y and then Enter to install the software. Do this on drbdnode2 as well
Now we need to create the partitions that we will use for the drbd cluster
to find out which disk we will be using run the command

sudo fdisk -l

to see which disks have not been partitioned your screen should look like this

As you can see at the end is the disk /dev/sdb does not have a partition table
look for the line “ Disk /dev/sdb doesn’t contain a valid partition table “
to create a partition table we need to run the following commands

sudo fdisk /dev/sdb
n (to create a new partition)
p (to select a primary partition)
1 (for the first partition)
Enter (to select the start cylinder)
and enter (to select the end cylinder)
w (to write the changes)

the screen should look like this

Do this on both servers
once this is complete we now need to edit the drbd configuration files to set up our clustered filesystem.
In your terminal on drbdnode1 enter the command

sudo nano /etc/drbd.d/clusterdisk.res

Enter the password for your user and edit the file
Copy and paste the following code into your terminal screen and then change the details to match your server names and ipaddresses

resource clusterdisk { # name of resources

protocol C;

on drbdnode1 { # first server hostname

device /dev/drbd0; # Name of DRBD device

disk /dev/sdb1; # Partition to use, which was created using fdisk

address; # IP addres and port number used by drbd

meta-disk internal; # where to store metadata meta-data


on drbdnode2 { # second server hostname

device /dev/drbd0;

disk /dev/sdb1;


meta-disk internal;


disk {

on-io-error detach;


net {

max-buffers 2048;

ko-count 4;


syncer {

rate 10M;

al-extents 257;


startup {

wfc-timeout 0;

degr-wfc-timeout 120; # 2 minutos.



The screen should look similar to this

ctrl x (to exit)
y (to save the changed file)
enter (to overwrite the file)
Now we need to create the DRBD resource
enter the following command into your terminal session

sudo drbdadm create-md clusterdisk

After running this command you should see a screen similar to this

On drbdnode1 enter the following command

drbdadm -- --overwrite-data-of-peer primary all

this will activate it as the primary drbd node
to see if this has worked you can run the following command

sudo drbdadm status

the result should look like this on drbdnode1

and like this on drbdnode2

you will see that drbdnode1 has a status of
and drbdnode2 has a status of
this tells you what role they are playing in the cluster
at the end of this line you will see a status resynced_percent=”3.8″
this tells you how much the drbd disk has synced.
Once the sync is complete connect to drbdnode1 and run the following command

sudo mkfs.ext4 /dev/drbd0

this will create an ext4 partition on the drbd file system. Which will sync across to drbdnode2

Configuring heartbeat resource

Now we need to setup the Mysql resource in the heartbeat configuration
firstly we need to create a file called authkeys. The file should be created in /etc/ha.d directory. You can do this with the following command

nano /etc/ha.d/authkeys

in this file you need to add the following text.

auth 3


Replace [SECRETWORD] with a key you have generated.
This file needs to be on both servers in the /etc/ha.d directory.
After you have created the file you need to change the permissions on the file to make it more secure. This can be done with the following command

chmod 600 /etc/ha.d/authkeys

do this on both servers
Now we need to create the /etc/ha.d/ file to store the cluster config.
You can do this with the following command

nano /etc/ha.d/

copy and paste this code into the file

logfile /var/log/ha-log

keepalive 2

deadtime 30

udpport 695

bcast eth0
auto_failback off
stonith_host drbdnode1 meatware drbdnode2
stonith_host drbdnode2 meatware drbdnode1
node drbdnode1 drbdnode2

do the same for both servers
next is the haresources file. Create the file here

nano /etc/ha.d/haresources

paste this code in there

dhcp-1 IPaddr:: /24/eth0 drbddisk::clusterdisk Filesystem::/dev/drbd0::/var/lib/mysql::ext4 mysql

Your cluster is now ready to role.
All you now need to do is test the cluster which I will tell you how to do in a future blog post
Let me know how you get on

ESX Trunk VLAN config for Storage

I was struggeling with an install of ESXi on a cisco 6509 switch where the management and VM LAN connectivity worked just fine but for some reason the SAN NFS VLAN just did not want to communicate with the Nexenta on that VLAn.

After some searching and trial and error I was able to utilise this post to get the port-channel and the ports configured correctly. I did not use all the settings from this post but it did remind me to check my port0-channel config.

Connecting ESXi 4.1 to extreme x650 10G switches

I am busy working on a contract with a comonay that is implementing a 10G network for their ESX cluster.

We have been using extreme X650 10G copper switches for the core.

Migrating the current servers to the 10G environment was relatively easy and went with minimal issues.

Over the last 2 weeks I have been trying to get a new server to connect to the cluster ahnd have been frustrated. I have been unable to get the server communicating on the management VLAN. the server was configured correctly and so was the switch or so I thought.

It seems that to make this work you need to add the network cards to the vlan in the extreme os as untagged which then allows you to connect the server to vCenter and then once you add your NIC’s to the dv switch you lose connectivity again and have to readd the ports to the management vlan as tagged.

this post is more fo rme to be able to look it up in the future.

Learning Ruby and rBongo with WeBongo

This post should have been written quite a while ago as I wanted to start documenting my efforts to learn to program using Ruby. As most of you know I have been trying for a while to teach myself to programe.

I started my efforts with a course in c# at a company in London, the course was just great and the instructor was a fantastic guy. Unfortunately life meant I could not practice at all. I worked for a company for a year that gave me no opportunity to play during the day and having a newborn baby left my wife and I looking more like zombies that real people.

Then things changed the year before last when I Joined Forward as a contractor to help them with their Virtual infrastructure. This company is completly different to anywhere I have ever worked before. Normaly as a contractor you are shoved in a corner and beat with a whip so that they get the most out of you, here at Forward this is definitly not the case.

Forward has some really great intelligent developers who are a pleasure to work with and be part of and that is where I was going with this post.

A short while ago Fred George held one of his famous OO Bootcamp training sessions and I was lucky enough to be invited to join and true to Freds statement he tries to keep the course at a level where you always feel stupid and belive me I felt REALLY stupid. The good thing about feeling stupid was I actually learnt something. You kind of learn to program by accident (quoting Tom Hall).

This is where the Ruby, rBongo, WeBogo bits come in. Fred uses Ruby to illustrate OO programming best practice and to help you understand OO in general a side effect of this is that you start learning ruby syntax and start learning the programming vocabulary needed to accomplish the tasks, having gained some experience with ruby during the course I thought it best to use ruby to continue learning to program.

I have been working on Bongo since it was founded and the other day I was speaking to Alex the project lead and we realised it is almost 10 years now. I have always wanted to contribute more than just packaging the app on the OBS and being available to do testing and such. Alex wrote the PHP binding for the Bongo Store and having seen what some of the guys can do at Forward with Ruby and jQuery I wanted to create a binding for the store in Ruby and create a gem from it thus allowing anyone to create the best REST interface ever.

This is forcing me to learn TCP Sockets win Ruby and other nice things. I will try to document as often as I can what I am upto on this.

My efforts will be on 2 Ruby projects. Initially I will need to work on rBongo which is the ruby binding for the Bongo store I am sure most of the developers at Forward could probably write this in a day or so, hopefully I can convince one or two of them to help out .

My second effort will be on WeBongo the REST webui for the Bongo mail store. I have other ideas for the webui once we have a working solution (using it as a sync destination for Tomboy desktop notes)

Please keep that in mind as I try to get this working.