Off site backups

This long weekends task has been to set up some form of off site backup for my dads business. He has a relatively small set of data (total less than 2gb) that is not going to change a huge amount but it is going to continue to grow over time. Previously dad had been cutting backups to DVDs every night, but as well as being wasteful by generating large numbers of half full DVDs it was slow and required somebody to remember to put a fresh disk in the drive at the end of every day.

Dad has a couple of different machines that need backing up,

  • A ancient Novell 4.x machine running some legacy software
  • A new Windows 2008 Server running a database
  • A small Ubuntu Linux box acting as NAT gateway and mail server

So the plan was to come up with something that would meet the following criteria

  • Automatic
  • Simple
  • Support very varied sources

I looked at a couple of the companies offering hosted backup online but decided to roll my own due to not wanting to have to worry about a monthly bill and knowing that if something went wrong and the backup was actually needed then it would be quicker to be able to carry whatever held the back up to the office and restore from that rather than to wait for it all to download again.

Since there was such a big difference in the type of machine that needed backing up and that the Novell stuff is so out of date that nobody was likely to support it any more I decided the best bet was to mount the bits that needed backing up from the Windows and Novell machines on the Linux box and then back it up from there. Accessing the Windows share from was easy enough using samba and the CIFS filesystem mount options. Getting at the Novell mount was a little harder.

The old NetWare Novell server doesn’t talk IP like everything else on the network, it uses IPX instead. So the first task was to configure the Linux machine to join the IPX network. Detailed instructions for setting up IPX can be found here, but the basics are assuming your Linux distribution has IPX compiled in you should be able to just run the following command as root.

ipx_configure --auto_interface=on --auto_primary=on

Once the network is up and running the next job was to mount the share, for this I needed the NCPFS package. This package is very similar to Samba and allows you to search for and mount Novell NetWare shares. There are 2 useful commands, the first is slist which will list all the Novell servers that can be seen on the network. The second is ncpmount which will mount the share.

ncpmount -S <server> <mount point> -U <Novell user>

Now I had access to all the data I needed somewhere to send it. While dad has a desktop and a laptop at home neither is on all the time or have large amounts of spare disk space, so I needed to find something to store the backups on. I was looking for a low power NAS with rsync support. I had a hunt round and found several, but most of them where big multi disk systems intended for mid sized office use and cost several hundred pounds. A bit more searching turned up the Buffalo LinkStation Live 500GB, which is basically a 500gb disk with a mini ARM based Linux machine strapped to the side. There is a reasonable sized community online hacking these little boxes to do all sorts and there are detailed instructions on how to enable telnet and SSH access which in turn can allow rsync to be used. Peek power draw is about 20W and significantly less when idle so it’s not going to cost much to run.

So I had send dad off to order one of these LinikStations and it was waiting for me when I got home. I initially started off following this set of instructions but had no joy. It turns out with the latest version of the firmware (1.24 at time of writing) the APC commander application no longer works. I started to search round some of the forums and came up with this new set of instructions on how to patch the firmware to add SSH and allow console access. The instructions are good, but it still took 2 attempts to get the firmware to upload, but once it did it all worked like a dream.

At this point I had access to all the data that needed backing up on the Linux box at the office and the LinkStation was ready to go at home, it was time to set up a way to get the data from one to the other. Rsync is perfect for this as it allows you to only copy the differences between 2 directories, these directories don’t even have to be on the same machine and all the communication can be tunnelled over SSH. The basic starting point for rsync over SSH is:

rsync -az -e ssh /path/to/src user@machine:/path/to/destination

Lets just step through the options being used here.

  • -a – This tells rsync to “archive” the src directory, this basically means conserve all the file access permissions, timestamps, symlinks and recurse into directories
  • -z – This tells rsync to compress all the data passed back and forth to save bandwidth
  • -e ssh – This tells rysnc to use ssh to connect to the target machine

That’s ok to start with as it will copy anything new in the source directory to the destination directory but it will not delete things from the destination if they disappear from the source directory, this is fine for this situation since dad is not likely to be deleting anything on the src side. So I wrapped it up in a script to run as a cron job after everybody should have gone home for the night


rsync -az -e ssh $SRC $USER@$SERVER:$DST

