Tuesday, 19 July 2011

Backing Up a Brightbox DB Server

I've just finished setting up the backups for one of our Brightbox database servers, and I thought it might be interesting to share how are we doing them.

As we work a lot with Ruby we decided to use two gems: Backup and Whenever; to manage the backups.

Backup allows us to easily define which database to backup, where to store the backups, if we want the backup to be compressed and which type of notification should be used.

Whenever allows us to manage our server's Cron tasks with ease, allowing us to write the necessary tasks in Ruby.

For this server we decided to compress our backups with Gzip, to transfer them to Amazon S3 and to use email as our notification system. So our system was setup like this:

ruby 1.8.7
gem backup, 3.0.16
gem whenever, 0.6.8
gem mail, 2.2.19
gem fog, 0.7.2 #to handle the S3 storage


We are using Ruby 1.8.7 because it the default in the server and we didn't feel the need to change it.

After having all the necessary tools installed we created the config files. We want to backup our databases daily, monthly and yearly, so we need three backup files. Unfortunately the Backup gem doesn't seem to handle multiple databases in the same config file, so we created three files for each database.



The configuration is very straightforward. You just need to add the details of your database, the details of the S3 storage and of the mail notifications.

After having created the config files we created the schedule.rb file for the whenever gem.



Note that for the cron job to be able to execute the backup command we need to set the environment variable PATH. In the following lines the gem will go through the existing database names and add a line in crontab to execute each of the type of backups (daily, monthly and yearly).

To add these tasks to cron we just need to run:

whenever -w "[a_name]".

And by running the following command we can see the crontab list:
crontab -l

Which might look something like:



So this is how we are backing up this database server. How are you backing up yours?

If you have any questions, or suggestions about this please let me know in the comments. =)

##Edit:
I just realised that I forgot to mention the Server details:
Operating System: Ubuntu 8.04 LTS
Database Server: PostgreSQL 9.0

Friday, 17 June 2011

Why You - Don't Debug in Production

Some time ago there was a very heated discussion about CoffeeScript in a Rails' Commit @ Github. Yesterday a friend of mine brought to my attention an interesting issue also @Github.

The issue referred to a command that was ran during installation and that, in Linux machines, would delete the /usr directory... which is not very nice since:
"This directory contains user applications and a variety of other things for them, like their source codes, and pictures, docs, or config files they use. /usr is the largest directory on a Linux system, and some people like to have it on a separate partition."

The issue was promptly fixed but the joke was on, and many many comments are being made on the commit page.

Funny enough one of those comments "mentions" my blog in some way with this image:


And I couldn't miss the chance to prove the point of my blogs' title.

I feel sorry for MrMEEE, everyone does mistakes. But maybe this way he'll get more people to help him with his app.

Thursday, 26 May 2011

Choosing the best way #1

Yesterday I was building a method to populate my chart, with Ruby on Rails, and was trying to think of the best way to get the array of years and the array of series to my view. Both would be obtained from a set of 'arrangements' associated with the current user.


I didn't want a messy controller so most of the action would happen in the model. Still I was not sure if I should have two instance variables (one array for the years and an hash for the series) or only one (an hash with information about the years and the series). So I defined three ways to do this and asked for opinions from my colleagues to help me decide.



The first alternative would need two methods in the model. The second one and the third would need only one method. But the third way could make it a bit confusing, some said.

I ended up going for the second alternative, but I must say that the third one also attracted me for it's use of that interesting ruby functionality (returning multiple results from a method).

Which one would you choose? A completely different way to do this?

Wednesday, 25 May 2011

Javascript Charts

One of our latest projects is focused mainly in data visualization, with both maps and charts. In the past day and a half I have been implementing a chart that was designed by the guys at Vizzuality.

The chart is an area chart that shows four or five series of figures over a number of years and it has some particular characteristics that make it blend in with the whole design of the application.

Desired chart

I started by using Google Charts API and managed to get really close to what I wanted, but unfortunately I didn't manage to find some options that I needed. Like for instance hiding the marker on specific points of the chart, or moving the y axis labels to the interior of the chart, and some other small things.

Google Charts atempt

Maybe it was my fault, but as I didn't really want to spend too much time looking for those options I ended up trying out Highcharts, that had mentioned by one of my colleagues when we first started looking into this project.

It was with much relief that by looking into their documentation and examples I found the exact options that I needed. In a few hours I managed to draw a chart like the one in the Vizzuality designs! And after a short while I managed to have our sample data being displayed in the chart.

Achieved result

It was really nice to achieve this goal and I was very pleased with Highcharts. "Unfortunately" it has a drawback, it's not free... except for non profit organizations like ours. =)

Anyway if you don't want to have to pay or use Highcharts I think that Google Charts is pretty good as well and as easy to use.

Maybe there are other options out there, care to recommend some?

PS: First post is here! Hurray!=)