Skip to content

Blog

It’s here!!

My amazing web server backup script

For my own server setup on my machine, I’ve just finished a better version of my automated backup script.

It backs up everything in the Apache document root, all my virtual hosts directories and also does a MySQL dump, before saving all three of those files (date in the filename) in a specified directory. But it gets better – it also copies the backups to another location (on a different physical disk) for redundancy. It also automatically prunes out old backups and deletes them (you set a specified number of backups that you want to keep in each folder).

It runs daily automatically via cron on my machine.

And I think it’s quite good and I thought it might come in handy as a base for someone else’s script.

#!/bin/bash

DATE1=`date | awk '{print $3}'`
DATE2=`date | awk '{print $2}'`
DATE3=`date | awk '{print $6}'`

THEDATE="${DATE1}${DATE2}${DATE3}"

########################### CONFIGURATION START ##################################

KEEPORIG=6			# how many backups to keep in original dir?
KEEPSECOND=30			# how many backups to keep in second dir?

KEEPSQLORIG=15			# how many MySQL dumps to keep in original dir?
KEEPSQLSECOND=50		# how many MySQL dumps to keep in second dir?

ORIGDIR="/root/Backups/apache"	# original directory to put backups
SECONDDIR="/secondplace/"	# secondary directory to copy backups
APACHEDIR="/var/www/html"	# apache docroot
VHOSTSDIR="/var/www/vhosts"	# apache virtual hosts directory

MYSQLUSER=root			# MySQL user for dump
MYSQLPASS=password		# MySQL password for dump

########################### CONFIGURATION DONE ###################################

cd ${ORIGDIR} # chdir to the right dir
tar -cjvf "./Webdev_${THEDATE}.tar.bz2" ${APACHEDIR} # tar up apache dir
tar -cjvf "./Vhosts_${THEDATE}.tar.bz2" ${VHOSTSDIR} # tar up vhosts dir

mysqldump -u ${MYSQLUSER} -p${MYSQLPASS} -A > "./MySQL_${THEDATE}.sql" # dump db
bzip2 "./MySQL_${THEDATE}.sql" # compress db

cp -v "./Webdev_${THEDATE}.tar.bz2" ${SECONDDIR} # copy
cp -v "./Vhosts_${THEDATE}.tar.bz2" ${SECONDDIR} # copy
cp -v "./MySQL_${THEDATE}.sql.bz2" ${SECONDDIR} # copy

# prune .tar.bz2 in original folder
if [ `ls -1 "${ORIGDIR}" | grep .tar.bz2 | wc -l` -gt $KEEPORIG ]; then
   i=1
   for each in `ls -1t "${ORIGDIR}" | grep .tar.bz2`; do
       if [ $i -gt $KEEPORIG ]; then
           echo Removing "${ORIGDIR}/${each}"
           rm -fv -- "${ORIGDIR}/${each}"
       fi
       let "i = i + 1"
   done
fi

# prune .tar.bz2 in second folder
if [ `ls -1 ${SECONDDIR} | grep .tar.bz2 | wc -l` -gt $KEEPSECOND ]; then
   i=1
   for each in `ls -1t "${SECONDDIR}"`; do
       if [ $i -gt $KEEPSECOND ]; then
           echo Removing "${SECONDDIR}/${each}"
           rm -fv -- "${SECONDDIR}/${each}"
       fi
       let "i = i + 1"
   done
fi

# prune db dumps in original folder
if [ `ls -1 "${ORIGDIR}" | grep .sql.bz2 | wc -l` -gt $KEEPSQLORIG ]; then
   i=1
   for each in `ls -1t "${ORIGDIR}" | grep .sql.bz2`; do
       if [ $i -gt $KEEPSQLORIG ]; then
           echo Removing "${ORIGDIR}/${each}"
           rm -fv -- "${ORIGDIR}/${each}"
       fi
       let "i = i + 1"
   done
fi