The following line in the crontab runs the backup at 5 past midnight on Tuesday through Saturday so to pick up the changes for the working days.

5 0 * * 2-6 /usr/local/backup

At the moment every time the script runs it will ask for the password for the SSH connection to the Linkstation at home. To get round this I set up an SSH key. There are lots of examples for creating SSH keys and using online so I’ll skip past that now.

So that is nearly that, except having set this all up I started to think about how to recover should a problem happen. What happens if a important file gets trashed at some point and nobody notices for a day or two. If the current script is running every day at midnight then the safe copy of the trashed file will get overwritten as soon as the script runs on the day it was damaged. To get round this I needed some sort of rolling incremental backup. Luckily rsync has this support as well and there is an example on the rsync page of how to set it up. I’ve modified it a little bit to give me this:

INCDIR=`date --date=yesterday +%A`
OPTS="--backup --backup-dir=$DSTDIR/$INCDIR -az -e ssh"

# the following line clears the last weeks incremental directory
rsync --delete -a $HOME/emptydir/ $USER@$SERVER:/$DSTDIR/$INCDIR/
rmdir $HOME/emptydir


This will create a directory called “current” which will hold the most up to date version backed up, it will also create 7 other directories named after the day of the week holding the previous version of any files that changed that day. This should allow any changes in the last week to be reverted.

In order to prevent having to copy all the initial 2gb over the dads broadband I took the LinkStation to the office and set it up on the local network then ran the backup script just with the local IP address rather than the SERVER entry.

For the normal operations I also had to set up dads router at home to assign the LinkStation a static IP address and forward port 22 to it so it was visible to the outside world.

Using Emprex 3009URF III Vista MCE Remote with MythTV



  • The Big Green Start Button
  • Teletex
  • Red, Green, Yellow & Blue

Kernel work



# yumdownloader kernel
# rpm -ivh kernel-








ApplyPatch hdpvr-ir-enable.patch
ApplyPatch hid-ignore-all-recent-imon-devices.patch

# Add kernel KSM support
ApplyPatch linux-2.6-ksm.patch
ApplyPatch linux-2.6-ksm-updates.patch


# rpmbuild -bb SPECS/kernel.spec


# yum erase kernel-
# yum --nogpgcheck localinstall RPMS/kernel-



<deviceinfo version="0.2">


U: Uniq=
H: Handlers=kbd event7
B: EV=1f
B: REL=40
B: ABS=1 0
B: MSC=10


Udevadm info starts with the device specified by the devpath and then
found, all possible attributes in the udev rules key format.
and the attributes from one single parent device.








# Play
prog = mythtv
button = KEY_PLAY
config = Return

# Stop
prog = mythtv
button = KEY_STOPCD
config = I

# Escape/Exit/Back
prog = mythtv
button = KEY_BACK
config = Esc
prog = xine
button = KEY_PLAY
repeat = 3
config = Play

prog = xine
button = KEY_STOPCD
repeat = 3
config = Stop

prog = xine
button = KEY_BACK
repeat = 3
config = Quit

Now we are all good to go.


A different kind of TV remote control

This was originally posted to the eightbar blog back in June 2009.

I got a new TV around Christmas last year and while unpacking it I noticed along with the HDMI, SCART and other sockets on the back it had a 9-pin socket labelled “RS232C IN CONTROL&SERVICE”. I didn’t think that much of it at the time, but I remembered it last week while thinking about a couple of problems that had come up.




The protocol is relatively simple

[cmd1][cmd2] [setid] [data]


The response from the TV looks like this for a success

[cmd2] [setid] OK[data]x

and like this for a failure

[cmd2] [setid] NG[data]x

The command to turn the TV on and off is “ka” so sending

ka 00 1

turns the TV on and sending

ka 00 0


ka 00 ff

gets the following when the TV is off

a 00 OK0x



How to get personal CCTV MMS’d to your phone

I left the setup in the last post with a system that would email photos of the burgular off site and then an SMS message. This is a prety good solution but since nearly everybody has a phone capable of receiving picture messages it seamed like the next step is to not just email the photos off site, but to also send them as a picture message so they can be checked for false alarms even when I’m not at my computer.

