Site5 Backup Script Revised

Posted on February 5th, 2008

About 2 weeks ago I wrote about a little script I used to backup some of my Wordpress installs automatically to Subversion. A serious problem arose with this method though, and the main reason was this line:


svn add --force *

I used this line to automatically add any new files to the repository. This was handy because often new files are created (e.g. attachments for posts in a blog), as you wouldn’t want to do this by hand every time.

This code doesn’t keep in mind deletes though. If you delete a plugin in your Wordpress, SVN will miss it and start complaining. Additionally the method above overwrites SVN:Ignore settings, which means you can’t ignore certain files (e.g. cache files that change constantly).

So instead I decided to come up with a new solution: see what files are new and what are removed, and perform “svn add” and “svn remove” actions on those files. I used a bit of code from this blog to come up with a fairly good solution.

And replace it with:


svnstatus=$(svn status)
added=$(printf "$svnstatus" | sed -n 's/^[A?] *\(.*\)/\1/p’)
removed=$(printf “$svnstatus” | sed -n ’s/^! *\(.*\)/\1/p’)

What this does is run the “svn status” command that will return a text output of all the modified files (starting with a ‘M’), added files (starting with a ‘?’) and deleted files (starting with a ‘!’). The next 2 lines do a regex to figure out the file names of the new and missing files.

Now add the following two pieces of code after the previous bit of code (and before the svn commit).


if [ "x$added" != "x" ]
then
echo adding “$added” to repository
svn add $added
fi


if [ "x$removed" != "x" ]
then
echo removing “$removed” to repository
svn remove $removed
fi

Both pieces of code use the previously regex calculated paramaters and sees if there are any files to be added or deleted. In then runs the “svn add X” and “svn add Y” commands to update the svn status. After this, a svn commit will include all new files and remove all old files from the repository. This does not remove the backup, so you always go back in time!

The “echo” commands used in these lines of code will show up on the command line, and if your cron job forwards output to an email address this can be used to check if the cron job is working correctly. If it becomes annoying, just remove them.

[Updated] Simple Tutorial on Backing up Your (Small) Sites To Subversion

Posted on January 20th, 2008

Since I wrote this article I added a followup article fixing a small problem with this script. Read the article below first though!


This tutorial is really most of all a reminder for me, and some of my friends who use Site5 hosting. It has a few flaws which I will get back to in the end. This site is intended for small sites, like Wordpress blogs, running on shared hosts. The main idea is this: backup all the data of your website daily, automatically, to an offsite location.

Step 1: Get Access to a Subversion Repository

The great thing about Subversion is that it offers incremental backups, allowing you to go back in time as far as you need to restore any problems you might run into. Assembla.com offers free subversion hosting (besides all the other things they offer), which is virtually unlimited. They do charge corporations, but with my current use (4 sites doing a daily backup) I haven’t had any problem with them contacting me or something.

Simply sign up and set up a “Space”. Ignore most of the settings but make sure to setup a Trac+Subversion package for your space. This will enable Trac support and subversion. Once the site is setup, go into the Trac/SVN tab and check the Subversion URL. It should be something like this:

http://svn2.assembla.com/svn/<your_site_name>
(more…)

2008 New Year’s Resolutions

Posted on January 2nd, 2008

After reading Melinda’s and Ian’s New Year’s resolutions on their blogs, I decided that it might be interesting for me to document my resolutions too. If not for your interest, at least for my personal motivation.

  • Get my MSc Degree: I should have gotten my degree by now, but somehow London has kept me to busy last year.
  • Work on my health: I haven’t gained weight in the last year, but this doesn’t mean I feel better. I will have to start eating healthier, although I don’t think that’s the main problem, which actually is: sport. I really need to get my ass moving and away from my laptop. I bought some running shoes and had my first 1.5km run today. Did it in 9 minutes and was completely dead after it. Let’s see if I can keep this up and do this twice a week, and so slowly increase the distance to maybe 3km and beyond.
  • Organize events: Since arriving in London almost a year ago (yes, it’s almost a year now) I have been going to Barcamps, GeekDinners, GirlGeekDinners, all organized by great people with too much of a philanthropic nature. So this year I want to go and help people organize events, starting with helping Ian with the GeekDinners, and maybe even eventually help/organize a Barcamp-like-event.
  • Read more books: I love reading books, but somehow I never get to doing it. I am not a very fast reader (especially not in comparison to Melinda), but recently I discovered Audiobooks on the iPhone. Especially the option to speedup the audio s simply brilliant. On my list to read for now are Freakonomics, Fooled by Randomness, Wheel of Time - Part 6 to 12, I am Legend, and many more.
  • Wake up earlier and more regularly: This goes partly together with my plan to sport, but it is also simply more handy to wake up at regular times. Yesterday I was up until 4am, which meant I didn’t really wake up before 12pm.

Clipperz: OpenID-proxy concept gone haywire

Posted on April 27th, 2007

There is clearly some demand for a password repository site done right. I myself would like a simple system that automatically saves/restores my information using a bookmarklet and allows me to login to the service with my OpenID. One fairly bad example is Clipperz which I was referred to by the creator (Marco Barulli) who I actually didn’t meet but did photograph at OpenCoffee.

clipperz.png

The problem of Clipperz is probably not the technique, but definitely the way it was presented (although I do wonder if saving all the secure information in your browser is that save). The Clipperz site gives me a very big *nix feel as it keeps stating what kind of crypto technology is behind it, uses concepts like cards to save scripts, and requires users to “review their code”.

From a user perspective the whole work flow is very tedious, amazingly complex, and really doesn’t provide a single-click sign-on. I think the concept is very good and probably more secure than my idea, but I think they really need a designer and usability expert to help them enable simple users to use this. I did get some nice information about how a system like this works so if will ever implement my own system than I will use some of these basic concepts.

© Cristiano on Tech/Life • Powered by Wordpress • Themed based loosely on the Swiss Cool theme.