# prune db dumps in second folder
if [ `ls -1 "${SECONDDIR}" | grep .sql.bz2 | wc -l` -gt $KEEPSQLSECOND ]; then
   i=1
   for each in `ls -1t "${SECONDDIR}" | grep .sql.bz2`; do
       if [ $i -gt $KEEPSQLSECOND ]; then
           echo Removing "${SECONDDIR}/${each}"
           rm -fv -- "${SECONDDIR}/${each}"
       fi
       let "i = i + 1"
   done
fi

You can also download it here, I don’t know how reliable the copy/paste will be.

Full steam ahead on the MS FUD machine

This OSNews article.

Ballmer:

“The deal that we announced at the end of last year with Novell I consider to be very important. It demonstrated clearly the value of intellectual property even in the Open Source world. I would not anticipate that we make a huge additional revenue stream from our Novell deal, but I do think it clearly establishes that Open Source is not free and Open Source will have to respect intellectual property rights of others just as any other competitor will.”

Clearly, Microsoft are openly admitting here that they are unable to sell Microsoft products on their own merits, and so they have to bully people into thinking that choosing open source solutions is legally unsafe by firing random bursts of intellectual property violation bravado.

Here’s a challenge for you, Steve. Show me some infringing code. It’s all out there, in the open. Show me some infringing code and we’ll collectively sort it out.

Except that’s not the point. MS don’t want to actually start a patent war – I guess they know full well they have infringed more than a few of other people’s patents, so they don’t want to open a can of worms.

The game is FUD. Fear, uncertainty, doubt. Here’s how it goes.

  • Some open source solutions are better and cheaper than MS ones. Lots of people start investigating them to use instead of MS solutions.
  • MS notices this and invents some wonderful reason why open source is ‘unsafe’ legally.
  • MS spread the idea that “open source is unsafe”.
  • The people that were investigating the open source products hear MS’s idea, believe it, and go “we don’t want trouble with MS lawyers, we better not choose the open source product”.
  • These people go on to buy MS products.
  • MS get money and retain market share.

I don’t think they can play that game forever. At some point, they’re going to have to change their strategy.

It’s just a shame they have to resort to such childish methods to sell their products. Imagine what they could do if they put all their time, effort and money into making great products instead of bullying the world into rebuying their stuff.

“First they ignore you, then they laugh at you, then they fight you, then you win.”

A tip when writing massive WordPress posts

If you’re anything like me, when writing long WordPress posts, you constantly press Save and Continue Editing so you can see the preview which appears below the editing area in the WP dashboard. It’s really nice to be able to see what the post will really look like when done, but the frame it’s put in is a bit small.

If you want a full browser window sized preview, then (in Firefox) right-click inside the frame and do This Frame > Open Frame in New Tab. Now, everytime you click that button, you can head over to this tab and reload it for a real-sized preview of what your post is going to look like when done.

I find it useful, anyway…

Taking Ajax further with PHP

Peter's WebDev Workshop

Find this tutorial useful?





First of all, I have to apologise. It’s been literally two months since my last post in this series, and it’s been more than that since I last looked at Ajax in PHP. OK, I might admit it, it was this comment that motivated me to pick up this series again. Oh, that and I’m now on the half term break, so I’m finally getting round to some things that have been on the back burner for a long time.

In our last Ajax tutorial, we got started with Ajax using PHP and made our first Ajax application.

Today, we’re going to take Ajax a little further, by building a little application where our user selects a product from a pop-up list, and then we do a little Ajax dance to get some product details (and an image) and display them in a box below. We’ll be making our own little XML schema which we’ll use to pass information between the JavaScript in the user’s browser and our PHP script on the server.

» Read the rest of this post…

This is why I love blogging

I just got a comment from someone called Jack (Dunford), on my last post. That’s not remarkable in itself – I get comments from people I don’t know fairly frequently.

Checking his blog, it looks like he also attended the West Quay Apple Store opening.

That’s a pretty unlikely coincidence, if you ask me. What’s even weirder though, is that he happened to take a photo of the queue, and I happened to be in that photo! Considering there were hundreds of people at the store opening, the likelihood of someone happening to have taken a picture with me in it is really really low.

That is one seriously weird coincidence. Weird, but cool.

Here’s the full photo, and I’ve cropped it a bit and pointed me out below.

Me at West Quay

There’s also a set of lots more photos from the opening here.