I went back to searching the net for a package that would supply MMS capability using a cell phone attached to a computer, not a direct connection to a bulk messaging provider. There is project called Mbuni that is a fully functional MMS gateway and relaying service as run by the cell phone providers. Normally this would run on the providers network and or at a company providing paid for content via MMS. Hidden away in the CVS for the latest version there is a add on to one of the components which will allow the sending of MMS messages via a phone.


In the last post I had discounted Kannel for sending SMS messages because of the complexity. But Mbuni prereqs it so it was time to have another look at the setup. Mbuni also request a specific level of Kannel (CVS 2008-07-28 download) so because I was planning on using some very new function in Mbuni I decided to build this Kannel version from source to make sure it all matched up.

tar -zxf kannel-snapshot.tar.gz
cd kannel-snapshot
su -c "make install"

Kannel is made up of a number of separate programs that provide different bits of functionality

  • bearerbox
  • smsbox
  • wapbox

In order to be able to send and receive SMS messages we are going to need the frist two on the list. Wapbox is only used if you want to provide a dial up WAPgateway.

Setting up Kannel is not hard, the docs are very good and can be found here and there is a copy of my config files as a guide in the resources section


There is some good documentation for setting up the full MMS gateway version of Mbuni, but because the cell phone plugin is stil only in the development stream there is only a small sample config file and the source code. I have tried to document what I have learned setting it up here.

Since this is a bleeding edge function you will need to build Mbuni from the src in cvs. There are instructions on how to do this on the web site here, but here is a short version

cvs login
cvs -z3 co -P
cd mbuni
cd extras/mmsbox-mm1
cd ../..
su -c "make install"

The change of directory to the extras/mmsbox-mm1 is to build the extra library needed to work with the phone. If you are running on a machine that has SELINUX enabled you will need to run the following command to allow the library to work

su -c "chcon -t texrel_shlib_t /usr/local/lib/"

Like Kannel, Mbuni is made up of a collection of applications

  • mmsc
  • mmsproxy
  • mmsrelay
  • mmsbox

To send MMS messages via a phone we only need mmsbox which is what is known as a VAS gateway. So we need to create a Mbuni config file, there is a sample file shipped with the src in the doc/examples directory. Here is my version modified to work with O2 UKs MMS service

group = core
log-file = /var/log/kannel/mmsbox.log
access-log = /var/log/kannel/mmsbox-access.log
log-level = 0

group = mbuni
storage-directory = /usr/local/var/spool/mbuni
max-send-threads = 5
maximum-send-attempts = 50
default-message-expiry = 360000
queue-run-interval = 5
send-attempt-back-off = 300
sendmms-port = 10001
sendsms-url = http://localhost:13013/cgi-bin/sendsms
sendsms-username = tester
sendsms-password = foobar

# Sample conf for MMSBox using a modem (MM1)
group = mmsc
id = modem
type = custom
custom-settings = "smsc-on=lynx -dump 'http://localhost:13000/start-smsc?
 smsc-off=lynx -dump 'http://localhost:13000/stop-smsc?password=bar&smsc=w880i'; 
 gprs-on=/usr/bin/pon o2; 
 gprs-pid=cat /var/run/ | head -1;port=13014;
mmsc-library = /usr/local/lib/

group = send-mms-user
username = tester
password = foobar
faked-sender = 100

The interesting bits are the sendsms-url and the custom-settings lines. The sendsms-url points to the bearerbox/smsbox URL from setting up Kannel earlier which Mbuni uses to send the notification about the new mail.

The custom-settings line is a lot more complicated, it is basically a mini config file all of it’s own. The two entries that start with smsc-on and smsc-off are commands that the custom library built earlier uses to stop and start the sms gateway while the MMS message is sent. gprs-on is used to start a PPP session via the phone. This can be either gprs or 3G. The code implies that this command should not return until it’s killed at shutdown, but using /usr/bin/pon on Ubuntu seams to work.

The next few bits depend on which cell phone provider your using. The mmsc-url and proxy are the addresses for the machines on their network you need to use to
send MMS messages. I found the following page has a good list of the settings for UK provider


