Showing posts with label Ruby. Show all posts
Showing posts with label Ruby. Show all posts

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

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?