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…)

Serious Safari Cookie Bug?

Posted on December 14th, 2007 nederlands

It seems that quite a few people (including me and Alper) are having problems with the latest release of Safari for Mac (3.0.4 for Leopard, and 3.0.3 for Tiger) concerning it sporadically forgetting cookies. I had the issue a few times now that I suddenly seemed to be logged out of all my websites. Luckily I got a very nice keychain to get me logged in pretty quickly again, but it is very annoying. I think the bug most be reported to Apple by know as the discussions in the Apple Support page refer to a couple of tickets submitted to Apple already.

How to run an EyeToy on Mac OS X

Posted on December 13th, 2007

So, I was trying to get my PS2 EyeToy to work on my G4 Mac Mini for a while now. I had done this a while back on a Windows machine and I loved it, so I was hoping it would be a breeze to get to work in Mac OS X. It took a while though to get it working, not because it was difficult to do or something, but simply because there was only one place on the whole internet that gave me an interesting link! So now I will try to make a more Google accessible blog post that can serve as a point to go to for everyone in the future.
(more…)

Geotagging on Flickr Help Needed

Posted on April 21st, 2007

I really enjoy my new Nikon D40 and as some of you might know I even like to provide all my photos on Flickr with tags, names, sometimes descriptions, and most of the time Geo Tags. But as I keep shooting more photos, keeping track of where I shot them is beginning to become difficult.

So I know that there are small bluetooth GPS devices that can keep track of your location and then later on match the photos with the proper GeoTags. There are many examples online about how to use these GPS devices and most of them are very broad, for me too broad.

Basically all I need is a GPS unit that keeps track of my location throughout a day. It needs to work with a Mac, and if possible the software better have some nice integration with Flickr. Anyone have any experience with this that could help me?

© Cristiano on Tech/Life • Powered by Wordpress • Using the Swiss Cool theme.