So now we’ve got the set up working we need some content to send. MMS messages are defined using SMIL markup. The following is the simple SMIL file I am using to send a short video clip and text caption. The first half divides the display in half, with the video in the top half and the text in the lower. The second section contains the details of the links to where Mbuni can find the content to
fill those areas and how long to display them. This is a very simple example, much more complex messages can be assembled with

         <root-layout />
         <region id="Image" top="0" left="0" height="50%" width="100%" fit="hidden" />

         <region id="Text" top="50%" left="0" height="50%" width="100%" fit="hidden" />
      <par dur="5000ms">
         <video src="http://tiefighter.loc/cam1/intruder.3gp" region="Image"></

         <text src="http://tiefighter.loc/cam1/message.txt" region="Text"></text>


So far we have been just sending static images, next comes converting the avis created by Motion to mpeg4 in a 3gp container that should be playable on any MMS capable phones. The following ffmpeg command will convert the file to the right format.

ffmpeg -i 07-20090916100019.avi -s qcif -vcodec h263 -y intruder.3gp

Where “-i 07-20090916100019.avi” is the file created by motion, “-s qcif” tells ffmpeg to use an output file that is 176×144 and conforms to a standard that all phones should understand, “-vcodec h263” is the video codec to use. “-y intruder.3gp” tells ffmpeg to overwrite the file if it already exists.

Here is an example of the Motion output.

After transformation:

When viewed on a 2 inch screen the drop in quality is not noticeable and it is still possible to tell if it is somebody you know.

Actually sending the MMS

So now we have actually created the content for the MMS message we need to put it somewhere mbuni can find it. In this case I put the video and text files into the /cam1 directory being server up by http server. The URLs match the entries in the SMIL file created earlier.

Now we need to send the SMIL file to Mbuni along with the phone number to send it to. The following curl command will send the SMIL file and the rest of it.

curl  --data "username=tester&password=foobar&to=07703xxxxxx&subject=Possible+Intruder&from=07543xxxxxx" --data-urlencode "smil@/var/www/html/cam1/intruder.smil"  http://x-wing.loc:1000

In this case Mbuni is running on the a machine called x-wing and listening on port 10001 (as set with the sendmms-port in the config above). The frist half is the urlencoded version of the username, password, the senders and recipients numbers and the subject of the message. The second section, after the –data-urlencode loads the SMIL file and encodes it before sending it.

Putting it together

Now we need a to collect all of this up in a scrip to attach to the movie end action of motion. The following script first helps to prevent false alarms by ensuring that any video has at least 15 frames. Assuming that test is satisfied the orginal version of the video is emailed offsite for safe keeping, before converting the it to the 3gp format. It then adds the time and date to the message.txt before sending the SMIL to Mbuni.


FRAME_COUNT=`/home/hardillb/bin/frameCounter $1`

if [ $FRAME_COUNT -gt 14 ]; then

    uuenview -a -m $1 <<EOF
Subject: Movement detected video $2 $3


    /home/hardillb/bin/sendMessage SMS/Outbound "TO: +447703xxxxxx MESSAGE: possible intruder"

    ffmpeg -i $1 -s qcif -vcodec h263 -y /var/www/html/cam1/intruder.3gp

    echo "$2 $3" > /var/www/html/cam1/message.txt


The frameCounter was a script I had run up earlier for a different project, made sense to reuse it here.

mplayer -v $1 -nosound -vo null -frames 0 2> /dev/null | grep "frames  t" | awk ' { print $3 } '

So that’s about it, I have a motion activated CCTV system that will log off site and send alerts to me anywhere in the world with enough detail to decided if it’s a false alarm


How to get a Txt Msg from your burglar


Image CC licensed by Dr_John2005 on Flickr









uuenview -a -m $1 << EOF
Subject: Possible Intruder $2 $3






Image CC licensed by Eerko on Flickr




I added a new script to the “on_movie_end” Motion trigger


There is a sample Gnokii config file in the Resources section

Anybody Home?







while true; do
    echo "home"
      echo YES > /home/user/home
     lwp-request -C user:password > /dev/null
     sleep 90
    echo "away"
      echo NO > /home/user/home
    lwp-request -C user:password > /dev/null
    sleep 15


