Category: Tech stuff

  • Backing up MySQL to a remote site

    I now run two webservers in different locations. The basic platform is Apache with Joomla on top for a CMS and a splattering of wordpress and roundcube for good measure. I needed to do a couple of things though – backup the databases to another location and ensure static image content was mirrored between the two sites. I didn’t want to necessarily keep the MySQL servers in sync so much as have a backup of the CMS content. I intend to import old databse copies as and when I need to. Here is how I did it:

    (replace theuser with the real username, thepassword with the real password and x.x.x.x with your real destination FTP server).

    lftp -c ‘open -e “mirror /otndocs/images/ /var/www/otndocs/images/” -d -u theuser, thepassword X.X.X.X‘

    lftp -c ‘open -e “mirror /otndocs/templates/rhuk_milkyway/ /var/www/otndocs/ templates/rhuk_milkyway/” -d -u theuser,thepassword X.X.X.X‘

    The above script uses lftp to mirror two directories. The different paths reflect how the target FTP server holds content in different folders to the source webserver. I have to be picky wth what I transfer because the target server is a WindowsXP machine and the source runs Ubuntu Server. If both machines matched paths and underlying O/S, you should pretty much be able to just dump the whole server over. That is a bit risky as you will carry any malicious code over as well. I stuck with just images for the moment, though the second line shows how to copy a specific template as well.

    Here is the script to backup the mySQL database. It dumps, gzips and uploads the files one by one in a target folder with today’s date on it. I’ve added my crontab entry at the end to show how you could, like me schedule it to run at 3am for example. Again, replace the bits in blue with your usernames etc.

    #!/bin/sh
    
    # List all of the MySQL databases that you want to backup in here,
    
    # each separated by a space
    
    databases="mysql otndata wordpress"
    # Directory where you want the backup files to be placed
    
    backupdir=/backup
    
    # MySQL dump command, use the full path name here
    mysqldumpcmd=/usr/bin/mysqldump
    
    # MySQL Username and password
    userpassword=" --user=themysqluser --password=themysqlpassword"
    
    # MySQL dump options
    dumpoptions=" --quick --add-drop-table --add-locks --extended-insert --lock-tables"
    
    # Unix Commands
    gzip=/bin/gzip
    uuencode=/usr/bin/uuencode
    mail=/bin/mail
    
    # Send Backup?  Would you like the backup emailed to you?
    # Set to "y" if you do
    sendbackup="n"
    subject="Your MySQL Backup"
    mailto="person@mailbox.org"
    
    # Create our backup directory if not already there
    mkdir -p ${backupdir}
    if [ ! -d ${backupdir} ]
    then
    echo "Not a directory: ${backupdir}"
    exit 1
    fi
    
    # Dump all of our databases
    echo "Dumping MySQL Databases"
    for database in $databases
    do
    $mysqldumpcmd $userpassword $dumpoptions $database > ${backupdir}/${database}.sql
    done
    
    # Compress all of our backup files
    echo "Compressing Dump Files"
    for database in $databases
    do
    rm -f ${backupdir}/${database}.sql.gz
    $gzip ${backupdir}/${database}.sql
    done
    
    # Send the backups via email
    if [ $sendbackup = "y" ]
    then
    for database in $databases
    do
    $uuencode ${backupdir}/${database}.sql.gz > ${backupdir}/${database}.sql.gz.uu
    $mail -s "$subject : $database" $mailto < ${backupdir}/${database}.sql.gz.uu
    done
    fi
    
    # And we're done
    ls -l ${backupdir}
    echo "Dump Complete!"
    
    HOST='X.X.X.X'
    USER='theuser'
    PASSWD='thepassword'
    DATE=$(date +%d%m%y)
    
    #Our local directory containing files to FTP
    cd ${backupdir}
    
    # Process each file in directory, ftping each one
    
    for filename in ${backupdir}/*; do
    fn=$(basename "$filename")
    echo "$fn"
    
    ftp -n -v <<-EOF
    open ${HOST}
    user ${USER} ${PASSWD}
    cd /
    mkdir $DATE
    cd $DATE
    pwd
    put $fn
    bye
    EOF
    echo "FTP upload attempt for $fn complete"
    
    done
    
    echo "FTP complete!"
    exit

    type crontab-e to add your scripts to the schedule:

    0 3 * * * /home/simkin/backup-databases
  • Nokia N95 Sportstracker, Google Latitude & ASDA mobile settings

    I like sportstracker. It lets me record by cycle journeys whilst I’m doing them and review my performance or plan the route of my next ride. That’s the theory. In practice, sportstrack captures between 5 to 8 miles and crashes. Today I did 31miles. Sportstracker has a record of the first 5 and the last 15 because I checked it and restarted my phone. It doesn’t just crash the app or reset the phone, it turns the darn thing off. Not ideal.

    One other oddity is that it feels I did a maximum speed of 45.9miles per hour. I was on a bicycle. BICYCLE! My odometer says my max was 31mph which is more believable (there were not any long descents).

    I’m thinking of getting a handlebar mount so I can see when it does crash so I can park up and reset it. I’ll also consider doing a complete reset and rebuild of the phone application load before I next go on a long ride as that may help.

    Google Latitude works well on the N95 by the way. It means loading Google maps when Nokia maps are already loaded. Nokia maps are on the memory card and not downloaded over the wire which is handy when abroad. Google maps and Latitude just go that little bit further and I find it easier to use. Keeping track of my phone’s location over the web is also a neat trick. So I’m keeping them both for now…

    I struggled when I put the ASDA SIM into the N95 beacuse my poor little brain could not convert ASDA settings-speak inot Nokia-speak. Eventually I got there. Here for those that need it are the ASDA settings in Nokia speak:

    ASDA mobile web
    Tools > Settings > Connection > Access Points
    Connection name: ASDA mobile web
    Data bearer: packet data
    Access point name: asdamobiles.co.uk
    user name: web
    prompt password: no
    password: web
    Authenication: normal
    Homepage: http://www.asda-mobile.com/wap
    Options > Advanced settings:
    Network Type: IPv4
    Phone IP address: Automatic
    DNS address: Automatic
    Proxy server address: none
    Proxy port number: 0

    ASDA mobile wap
    Tools > Settings > Connection > Access Points
    Connection name: ASDA mobile wap
    Data bearer: packet data
    Access point name: asdamobiles.co.uk
    user name: web
    prompt password: no
    password: web
    Authenication: normal
    Homepage: http://www.asda-mobile.com/wap
    Options > Advanced settings:
    Network Type: IPv4
    Phone IP address: Automatic
    DNS address: Automatic
    Proxy server address: 212.183.137.12
    Proxy port number: 8799

    ASDA mms
    Tools > Settings > Connection > Access Points
    Connection name: ASDA MMS
    Data bearer: packet data
    Access point name: asdamobiles.co.uk
    user name: wap
    prompt password: no
    password: wap
    Authenication: normal
    Homepage: http://www.asdamobiles.co.uk/servlets/mms
    Options > Advanced settings:
    Network Type: IPv4
    Phone IP address: Automatic
    DNS address: Automatic
    Proxy server address: 212.183.137.12
    Proxy port number: 8799

    Now go to:
    Tools > Settings > Connection > Packet Data
    Packet data connection: when needed
    Access point: ASDA mobile

    Now go to:
    Home > Messaging > Settings > Multimedia Message
    Access point in use: ASDA mms

    Another tip: How to change the shortcut menu icons on the start screen:
    Tools > Settings > General > Personalisation > Standby mode > Active Standby Apps

    I’ve just changed mine to: Phone book, Messaging, Web, Sportstracker, Google maps, Music player

  • Nokia N95 Sportstracker, Google Latitude & ASDA mobile settings

    I like sportstracker. It lets me record by cycle journeys whilst I’m doing them and review my performance or plan the route of my next ride. That’s the theory. In practice, sportstrack captures between 5 to 8 miles and crashes. Today I did 31miles. Sportstracker has a record of the first 5 and the last 15 because I checked it and restarted my phone. It doesn’t just crash the app or reset the phone, it turns the darn thing off. Not ideal.
    One other oddity is that it feels I did a maximum speed of 45.9miles per hour. I was on a bicycle. BICYCLE! My odometer says my max was 31mph which is more believable (there were not any long descents).
    I’m thinking of getting a handlebar mount so I can see when it does crash so I can park up and reset it. I’ll also consider doing a complete reset and rebuild of the phone application load before I next go on a long ride as that may help.
    Google Latitude works well on the N95 by the way. It means loading Google maps when Nokia maps are already loaded. Nokia maps are on the memory card and not downloaded over the wire which is handy when abroad. Google maps and Latitude just go that little bit further and I find it easier to use. Keeping track of my phone’s location over the web is also a neat trick. So I’m keeping them both for now…
    I struggled when I put the ASDA SIM into the N95 beacuse my poor little brain could not convert ASDA settings-speak inot Nokia-speak. Eventually I got there. Here for those that need it are the ASDA settings in Nokia speak:
    ASDA mobile web
    Tools > Settings > Connection > Access Points
    Connection name: ASDA mobile web
    Data bearer: packet data
    Access point name: asdamobiles.co.uk
    user name: web
    prompt password: no
    password: web
    Authenication: normal
    Homepage: http://www.asda-mobile.com/wap
    Options > Advanced settings:
    Network Type: IPv4
    Phone IP address: Automatic
    DNS address: Automatic
    Proxy server address: none
    Proxy port number: 0
    ASDA mobile wap
    Tools > Settings > Connection > Access Points
    Connection name: ASDA mobile wap
    Data bearer: packet data
    Access point name: asdamobiles.co.uk
    user name: web
    prompt password: no
    password: web
    Authenication: normal
    Homepage: http://www.asda-mobile.com/wap
    Options > Advanced settings:
    Network Type: IPv4
    Phone IP address: Automatic
    DNS address: Automatic
    Proxy server address: 212.183.137.12
    Proxy port number: 8799
    ASDA mms
    Tools > Settings > Connection > Access Points
    Connection name: ASDA MMS
    Data bearer: packet data
    Access point name: asdamobiles.co.uk
    user name: wap
    prompt password: no
    password: wap
    Authenication: normal
    Homepage: http://www.asdamobiles.co.uk/servlets/mms
    Options > Advanced settings:
    Network Type: IPv4
    Phone IP address: Automatic
    DNS address: Automatic
    Proxy server address: 212.183.137.12
    Proxy port number: 8799
    Now go to:
    Tools > Settings > Connection > Packet Data
    Packet data connection: when needed
    Access point: ASDA mobile
    Now go to:
    Home > Messaging > Settings > Multimedia Message
    Access point in use: ASDA mms
    Another tip: How to change the shortcut menu icons on the start screen:
    Tools > Settings > General > Personalisation > Standby mode > Active Standby Apps
    I’ve just changed mine to: Phone book, Messaging, Web, Sportstracker, Google maps, Music player

  • Apache Virtual Hosts

    As well as a new postfix build, I obviously need a second webserver in case this one falls over. Best place for config help was here.

    Apache2 is really easy to configure now it is split into differnet conf files but you need to follow the method outlined in that tutorial or like me you will unravel it all.

  • Postfix Store-and-forward

    After having a little outage due my my ADSL router deciding to take a couple of hours off, I decided I really really really did need to sort out a secondary MX. I have a little Ubuntu server in a rack offsite that I toyed with for a while but never seriously did anything with once I got distracted with other things.

    Now of course it is going to be my store-and-forward server for when my home mail server disappears off the big scary Internet. A Store-and-forward server is basically a mail server that relays mail for a certain list of known domains. It will also be prepared to hold mail in the queue for a few days until the primary is back to life.

    The best description and config help I found was here. Well worth a look if you want to do this kind of thing yourself for free on old hardware for when that expensive Exchange mail server (or in my case cheap Mercury server) decides it doesn’t want to play any more.

    Postfix is currently not being too helpful and I’m going to rip-and-replace it. It should be a simple config but I couldn’t help trying to refine it. Oops. It also doesn’t help that I seem to fallen foul of the “smtp fixup” provided by the over-eager Cisco ASA sitting in front of it.

    Another good site for novice Postfix admins is here. It lists a verbose config with lots of good little security-conscious snippets.

    One way to achieve a store-and-forward server is to use Postfix aliases. An Alias file will allow your server to be the server listed as the MX in your domain zone file but then incoming mail is redirected to a server with a real mailbox. Here is an extract from my main.cf to show you how I did it:

    # Do not relay anything  
    #relay_domains = $mydestination
    #relay_recipient_maps = hash:/etc/postfix/relay_recipients
    
    # Aliases is what we want to do
    alias_maps = hash:/etc/aliases
    
    # start virtual domains section, list all the domains we receive email for and the file containing the mappings
    virtual_alias_domains = simkin.org, orangeteapot.co.uk
    virtual_alias_maps = hash:/etc/postfix/virtual
    
    # security fixes
    disable_vrfy_command = yes
    smtpd_helo_required = yes
    allow_percent_hack = no
    swap_bangpath = no
    smtpd_sasl_authenticated_header = yes
    smtpd_helo_restrictions = reject_unknown_helo_hostname
    smtpd_client_restrictions = permit_mynetworks,
                                reject_rbl_client zen.spamhaus.org,
                                reject_invalid_hostname,
                                warn_if_reject,
                                reject_unknown_reverse_client_hostname,
                                reject_non_fqdn_helo_hostname,
                                reject_unauth_pipelining,
                                reject_invalid_helo_hostname,
                                permit
    
    smtpd_recipient_restrictions = permit_mynetworks,
                                   check_client_access cidr:/etc/postfix/client_checks,
                                    permit_sasl_authenticated,
                                    reject_unauth_destination,
    
    smtpd_sender_restrictions = reject_unknown_sender_domain
    smtpd_data_restrictions = reject_unauth_pipelining
    # end security fixes
    
    mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
    mailbox_command = procmail -a "$EXTENSION"
    mailbox_size_limit = 0
    recipient_delimiter = +

    For the “Client Checks” section, see this post.

    Then build your alias table to pass incoming mail to a particular email address to go to wherever you want.

     nobody@simkin.org    myrealmailbox@gmail.com

    Save the file to /etc/postfix/virtual and run

    postmap virtual
    /etc/init.d/postfix reload
  • Serving up virtuals ?

    So I have me ESX server and a nice shiny Ubuntu VM but really need to shift my current XP “server” onto it too. VMWare Converter fails trying to copy the volue after about half an hour. I’m just going to build me a new one.

    I hate the fact that XP doesn’t have the SCSI drivers I need so I decided to slipstream:

    1.) copy XP CD_ROM to a folder

    2.) Use MagicISO or ISO Buster to extract the bootable section (Microsoft Corporation.img)

    3.) Download SP3 (WindowsXP-KB936929-SP3-x86-ENU.exe)

    4.) Download nLite

    5.) Download the VMWare Buslogic FLP

    6.) USe MagcISO to extract the FLP into a folder

    7.) Run nLite to slipstream SP3 and the drivers into the XP folder

    8.) Use Nero to burn a new bootable ISO image

    Note: Nero Settings are quite particular and the “Expert Settings” seem to drop off the radar so make sure you check the tick-box is ticked very last thing before clicking BURN.If it unticks it self you will get “cannot boot from cd code 4” when you try and boot the disk.

    Settings available here (http://www.pcstats.com/articleview.cfm?articleid=1626&page=4)

    Quite a bit of fiddling around but worth it to get a one-shot, unattended XP installer. (Insert manic laughter here)

  • Startup Program Troubleshooting

    So you have a very very slow computer that is flagging up messages about viruses and how to make it run faster? You may well have something nasty on there. But how do you find out what is running at startup and how do you prevent them from doing that?

     

    (more…)

  • Recovering Windows XP

    After receiving a plea for help from a good friend whom due to a mishap with a Windows update and a kitten called “Marmite” had a broken Windows XP system, I thought I’d better let you know how to use the Recovery Console to get hold of your old Restore Points.

    (more…)

  • OpenVPN – The VPN for everyone

    For various reasons I decided to finally sort out a secure VPN connection back to my home network. I am lucky to own a Sonicwall Pro 200 firewall with an unlimited VPN licence. Trouble is that Sonicwall made the client software End of Life and I need to buy their newer one. Don’t fancy that.

    So let’s go visit the bast treasure trove that is Open Source. Hey presto – OpenVPN. An SSL-based VPN solution which is more flexible, easier to configure and free.

    There is a great getting started guide here.  I basically downloaded the “Windows GUI” version, created some certificates and wrote my own server.ovpn config file. After ensuring my Sonicwall let the relevant port through and that my DNS names were all correct (I wanted a specific name for the VPN server) I went into work and tried it out.

    The client needs a slightly different .ovpn file and a copy of the relevant certificates (ca.crt and the one generated for that particular client). I kept the same file structure as for the server to make my life easier:

    C:\Program Files\OpenVPN\easy-rsa\keys
    ca.crt
    clientx.key
    clientx.crt
    C:\Program Files\OpenVPN\config
    clientx.ovpn

    Everything went fine except I cannot see the LAN, only the server. A bit more reading and it looks like it may be the Windows firewall running on the server. Soon fixed that. Will go into work tomorrow and try again.

    The GUI works well and whilst it isn’t as polished as say, the Cisco VPN client, it works and it works well. I certainly recommend it for home users and admins. Possibly not quite ready for mainstream deployment for novice users. I’ll try it out on my wife though and see how she gets on. She is used to me by now.

  • Adventures in Media Centre

    So I now have the MC bug and have decided that my Media Centre PC will:

    • Act as an interface for the boys computer games
    • Play DVDs with full Dolby DTS surround sound
    • Record TV shows off of the Sky Box for shipping onto DVD
    • Allow me to build a DVD library to save digging out the Disc every time the boys want to watch a movie

    Launching games

    The first one was a bit tricky but thanks to this link, and a copy of gameloader.exe I managed to solve it. Basically the “Program Library” within MC can be used to launch almost anything as follows:

    1. Create a folder called c:\MC_Launch for example
    2. create a shortcut to Gameloader.exe “mygame.exe” for the EXE of the game and call it MyGame.lnk
    3. create a MyGame.png image for MC to use
    4. create MyGame.mcl in notepad with the following content:

    <application
    name = “My Game”
    ID = “”
    Run = “.\Launch.lnk”
    BGColor = “RGB(0,0,0)”
    CompanyName = “.”
    StartImage = “MyGame.png”
    ThumbnailImage = “MyGame.png”
    SharedViewport = “”
    NowPlayingDirective = “”>
    <capabilitiesrequired
    directx=”True”
    audio=”False”
    video=”False”
    intensiverendering=”True”
    console=”False”
    cdburning=”False” />
    </application>

    5. Now copy the MCL into “Programs\Media CEnter\Media Center Programs” in the Start Menu

    Play DVDs with DTS

    Easy really. Just plugged the SPDIF co-ax into my Logitech z55000 and trawled through the advanced audio driver settings until I found the DTS tick box. Works a treat. Might need to play with Nero Drive speed as sometimes the disc runs a litle noisy but otherwise it is all good.

    Record TV Shows

    My Hauppauge HVR card has a composite feed from the back of the Sky box and the Sky box phono outputs provide sound. Only stereo of course but I’m only recording TV programmes not movies so that isn’t really a problem. For DVD-quality sound, I’ll buy the DVDs. Another reason not to get pirate copies if you ask me…

    DVD Library

    Possibly the most tricky. But here is what I ended up with.

    1. Use RipIt4Me to build a sectors list for DVDecrypter and force the VOB to the root menu.
    2. Save the resultant VIDEO_TS folder onto my Thecus NAS box
    3. Load-up MyMovies under MC and point it at this folder.
    4. The Movie appears with full artwork in MC and can be played without needing to insert the DVD

    For the record, I buy legal, genuine DVDs and have them on the shelf. I only have the NAS open on my LAN and only the MC box runs MyMovies to be able to pick the movies out and play them.

    I could go one stage further and rip only the main title using VOB2MPG but then my movies are listed as “Videos” and I don’t get the extras menus. I’m happy to sacrifice some disc space to ge the full DVD experience.

    For extra tips and advice, the Australian Media Centre Forum is worth a trawl….