Bacula & Bareos: A Complete Backup Solution for the Home and Enterprise

Let’s talk about the Bacula & Bareos backup programs.

Preflight

Windows Platform
@!:{Before you deploy Bareos, you’ll need the following prerequisites installed and properly configured on the target server:
•    postgreSQL
•    PowerShell 2.0 or geater
This requires .Net Framework 2.0 or greater

Platform Info & Defaults Used
Item Description
OS Platform Windows Server 2003 R2 32-bit
Bareos Version 14.1.0 32-bit
PostgreSQL Version 9.3 32-bit
Bareos Service Password bareos
Installation Directory C:\Program Files\Bareos
Configuration Directory C:\Documents and Settings\All Users\Application Data\Bareos
Bareos Working Directory C:\ProgramData\Bareos

@!:{This article relies mostly on command line (cmd) user interaction

[divider]

About Bacula & Bareos

[divider]

What is Bacula?

A Client/Server-based backup program

In a nutshell:
Server component handles the backups, Client component sends the data to be backed up.

Simar to
Symantec Backup Exec
BackupPC
CrashPlan

Bacula website: http://blog.bacula.org/

What is Bareos?

Bareos is a fork of the Bacula project, so it boasts all of the same features as Bacula, as well as additional enhancements.

Bareos website: http://www.bareos.org/en/

For me, the most attractive feature of this fork is that the server component, the director, can now be installed on Windows.

Features

    Enterprise-level
Highly Scalable
Centrally managed
Secure
Multiplatform Client Component
Linux
OSX
Windows
Unix
Multiplatform Server Component
Bareos
Windows
Bacula
Linux
Unix
Free

How Does Bacula/Bareos Work?

wpid689-media_1418590354210.png

I yanked this verbatim from this website: http://www.netways.de/en/de/produkte/bacula/architecture_components/

Bacula Architecture & Components
Bacula is made up of several components that can be distributed to operate on several servers. Thus a central Bacula director demon can backup multiple servers, and in turn save data to multiple servers. Even a physically distributed backup strategy can be implemented easily and above all, centrally controlled.
Bacula’s individual components consist of:
Bacula director
Bacula director is the central program which controls and monitors all key tasks such as backup, restore, verify and archive. The director usually operates as a daemon or service.
Bacula console
Bacula console is the tool through which the administrator can communicate with the Bacula director. The console comes in 3 different versions, with the simplest and most popular being a text-based shell for Linux. The text-based console offers the greatest functional scope, while the GNOME and Windows GUIs provide fast backup and restore.
Bacula file demon
Bacula file demon is the actual backup client, installed on the machines to be backed up. It is operating system-specific and sends to-be-protected data with their attributes to the Bacula Director. Or in a recovery, it writes the data back onto disk. Bacula File Demon runs as a service on the servers to be backed up and is available for Unix / Linux and Windows.
Bacula storage
Bacula storage is responsible for storing and reading the saved data and their related attributes onto backup media. It runs as a service on the server which is connected to backup hardware (tapes or disks).
Bacula catalog
Bacula catalog is responsible for the indexing of all files and volumes. It allows the administrator to find and restore desired files quickly. All used volumes, saved files and exported jobs are saved in the catalog. This offers fast and efficient file restoration and management. Bacula currently supports MySQL, PostgreSQL and SQLite as catalog databases.

[divider]

Configuration Overview

Bacula/Bareos is pretty simple.

It is nothing but the sum configuration of its components. So, in essence, once you configure all of its ‘moving parts’, it will just work as intended.

Each component has its own config file
director
bacula-dir.conf
console
bconsole.conf
file daemon
bacula-fd.conf
storage
bacula-sd.conf
catalog
n/a

Each config file is formatted based on resources comprised of directives
Directives:
Specify values relative to the component
Are surrounded by curly braces {}

        @!:{For Bareos:
Configuration files are named as bareos-{}.conf instead of bacula-{}.conf

As a security measure, the various Bacula components must authorize themselves to each other
This is accomplished using password specification
example:
the Storage resource password in the bacula-dir.conf file must match the Director resource password in bacula-sd.conf

[divider]

Configuration Architecture

wpid697-media_1419381381377.png

By default, the Bacula/Bareos main configuration files are monolithic
Pros:
One config file
One location
Cons:
Difficult to manage
More prone to user error

Since Bacula 2.2.0 you can include the output of a command within a configuration file with the ”@|” syntax.
The same applies to Bareos
This allows us to break up the configs into separate, more manageable ‘child’ configuration files
How?
By parsing these ‘child’ configuration files
ForEach child config file
Read content
Incorporate into main config file

In our configuration, we will be using this special syntax to create a distributed configuration
That is …
The main config file will be built from child config files located in specified folders
Pros:
Compartmentalized
One folder per backup client
With each folder containing relevant client configs
Easier to manage
Easier to deploy new clients
This would involve:
Installing the backup client on the host
Creating a config folder for the client
Populating configuration files in the client folder
Cons:
Multiple configs
Multiple locations

The architecutre is as follows:
bacula-dir.conf
Any files in the “conf.dir” folder are considered part of this file
e.g.
On our Windows host, we have the following layout:
conf.dir [folder]
A ‘global’ folder contains default and global definitions for fileset, jobs, messages, pool, schedule, and storage directives
Client folders contain client-specific definitions for client, fileset, jobs, messages, pool, schedule, and storage directives
global [folder]
fileset.conf
jobs.conf
messages.conf
pools.conf
schedules.conf
storages.conf
NewJersey [folder]
njexch01 [folder]
configs {njexch01.fileset.conf; njexch01.jobs.conf; njexch01.pools.conf …}
NewYork [folder]
nyweb03 [folder]
configs {nyweb01.fileset.conf; nyweb01.jobs.conf; nyweb01.pools.conf …}
Pennsylvania [folder]
padb01 [folder]
configs {padb01.fileset.conf; padb01.jobs.conf; padb01.pools.conf …}
Florida [folder]
flexch01 [folder]
configs {flexch01.fileset.conf; flexch01.jobs.conf; flexch01.pools.conf …}
bacula-sd.conf
Any files in the “conf.sd” folder are considered part of this file
e.g.
On our Windows host, we have the following layout:
conf.sd [folder]
A ‘global’ folder contains default and global storage device definitions
Client folderscontains client-specific storage device definitions
global [folder]
default-device.conf
NewJersey [folder]
njexch01-device.conf
NewYork [folder]
nyweb03-device.conf
Pennsylvania [folder]
padb01-device.conf
Florida [folder]
flexch01-device.conf

 

File Paths

Windows Server 2003
[shell]C:\Documents and Settings\All Users\Application Data\Bareos\bareos-dir.conf
C:\Documents and Settings\All Users\Application Data\Bareos\bareos-dir.conf.readme.txt
C:\Documents and Settings\All Users\Application Data\Bareos\bareos-fd.conf
C:\Documents and Settings\All Users\Application Data\Bareos\bareos-sd.conf
C:\Documents and Settings\All Users\Application Data\Bareos\conf.dir
C:\Documents and Settings\All Users\Application Data\Bareos\conf.sd
C:\Documents and Settings\All Users\Application Data\Bareos\logs
C:\Documents and Settings\All Users\Application Data\Bareos\scripts
C:\Documents and Settings\All Users\Application Data\Bareos\tray-monitor.conf
C:\Documents and Settings\All Users\Application Data\Bareos\working
C:\ProgramData\Bareos\logs\bareos.log
C:\ProgramData\Bareos\logs\bareos-audit.log
C:\ProgramData\Bareos\working[/shell]

[divider]

Getting Started

Let’s get down to the guts shall we?

Installing Bacula on CentOS Linux 6.x

Installing Bareoes on Windows Server 2003 R2

Installing Bacula on CentOS Linux 6.x

@!:{this should work for the RedHat equivalent.

[divider]

Install MySQL and Bacula

[shell]yum install mysql-devel mysql-server
yum install bacula-storage-mysql bacula-docs
yum install bacula-director-mysql bacula-console
yum install bacula-client bacula-traymonitor[/shell]

Start and Configure MySQL for Bacula

[shell]service mysqld start
chkconfig mysqld on[/shell]

Change the MySQL root password if you have a fresh install of MySQL

[shell]mysqladmin -u root password ‘new-password'[/shell]

Creating the mysql database structure

wpid690-media_1418671835366.png

[shell]/usr/libexec/bacula/grant_mysql_privileges -u root -p
/usr/libexec/bacula/create_mysql_database -u root -p
/usr/libexec/bacula/make_mysql_tables -u root -p
/usr/libexec/bacula/grant_bacula_privileges -u root -p[/shell]

Installing from Source [Optional]

see:{http://wiki.bacula.org/doku.php?id=bacula_manual:installing_bacula
gls*install bacula from source
see:{Bacula Client For HP-UX@http://h30499.www3.hp.com/t5/System-Administration/Bacula-Client-For-HP-UX/td-p/5173539#.Ut7NwvQo5ok

Bacula: Post-Installation

Create the backup folder(s)
[shell]mkdir /backup
chown bacula /backup
chmod 766 /backup[/shell]

Set the MySQL password for user bacula
[shell]mysql -u root -p
–Enter Password:
WHERE user=’bacula’;
UPDATE mysql.user SET password=PASSWORD (‘somepassword’) WHERE user=’bacula’;
FLUSH PRIVILEGES;
quit[/shell]

Configure and Start the Bacula Services
[shell]chkconfig bacula-dir on
chkconfig bacula-fd on
chkconfig bacula-sd on
service bacula-dir start
service bacula-fd start
service bacula-sd start[/shell]

Update Firwall Rules (If Applicable)
Modify the iptables configuration file to allow traffic to the bacula-director
[shell]vi /etc/sysconfig/iptables[/shell]
#Allow TCP – Bacula Director
[shell]    -A INPUT -m state –state NEW -m tcp -p tcp –dport 9101 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 9102 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 9103-j ACCEPT
:q[/shell]
    Restart the firewall
[shell]service iptables restart[/shell]

[divider]

Installing Bareoes on Windows Server 2003 R2

@!:{Before you deploy Bareos, you’ll need the following prerequisites installed and properly configured on the target server:

  • postgreSQL
  • PowerShell Installed

Preflight Information
Item Description OS Platform Windows Server 2003 R2 32-bit Bareos Version 14.1.0 32-bit PostgreSQL Version 9.3 32-bit Bareos Service Password Being Used bareos Installation Directory C:\PostgreSQL\9.3 Data Directory C:\PostgreSQL\9.3\data

[divider]

Bareos Setup

wpid691-media_1418678844770.png

Installation
Installer Filename: winbareos-14.1.0.git.1406399071-32-bit-r786.1.exe
Launch the installer
Next
Agree to Licence • Next
Destination Folder: C:\Program Files\Bareos • Next
Type of install: Full • Next
Bareos Client Configuration
Client Name
bareos-fd
Director Name
bareos-dir
Password
bareos
Network Address
bareos.mydomain.local
Client Monitor Password
bareos
Bacula Compatibility
Unchecked

Post-Installation

After installation is complete:
Ensure sufficient permissions are in place for the Bareos Service Account
Bareos config paths
[shell]cacls “C:\Documents and Settings\All Users\Application Data\Bareos\scripts” /e /g bareos:f /t[/shell]
libbareoscats-postgresql.dll
[shell]copy “C:\Program Files\Bareos\libbareoscats-postgresql.dll” to %WINDIR%\System32[/shell]
Launch the PostgreSQL database creation scripts
Change Working Directory
[shell]cd “C:\Documents and Settings\All Users\Application Data\Bareos\scripts\”[/shell]
Create the bareos database
[shell]psql.exe -U <postgres username> -f postgresql-createdb.sql[/shell]
Grant Database Rights
[shell]psql.exe -U <postgres username> -f postgresql-grant.sql bareos[/shell]

This concludes installation on Windows Server 2003

[divider]

Configuring The Services

Great! You’ve installed Bacula/Bareos
Now it’s time to configure everything
The config files we are concerned with:
Windows
bareos-dir.conf
bareos-fd.conf
bareos-sd.conf
bat.conf
bconsole.conf
tray-monitor.conf

[divider]

Director Config [bacula-dir.conf] – Directives Explained

    Client
A pointer to the computer you want to back up
Schedule
Definition of when this job will run and the type of backup
Where type can be
Full
Incremental
Differential
Storage
A pointer to the backup device (tape drive or disk storage)
Catalogue
Details of the SQL database which stores the catalogue (index to contents of backup)
Pool
Collection of tapes or disk files which make up the storage
You may have multiple pools in different rotations
Messages
This is the Notification Engine
Can send messages to
Email
Log File
etc
Fileset
Path definitions for the backup selection
Answers the question: What are you backing up?
Allows inclusion/exclusion rules
Job
The Job directive can be considered the glue that binds all other directives in the Director config
The following specifications comprise this directive:
Client
Schedule
FileSet
Pool
The Pool of backup destinations
Where the destination is a backup device defined in a Storage directive

Director Config [bacula-dir.conf] – Sample

[md]@|”sh -c ‘powershell.exe -ExecutionPolicy ByPass -Command C:/Docume~1/AllUse~1/Applic~1/Bareos/scripts/Get-BareosConf.ps1′”

C:\Documents and Settings\All Users\Application Data\Bareos\bareos-sd.conf
#Includes
@|”sh -c ‘powershell.exe -ExecutionPolicy ByPass -Command C:/Docume~1/AllUse~1/Applic~1/Bareos/scripts/Get-BareosConf.sd.ps1′”[/md]

Storage Daemon Config [bacula-sd.conf] – Directives Explained

Storage
One storage record for general setup
Messages
This is the Notification Engine
Can send messages to
Director
Director
Defines the Director allowed to control the Storage Daemon
Name
Password
Device
Defines the storage device
Type
Tape
Disk

[divider]

Appendix

[divider]

Managing Backup Volumes

You might need to manage the backup voulmes for various reasons, e.g.
You need to clean up some unneeded volumes that are taking up valuable disk space

[divider]

Prune & Purge Multiple Volumes From The Command Line

wpid694-media_1419017741972.png

Bacula on Linux:
echo “use bacula;SELECT volumename
FROM Media,Pool,Storage
WHERE Media.PoolId=Pool.PoolId
AND lastwritten < DATE_SUB(CURDATE(), INTERVAL 1 DAY)
AND Pool.Name=’etejedadmc-full-pool’
AND Media.StorageId=Storage.StorageId
ORDER BY VolumeName ASC;
” | mysql -u root -p | tail -n+2 > MatchedVolumes.list
cat MatchedVolumes.list | xargs -n 1 -I % echo ‘prune volume=”%” yes’ | bconsole
cat MatchedVolumes.list | xargs -n 1 -I % echo ‘purge volume=”%” yes’ | bconsole
cat MatchedVolumes.list | xargs -n 1 -I % echo rm -f /mnt/backups/etejedabackups/regular/etejedadmc.ufn.local/%
cat MatchedVolumes.list | xargs -n 1 -I % echo rm -f /mnt/backups/etejedabackups/regular/etejedadmc.ufn.local/%
cat MatchedVolumes.list | xargs -n 1 -I % ls -lh /mnt/backups/etejedabackups/regular/etejedadmc.ufn.local/%
#verify purge status
cat MatchedVolumes.list | xargs -n 1 -I % echo list volume=% | bconsole |grep ‘^|’|tail -n +2|sed ‘s,|,,g’
#remove volumes
cat MatchedVolumes.list | xargs -n 1 -I % rm -f /mnt/backups/etejedabackups/regular/etejedadmc.ufn.local/%

Bareos on Windows:
echo prune volume=Default-Pool-Full-etejedadmc-fd-183-vol yes| bconsole.exe
echo prune volume=Default-Full-Full-etejedabak02-fd-23-vol yes | bconsole.exe
echo prune volume=Default-Pool-Full-etejedadmc-fd-182-vol yes | bconsole.exe
echo prune volume=Default-Pool-Full-etejedadmc-fd-40-vol yes | bconsole.exe
echo prune volume=Default-Pool-Full-etejedadmc-fd-44-vol yes | bconsole.exe
echo prune volume=Full-0001 yes | bconsole.exe
echo prune volume=Incremental-0002 yes | bconsole.exe
echo prune volume=Differential-0003 yes | bconsole.exe

echo purge volume=Default-Pool-Full-etejedadmc-fd-183-vol yes| bconsole.exe
echo purge volume=Default-Full-Full-etejedabak02-fd-23-vol yes | bconsole.exe
echo purge volume=Default-Pool-Full-etejedadmc-fd-182-vol yes | bconsole.exe
echo purge volume=Default-Pool-Full-etejedadmc-fd-40-vol yes | bconsole.exe
echo purge volume=Default-Pool-Full-etejedadmc-fd-44-vol yes | bconsole.exe
echo purge volume=Full-0001 yes | bconsole.exe
echo purge volume=Incremental-0002 yes | bconsole.exe
echo purge volume=Differential-0003 yes | bconsole.exe

How to change Maximum Volume size in Pool Definition

update pool from resource
followed by
update all volumes in pool
follow the prompts in both cases

[divider]

Interacting With Bacula/Bareos

[divider]

Commands Cheatsheet

Scripting Bconsole

Windows BAT: Bacula Admin Tool

wpid696-media_1419026004472.png

[divider]

Monitoring Bacula

This secions covers monitoring basics for the Bacula software

[divider]

Server-Side Key Performance Indicators (KPIs)

Solutions

    Nagios Monitoring:
http://exchange.nagios.org/directory/Plugins/Backup-and-Recovery/Bacula
Xymon Bacula Check Script
http://www.revpol.com/xymon_bacula_check_script

[divider]

Caveats

This section covers some warnings one should heed to avoid problems in the future.

[divider]

Bacula Output File

wpid695-media_1419023701702.png

If you use the default bacula-dir.conf or some variation of it, you will note that it logs all the Bacula output to a file.

To avoid that this file grows without limit, we recommend that you copy the file logrotate from the scripts/logrotate to /etc/logrotate.d/bacula.

This will cause the log file to be rotated once a month and kept for a maximum of five months.

You may want to edit this file to change the default log rotation preferences.

See:{http://www.bacula.org/en/dev-manual/main/main/Getting_Started_with_Bacula.html

[divider]

Scripts

Windows
Get-BareosConf.dir.ps1
$fso = New-Object -ComObject Scripting.FileSystemObject;
Get-ChildItem -Recurse “C:\Docume~1\AllUse~1\Applic~1\Bareos\conf.dir” `
| Where-Object {!$_.PSIsContainer} `
| ForEach-Object {
$conf=$fso.GetFile($_.FullName).ShortPath
‘@’ + “$conf”
}
Get-BareosConf.sd.ps1
$fso = New-Object -ComObject Scripting.FileSystemObject;
Get-ChildItem -Recurse “C:\Docume~1\AllUse~1\Applic~1\Bareos\conf.sd” `
| Where-Object {!$_.PSIsContainer} `
| ForEach-Object {
$conf=$fso.GetFile($_.FullName).ShortPath;’@’ + “$conf”
}

[divider]

Miscellaneous Tasks

[divider]

Reset Bacula Databases and Files

Linux
Backup Existing Database And Files
[shell]/usr/bin/mysqldump -aecqQ bacula > bacula_before_purge.sql[/shell]
Stop Bacula Services
[shell]service bacula-dir stop
service bacula-fd stop
service bacula-sd stop[/shell]
Drop MySQL Tables
[shell]mysql -u root -p -e “drop database bacula;”[/shell]
Recreate Database & Grant Permissions
/usr/libexec/bacula/create_mysql_database -u root -p
/usr/libexec/bacula/make_mysql_tables -u root -p
/usr/libexec/bacula/grant_mysql_privileges -u root -p
Stop Bacula Services
[shell]service bacula-dir start
service bacula-sd start
service bacula-fd start[/shell]
@!:{Assumes you are using MySQL for the Bacula Database

[divider]

Troubleshooting

    

Problem Scenarios
Problem Possible Cause Troubleshooting
The Bacula Director service fails to start or starts then quickly stops There is most likely an error in the configuration preventing proper function The first step in troubleshooting is to determine what the problem is
Try launching the Director interactively from command line (without the /service flag) and observing output, e.g.:
[shell]"C:\Program Files\Bareos\bareos-dir.exe" -c "C:\Documents and Settings\All Users\Application Data\Bareos\bareos-dir.conf"
[/shell] In my case, I had an error in the configuration, so I was presented with the following standard output: [diff] … bareos-dir: ERROR TERMINATION atlib/res.c:459
Config error: Could not find config Resource Full referenced on line 13 : Full Backup Pool = Full …
: line 13, col 43 of file C:\DOCUME~1\ALLUSE~1\APPLIC~1\Bareos\conf.dir\base\JOBS~1.CON[/diff]
[diff]Fatal error: Storage daemon didn't accept Device
"device-name" because: 3924 Device "device-name" not in SD Device resources or no matching Media Type[/diff]
Possibibilites include:
1. Mismatching Media Type definitions between client storage definition and bacula storage definition
2. Missing Media Type definitions in either the client storage definition, bacula storage definition, or both
3. Insufficient permissions on the backup destination folder (if Media Type is File)
4. Storage daemon not running
5. You updated parameters for a storage device or pertinant configuration, but did not restart the storage daemon to finalize the changes [attr style="width:300px"
[diff]Fatal error: Storage daemon didn't accept Device "device-name" command[/diff] An error in the Storage Daemon configuration Double-check your SD configuration
Common problems include:
1. Invalid or non-existing path specified in Device directive (applies to Disk backup types)
[diff]Error: Director's comm line to SD dropped.
… Fatal error: filed/dir_cmd.c:2208 Comm error with SD. bad response to Append Data. ERR=Input/output error[/diff]
An error in the Storage Daemon configuration Double-check your SD configuration
Common problems include:
1. Invalid or non-existing path specified in Device directive (applies to Disk backup types)

@!:{Again, make sure to restart the storage daemon if you make any changes to the storage daemon configuration!

Filesystem Permissions

wpid693-media_1418712327445.png

Sources

see:{Bacula volumes – running low on disk space@http://dan.langille.org/2012/10/04/bacula-volumes-running-low-on-disk-space/
see:{File storage: disk full, how to recover@http://bacula.10910.n7.nabble.com/File-storage-disk-full-how-to-recover-td40740.html
see:{pruneall@http://bacula.10910.n7.nabble.com/file/n40741/pruneall
see:{delpurged@http://bacula.10910.n7.nabble.com/file/n40741/delpurged
see:{gls*bacula delete failed jobs
see:{Purge Jobs @http://www.backupcentral.com/phpBB2/two-way-mirrors-of-external-mailing-lists-3/bacula-25/purge-jobs-103092/
see:{gls*bacula disk full recycle
see:{Bacula disk space management@http://www.bignose.ca/2013/09/19/bacula-disk-space-management/
see:{Run sql-command from bash-script?@http://stackoverflow.com/questions/20351573/run-sql-command-from-bash-script
see:{produce a separate sql@http://www.crumpeta.com/using_xargs_to_create_sql_statements
see:{Volume Status is Full instead of Purge@http://bacula.10910.n7.nabble.com/Volume-Status-is-Full-instead-of-Purge-td76522.html
see:{gls*bconsole list vol status purged
see:{Bacula Cheat Sheet@https://workaround.org/bacula-cheatsheet
see:{Reset Bacula database and files@http://blog.mansonthomas.com/2009/09/reset-bacula-database-and-files.html




Troubleshooting Ruby Applications

This article lists errors and solutions I’ve come across in my experience with Ruby applications.

Errors/Solutions

Common Errors/Possible Solutions
Error Description Possible Cause Possible Solution "did not find expected key while parsing a block mapping at line …" You may have a syntax error in a config/yaml file Try testing your yaml file with Ruby for any syntax errors.
If there is no output, then the syntax is OK. If errors found, start troubleshooting at the line number reported by the error message:
ruby -e "require 'yaml'; YAML.load_file('/somepath/myconfigfile.yml')"




How I Am Learning Ruby on Rails Part I

This is the first post in what I am expecting to be a lengthy monologue centered around learning web programming with Ruby on Rails.

My Development Environment

Item Detail OS Windows 8.1 Hardware Dell Optiplex 760, 4.00 GB of RAM Programming Software JetBrains Ruby Mine (IDE Software)
Notepad2

Preflight – ELI5 What is Ruby on Rails?

Excerpt from the Documentation for rails (3.0.0):

Rails is a web-application framework that includes everything needed to create
database-backed web applications according to the Model-View-Control pattern.

This pattern splits the view (also called the presentation) into “dumb”
templates that are primarily responsible for inserting pre-built data in between
HTML tags. The model contains the “smart” domain objects (such as Account,
Product, Person, Post) that holds all the business logic and knows how to
persist themselves to a database. The controller handles the incoming requests
(such as Save New Account, Update Product, Show Post) by manipulating the model
and directing data to the view.

In Rails, the model is handled by what’s called an object-relational mapping
layer entitled Active Record. This layer allows you to present the data from
database rows as objects and embellish these data objects with business logic
methods. You can read more about Active Record in
link:files/vendor/rails/activerecord/README.html.

The controller and view are handled by the Action Pack, which handles both
layers by its two parts: Action View and Action Controller. These two layers
are bundled in a single package due to their heavy interdependence. This is
unlike the relationship between the Active Record and Action Pack that is much
more separate. Each of these packages can be used independently outside of
Rails. You can read more about Action Pack in
link:files/vendor/rails/actionpack/README.html.

Day 1: Read the f#king Manual – Chapter 1 of The Ruby On Rails Tutorial

wpid229-wpid-wpid-media_140622352655111.png

The manual I chose to read: The Ruby on Rails Tutorial by Michael Hartl.
The author was kind enough to put the material online for free reading.
see:{http://www.railstutorial.org/

Things I learned today: The linux sudo command stands for “substitute user doO_O
In my relatively short time spelunking into the *nix commandline, I never bothered to look up the etymology behind the executable.
I think the term merits a line in a Wikipedia article, perhaps this one: List of computer term etymologies

[divider]

Day 2: Install Ruby & Rails, and Git

[divider]

Install Ruby & Rails

wpid230-wpid-wpid-media_140691320073511.png

Preflight:
The author recommends I install Ruby 1.9.3 if I’m on Windows, so that’s what I’m going to do.
Weblink: http://railsinstaller.org/en
I downloaded the file railsinstaller-2.2.3.exe
From the website – Packages included are:
Ruby 1.9.3
Rails 3.2
Bundler
Git
Sqlite
TinyTDS
SQL Server Support
DevKit

Configure Git, Verify Ruby & Rails

wpid231-wpid-wpid-media_140691533618911.png

As you can see in the illustration, I’ve configured Git security keys by following the prompts and entering my name and email address.
I also verified my ruby version:

ruby -v
as well as my rails version:
rails -v

Take note: the p545 suffix in the ruby version stands for the patch number.
I don’t believe it’s critical for this number to match the author’s ruby environment.

Configure & Install Development Environment

The author recommends Sublime Text 2 for the development environment.
Download here: http://www.sublimetext.com/2
From the website: “Sublime Text 2 may be downloaded and evaluated for free, however a license must be purchased for continued use. There is currently no enforced time limit for the evaluation.
I gave Sublime a try a few months ago. It’s very useful, but I prefer JetBrains RubyMine:http://www.jetbrains.com/ruby/
It’s not a free program, but you are allowed 30 days to evaluate.
Since I’m a student at Pennsylvania State University, I qualify for the $29.00 Academic License 🙂

Before you begin working with JetBrains RubyMine, read this: Using RubyMine IDE for Hartl’s Rails Tutorial
The author’s name is David Loeffler, and he gears the information for OSX Users, so I’ll compile some notes for Windows Users since that’s my platform.
I’ll begin with a table of contents like he does, substuting Windows-centric terms and applications where need be:

pik and Ruby Installation
Setting up RubyMine IDE
Version Control with Git using RubyMine
[Running Spork Server inside RubyMine]
Convert to PostgreSQL for development and testing
Data Model for Sample App starting in chapter 6.
Rails Console running inside RubyMine
Extras
Additional References

[divider]

Installing pik

From the github project page “… pik is a tool to manage multiple versions of ruby on Windows. It can be used from the Windows command line (cmd.exe), Windows PowerShell, or Git Bash”

Requirements are listed as:

Requirement Description gems: rake, isolate exerb-mingw Exerb is a program that converts Ruby scripts and extension libraries
into equivalent Microsoft Windows executables, which can execute alone and independently. upx
UPX is a free, portable, extendable, high-performance executable packer for several executable formats.

With that, let’s see about installing the tool.

1. Ensure you have the requisite gems installed:

gem list isolate
gem list rake

If the commands return nothing, you’ll need to install the gems

gem install isolate
gem install rake

2. Install exerb-mingw
Launch Windows CMD
Change dir to your workspace (could be any folder, just be consistent, e.g. C:\MyRuby)
Clone the exerb-mingw Github project

git clone git://github.com/snaury/exerb-mingw.git
cd exerb-mingw
ruby setup.rb all

For my environment, the installation resulted in a bunch of objects being created under C:\RailsInstaller\Ruby1.9.3
Sample Output:

mkdir -p C:/RailsInstaller/Ruby1.9.3/bin/
install exerb C:/RailsInstaller/Ruby1.9.3/bin/
install exerb.bat C:/RailsInstaller/Ruby1.9.3/bin/
install mkexy C:/RailsInstaller/Ruby1.9.3/bin/
install mkexy.bat C:/RailsInstaller/Ruby1.9.3/bin/
... 
mkdir -p C:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/
..mkdir -p C:/RailsInstaller/Ruby1.9

Some Notes:
setup.rb is a generic installer for ruby scripts and libraries. You can use setup.rb to install your any ruby programs.

3. Install upx
Navigate to the SourceForge page and download the Windows Binary
The file I obtained was upx391w.zip
From this archive, copy the upx.exe executable to a location accessible via your windows PATH environmental variable (machine scope is best)

4. Install Pik

pik_install c:\externaltools\bin

Sample Output

Thank you for using pik.
mkdir -p c:\bin
mkdir -p C:\Users\myusername/.pik
Installing to c:\externaltools\bin
cp C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/pik-0.2.8/tools/pik_runner.exe c:\externaltools\bin
cp C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/pik-0.2.8/tools/pik.bat c:\externaltools\bin
cp C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/pik-0.2.8/tools/pik.ps1 c:\externaltools\bin
creating C:\Users\myusername/.pik/.pikrc
pik is installed
if you want to use pik with git bash, add the following line to your ~/.bashrc:
[[ -s $USERPROFILE/.pik/.pikrc ]] && source $USERPROFILE/.pik/.pikrc

Setting Up RubyMine IDE

Switch ruby version:
pik use 1.9.3 p545
Verify active ruby version:
pik list

[divider]

Appendix

[divider]

Command Cheatsheet

Linux Commands
Command Description rvm list gemsets rails new myapp (where myapp is the application name) – At the command prompt, create a new Rails application cd myapp; rails server (run with –help for options) Change directory to myapp and start the web server.
Go to http://localhost:3000/ and you'll see
"Welcome aboard: You're riding Ruby on Rails!"

Debugging Rails

== Debugging Rails

Sometimes your application goes wrong. Fortunately there are a lot of tools that
will help you debug it and get it back on the rails.

First area to check is the application log files. Have "tail -f" commands
running on the server.log and development.log. Rails will automatically display
debugging and runtime information to these files. Debugging info will also be
shown in the browser on requests from 127.0.0.1.

You can also log your own messages directly into the log file from your code
using the Ruby logger class from inside your controllers. Example:

class WeblogController < ActionController::Base
def destroy
@weblog = Weblog.find(params[:id])
@weblog.destroy
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
end
end

The result will be a message in your log file along the lines of:

Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!

More information on how to use the logger is at http://www.ruby-doc.org/core/

Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
several books available online as well:

* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)

These two books will bring you up to speed on the Ruby language and also on
programming in general.

 

== Debugger

Debugger support is available through the debugger command when you start your
Mongrel or WEBrick server with –debugger. This means that you can break out of
execution at any point in the code, investigate and change the model, and then,
resume execution! You need to install ruby-debug to run the server in debugging
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:

class WeblogController < ActionController::Base
def index
@posts = Post.find(:all)
debugger
end
end

So the controller will accept the action, run the first line, then present you
with a IRB prompt in the server window. Here you can do things like:

>> @posts.inspect
=> "[#<Post:0x14a6be8
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
#<Post:0x14a6620
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
>> @posts.first.title = "hello from a debugger"
=> "hello from a debugger"

…and even better, you can examine how your runtime objects actually work:

>> f = @posts.first
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
>> f.
Display all 152 possibilities? (y or n)

Finally, when you’re ready to resume execution, you can enter "cont".

 

== Console

The console is a Ruby shell, which allows you to interact with your
application’s domain model. Here you’ll have all parts of the application
configured, just like it is when the application is running. You can inspect
domain models, change values, and save to the database. Starting the script
without arguments will launch it in the development environment.

To start the console, run <tt>rails console</tt> from the application
directory.

Options:

* Passing the <tt>-s, –sandbox</tt> argument will rollback any modifications
made to the database.
* Passing an environment name as an argument will load the corresponding
environment. Example: <tt>rails console production</tt>.

To reload your controllers and models after launching the console run
<tt>reload!</tt>

More information about irb can be found at:
link:http://www.rubycentral.com/pickaxe/irb.html

 

== dbconsole

You can go to the command line of your database directly through <tt>rails
dbconsole</tt>. You would be connected to the database with the credentials
defined in database.yml. Starting the script without arguments will connect you
to the development database. Passing an argument will connect you to a different
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
PostgreSQL and SQLite 3.

== Description of Contents

The default directory structure of a generated Ruby on Rails application:

|– app
| |– controllers
| |– helpers
| |– mailers
| |– models
| `– views
| `– layouts
|– config
| |– environments
| |– initializers
| `– locales
|– db
|– doc
|– lib
| `– tasks
|– log
|– public
| |– images
| |– javascripts
| `– stylesheets
|– script
|– test
| |– fixtures
| |– functional
| |– integration
| |– performance
| `– unit
|– tmp
| |– cache
| |– pids
| |– sessions
| `– sockets
`– vendor
`– plugins

app
Holds all the code that’s specific to this particular application.

app/controllers
Holds controllers that should be named like weblogs_controller.rb for
automated URL mapping. All controllers should descend from
ApplicationController which itself descends from ActionController::Base.

app/models
Holds models that should be named like post.rb. Models descend from
ActiveRecord::Base by default.

app/views
Holds the template files for the view that should be named like
weblogs/index.html.erb for the WeblogsController#index action. All views use
eRuby syntax by default.

app/views/layouts
Holds the template files for layouts to be used with views. This models the
common header/footer method of wrapping views. In your views, define a layout
using the <tt>layout :default</tt> and create a file named default.html.erb.
Inside default.html.erb, call <% yield %> to render the view using this
layout.

app/helpers
Holds view helpers that should be named like weblogs_helper.rb. These are
generated for you automatically when using generators for controllers.
Helpers can be used to wrap functionality for your views into methods.

config
Configuration files for the Rails environment, the routing map, the database,
and other dependencies.

db
Contains the database schema in schema.rb. db/migrate contains all the
sequence of Migrations for your schema.

doc
This directory is where your application documentation will be stored when
generated using <tt>rake doc:app</tt>

lib
Application specific libraries. Basically, any kind of custom code that
doesn’t belong under controllers, models, or helpers. This directory is in
the load path.

public
The directory available for the web server. Contains subdirectories for
images, stylesheets, and javascripts. Also contains the dispatchers and the
default HTML files. This should be set as the DOCUMENT_ROOT of your web
server.

script
Helper scripts for automation and generation.

test
Unit and functional tests along with fixtures. When using the rails generate
command, template test files will be generated for you and placed in this
directory.

vendor
External libraries that the application depends on. Also includes the plugins
subdirectory. If the app has frozen rails, those gems also go here, under
vendor/rails/. This directory is in the load path.

Sources

Sources
Source Details Google Search Term(s) "" https://github.com/madprog/kabona "" http://i.loveruby.net/en/projects/setup/doc/usage.html "" https://github.com/snaury/exerb-mingw/blob/master/README.en.txt "" http://upx.sourceforge.net/ "" gls*gem list gems Ruby Version Manager in Mountain Lion https://github.com/perfectionist/sample_project/wiki/Ruby-Version-Manager-in-Mountain-Lion PIK – Ruby Version Manager for Windows https://github.com/vertiginous/pik/downloads pik-0.3.0.pre.msi Ruby on Rails Screncasts http://rubyonrails.org/screencasts Beginning Ruby: From Novice to Professional by Peter Cooper http://www.amazon.com/gp/product/1430223634 The Well-Grounded Rubyist http://www.amazon.com/gp/product/1933988657 Eloquent Ruby (Addison-Wesley Professional Ruby Series) http://www.amazon.com/Eloquent-Ruby-Addison-Wesley-Professional-Series/dp/0321584104/ The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming http://www.amazon.com/gp/product/0672328844 Ruby on Rails Guides http://guides.rubyonrails.org/ Tealeaf Academy http://www.gotealeaf.com/ Codeschool https://www.codeschool.com Ruby Gems Basics http://guides.rubygems.org/rubygems-basics/ Ruby Gems Command Reference http://guides.rubygems.org/command-reference/ The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html