Archive for February, 2007

Automated sites backup script

Wednesday, February 14th, 2007

Today I have been restoring automatic backup system for the company I work at. The idea is to take backups of our clients' web sites (both web/html files and database snapshots). So I have decided why not to share? This script was dutifully working for me for almost a year and though it might be not the best way to do stuff, it proven itself pretty robust and problem-free.

Before pasting the script code here, here's how it works.

The script logs into remote server and takes backup of remote html files and database files. One important thing is to notice that database files backup is takes "as is", as I have found out not in the most pleasant way that taking backups of databases via mysqldump command can lead to problems in case tables in the SQL database use different encodings - so binary dump is much safer.

One more thing to notice is that you need to generate an ssh key-pair in order to be able to log into a remote server without entering a password (that's why there is no mention of passwords in the script's settings). You can read about logging into SSH without using passwords here.

Since I use rsync to fetch files from server, only files which were changes between backup sessions are being transferred - which makes backups much faster in case of successive backups.

Usage: php backup.php <backup_type>

you can specify type of backup, so it will be placed into a separate directory. Default is "nightly". Files will be backed up into directories inside the $backupDir you specified, in form of: "<sitename>_<backup_type>_<web or db>".

Once the script is deployed and configured, you might want to specify cron jobs which would make nightly, weekly and monthly backups for you. This way you will have at least 3 versions to choose from in case something shitty happens :)

And of course I would like to notice that the script goes "as-is" without any warranties that it won't destroy your data and nullify you hard disk (although if configured sanely, it would only save you from problems of loosing data).

Have fun with the script, modify it if you want. Hopefully it'll save you some nerve cells if ever a problem occurs on your remote servers.

The script follows:

(more…)

Moving to Rails 1.2.2

Thursday, February 8th, 2007

Well today I have FINALLY moved all my three current Rails projects (the third one is still in development though) to Rails 1.2.2.

There were some quirks I had to resolve during the transition though.

First of all, I have installed the latest version of rails onto the server by typing:

gem install rails –include-dependencies

Then I have updated all of the gems to their latest versions:

gem update

Some changes had to be made to the source code of my Ruby apps:

  • @params and @headers are deprecated now, so I have renamed them to params and headers
  • in environment.rb I have replaced the old RAILS_GEM_VERSION = '1.6' to RAILS_GEM_VERSION = '1.2.2' unless defined? RAILS_GEM_VERSION
  • there was a problem links generated by image_tag / FlexImage's flex_image generated image formatting function not resolved by Rails routing because image_tag attached the ".png" extension (and Rails 1.2 has a stricter checking for filenames in routes, so /image/show/123 was resolved just fine, but /image/show/123.png was getting unknown_action , though it was not a problem with Rails 1.1.6). As a simple solution I have added the following to routes.rb :
    map.connect 'image/:action/:id.:ext', :controller => 'image'
  • I have removed "vendor/plugins/engines", "vendor/plugins/unicode_hacks" as they seem not to be compatible with Rails 1.2 (everything worked fine in development mode, but was giving errors in production)
  • as the last step, I ran "rake rails:update" to update JS libs and stuff to their latest version

Everything works fine nice, and feels a bit snappier even. Cool :)

WordPress 2.1 upgrade/plugins check

Thursday, February 1st, 2007

Well today i FINALLY (!!!) had a few free minutes to upgrade my site to WordPress 2.1.

There we some comments asking if the WordPress plugins I have made are actually compatible with WordPress 2.1.

Well the answer is short, and it is, YES, both Google Inline Maps 2.0 and Easy Inline SWF are compatible with WordPress 2.1.

And here's some test under the cut :) (more…)

My World Map :)

Thursday, February 1st, 2007

Here's my world map. 5% of countries, just the amount of consumer tax in Japan :) (more…)