Really really strange coincidence.

Oh, and in response to the comment, the OLPC would be too low powered for my needs. Not quite a MacBook with my spec. 🙂 I want to see what they’re going to do with the interface though.

Dispatched

My MacBook apparently got dispatched today, one day ahead of the estimated time (yay!) and the shipping estimate is now the 23rd February.

With any luck, though, the shipping will be quicker than expected too, but I won’t get my hopes up.

In any case, my MacBook is now configured and on the way (expect a rush of posts once it’s here). 😀

When will they learn?

On BoingBoing:

Arnezami, a hacker on the Doom9 forum, has published a crack for extracting the “processing key” from a high-def DVD player. This key can be used to gain access to every single Blu-Ray and HD-DVD disc.

When will the recording/movie industries learn? Attempting to lock down consumers with ever more restrictive DRM is not going to work. Soon, we’ll get to a point where it’s easier to illegally acquire content than it is to purchase it, then jump through all the hoops to get it working legitimately (in fact, you could argue that we’ve already got there, with the whole ‘HD ready’ fiasco).

Sure, there are still practical issues with distributing 20 odd gigabytes of high definition movie, but it looks like AACS really was as completely rubbish as I thought it would be.

Clearly, DRM is flawed. The whole concept is. Good security algorithms are built on good mathematical foundations, then tested for years before they’re declared as secure. AACS simply didn’t have enough time to stand the test of time and get the heck pounded out of it, before it started being used.

DRM’s downfall is pretty much inevitable now, in my opinion. With Steve Jobs openly wanting it dead, it’s just a matter of when. And then everything will be great again. Oh, hang on, then there’s still Microsoft. Damn.

UPDATE: oooh, will this mean they’ll start revoking high-def players? Brilliant. Working one day, dead the next.

I bought a Mac

  • MacBook 13″ white
  • Intel Core 2 Duo 2.0 GHz
  • 2 GB RAM 😛
  • 120 GB HDD
  • And all of the other specs of the MacBook

It will take 3 business days to configure (that RAM upgrade and the HDD upgrade), then 3-7 days to ship.

And I can’t wait.

Just to clarify – this will not mean that I will stop using Linux (I certainly now don’t have the money to buy a new desktop anyway 😀 ). It’s not a ‘switch’ either, it’s expanding my horizons, being proficient in all three operating systems (not only does that look impressive on a CV, it’s fun too) and playing around with new stuff.

Expect a massive load of Mac-related blog posts coming as soon as it arrives (unboxing photos included hopefully) and then the platform balance will probably return to about 45%:45%:15% (Mac:Linux:Windows). Or something like that. 🙂

And I’ll try and get that Safari bug to reproduce. Plus there shouldn’t be future Safari bugs, as I’ll actually be able to test in it!

I can’t wait also to have a play around in Xcode and compare it to MS Visual Studio (the latter being a very good product, so I hope Xcode is mind-blowingly good 😀 ). In fact, I better shut up right now or I’ll be here all night explaining what I’m going to be doing. And annoy everyone.

West Quay Apple store

Just got back from Southampton (~30 miles away from where I live). The new Apple Store in the West Quay shopping centre opened today, and I managed to get my hands on an exclusive t-shirt for apparently being one of the first 1,000 people to go in!

I managed to leave without buying anything, this time. It was pretty cool to go there and be there for the opening, but it was really packed and I was queueing for over an hour to even get inside in the first place!

While there, I also discovered a rendering bug with this site under Safari (which doesn’t show up in Konqueror), so I’ll have to take a look at that and hopefully get it fixed!

UPDATE: I can’t seem to see the same issue using BrowsrCamp to get screenshots, so I have no idea what caused the bug. In case it shows up again, the sidebar on the left seemed to have the text appear twice – once on top of the existing text, so you couldn’t read it. Anyone else see this/not see this with Safari?

UPDATE #2: This bug is really nasty. I’ve been unable to get it to consistently happen, so I’m afraid I’m unable to fix it. If anyone else comes on this site on Safari and sees this bug, please screenshot it, tell me as much as you can what you were doing when it happened and send me the information. Thanks.