Tuesday, April 17, 2012

Mysql Backup all databases

0 0 * * * for i in $(mysql -N -e 'show databases' -uroot -p'secret' ); do mysqldump -uroot -p'secret' $i | gzip -9c > /root/MYSQL_DB_BACKUP/$i\_$(date +\%Y-\%m-\%d_\%Hh\%M).sql.gz; done

This cronjob will create backups of all the databases on the server, compress and put them in /root/MYSQL_DB_BACKUP/name_of_database_datestamp.sql.gz

Thursday, April 12, 2012

How to install JavaScript runtime in Rails

*** Exception PhusionPassenger::UnknownError in PhusionPassenger::Rack::ApplicationSpawner (Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable))

Solution: Install Node.js
install on RHEL:
wget http://nodejs.tchol.org/repocfg/el/nodejs-stable-release.noarch.rpm
yum localinstall --nogpgcheck nodejs-stable-release.noarch.rpm
yum install nodejs-compat-symlinks npm

Its also possible to add gem 'therubyracer' to the projects Gemfile and bundle install it.

Wednesday, April 11, 2012

How to install sqlite3 ruby gem on RHEL5

I get the following error message when running: rails new myproject

Installing sqlite3 (1.3.5) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... no
checking for sqlite3_backup_init()... no
checking for sqlite3_column_database_name()... no
checking for sqlite3_enable_load_extension()... no
checking for sqlite3_load_extension()... no

An error occured while installing sqlite3 (1.3.5), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.5'` succeeds before bundling.

Note that the sqlite3 ruby gem is for SQLite version 3.6.16 or newer. The most recent version packaged with RHEL5 is 3.3.6. To check run: rpm -qa sqlite

Solution: Build the latest SQLite from source.
Get the source from here: http://www.sqlite.org/download.html
wget http://www.sqlite.org/sqlite-autoconf-3071100.tar.gz
tar xzvf sqlite-autoconf-3071100.tar.gz
cd sqlite-autoconf-3071100
#Install Development Tools
yum install @development-tools
./configure --prefix=/opt/sqlite3
make install

Modify your environment:
edit ~/.bash_profile for current user or globally /etc/profile.d/custom.sh
add /opt/sqlite3/bin to the PATH variable.
verify SQLite3 version: sqlite3 --version should say 3.7.x

Install sqlite3 ruby gem:
gem install sqlite3 -- --with-sqlite3-include=/opt/sqlite3/include/ --with-sqlite3-lib=/opt/sqlite3/lib/