My Almost Daily Blog (MADB)

Saturday, July 08, 2006

Working with Named pipes and Sybase ASE

Named pipes can be useful for a lot of things. I recently used a named pipe to dump and load a database at the same time. Usually I would first dump the database to a file, then load a second database from the dumped file. With named pipes this operation can be done in one-shot without the need of creating a dump file. Obviously one may not want to use a named pipe if they intended to make a database backup. Using a named pipe to dump and load may be faster depending on your environment or if the database being dumped is too large to fit on a file system.


To create our named pipe, we do the following:


$> mkfifo -m 666 /dump/DB.pipe
prw-rw-rw- 1 swinful 0 Jul 8 21:04 DB.pipe|


From Sybase dump to the named pipe just created. Doing so cause the dump process to block until the pipe is read from. To read from the pipe we do the following:


1> dump database DB1 to "compress::/dump/DB.pipe"
2> go
Backup Server: 4.132.1.1: Attempting to open byte stream device: 'compress::/dump/DB.pipe::00'


As you can see, our process is being blocked until the pipe is read from. Opening another terminal load from the named pipe.


1> load database DB2 from "compress::/dump/DB.pipe"

change request from the Backup Server.
Backup Server: 4.132.1.1: Attempting to open byte stream device: 'compress::/dump/DB.pipe::00'
Backup Server: 6.28.1.1: Dumpfile name 'DB1061891297B ' section number 1 mounted on byte stream 'compress::/dump/DB.pipe::00'
Backup Server: 4.58.1.1: Database DB2: 6832 kilobytes LOADed.
Backup Server: 4.58.1.1: Database DB2: 12710 kilobytes LOADed.
Backup Server: 4.58.1.1: Database DB2: 18576 kilobytes LOADed.
Backup Server: 4.58.1.1: Database DB2: 25322 kilobytes LOADed.
Backup Server: 4.58.1.1: Database DB2: 33132 kilobytes LOADed.
...
Backup Server: 3.42.1.1: LOAD is complete (database DB2).
Use the ONLINE DATABASE command to bring this database online; SQL Server will not bring it online automatically.

1> online database DB2
2> go


From the dump window you will also see a similar output like the above:


...
Backup Server: 4.58.1.1: Database DB1: 87250 kilobytes DUMPed.
Backup Server: 4.58.1.1: Database DB1: 96488 kilobytes DUMPed.
Backup Server: 3.43.1.1: Dump phase number 1 completed.
Backup Server: 3.43.1.1: Dump phase number 2 completed.
Backup Server: 3.43.1.1: Dump phase number 3 completed.
Backup Server: 4.58.1.1: Database DB1: 96592 kilobytes DUMPed.
Backup Server: 3.42.1.1: DUMP is complete (database DB1).

Tuesday, July 04, 2006

Open Source Web Design

It has been a while. My first post since 2006! Guess I have been really busy.

First and foremost I want to thank Open Source Web Design for making avaliable such fantastic templates such as the one I am using now by Carlo Forghieri. The design is simple and to the point easy on the eyes. Excellent job Carlo!

Thursday, December 08, 2005

A Ruby in one hand is worth more than a thousand Perls

Oh Ruby.. what a beautiful Gem you are. You grew more beautiful as the days went by.

My first encounter with the Ruby programming language was when I took Programming Languages my Sophomore year in college. This was about three years ago. Then, Ruby was listed as one - of about a dozen languages we could choose from - on which, we could present for extra credit if we wanted extra points. I must say, I wish I would have kept up with what I was reading back then about Ruby, because now I am so excited about RubyOnRails (RoR) that I am now revisiting Ruby.

Before RoR, I used PHPPear and loved it! Back then I thought PHPPear was the greatest to hit the web for developing database backends. I even used it to build my senior project before graduating in 2005. I was in for a big suprise when I tried ROR. I wish I would have known about Rails then.

Like most people I was a little skeptical about using Rails. I finally decided to purchase the book "Agile Web Development with Rails", by Dave Thomas and David Heinemeier Hansson and after reading and a rails article www.OnLamp.com I was convenced that Ruby with Rails will be the next killer app when it comes to developing database backend sites

With Rails I was able to develop a database app in the matter of minutes with out hardly any work. The Rails framework is an excellent one indeed. I still have a lot to learn, so back to the books for me.

Who needs Exceed Anymore?

I finally decided to try cygwin on my home machine. Previously I used Exceed to run an X server while working on my FreeBSD server. Now that I have Cygwin installed, I don't think I will ever use Exceed again. I will only have to sacrifice space, given Cygwin is taking over 100MB of disk space, while Exceed uses just below 40MB of disk space. This I don't mind, because I paid nothing for Cygwin and it can do what I want.

Exceed has officially been ditched!

Friday, November 18, 2005

Who needs Microsoft Office anymore when there is OpenOffice?

I finally decided to give OpenOffice a try since the major 2.0 release in October. I must say, I am impressed! The overall look and feel has changed drastically! I last used OpenOffice with FreeBSD about a year or two ago. At first glance I thought I was still using Microsoft Office with a few tool-bars missing.

I am almost tempted to de-install Microsoft Office, but I will wait a few months to make sure I do not have any incompatibility issues with Office documents. The best feature I like about OpenOffice is the ability to Export to PDF right out of the box! It exported just about all the MS Office documents to PDF fabulously with ease. This my friend is impressive. I am just waiting for the ability to edit the PDF's I open as well.

Monday, November 07, 2005

Installing Apache2 in FreeBSD

While installing apache2 I ran into some minor trouble.

$> cd /usr/ports/www/apache2
$> make -DWITH_EXPERIMENTAL_MODULES -DWITH_LDAP_MODULES -DWITH_MISC_MODULES -DWITH_PROXY_MODULES -DWITH_SSL_MODULES -DWITH_SUEXEC_MODULES -DWITH_THREADS_MODULES install clean


...
mod_mem_cache.c: In function `remove_entity':
mod_mem_cache.c:556: error: structure has no member named `lock'
mod_mem_cache.c:557: error: structure has no member named `lock'
mod_mem_cache.c:571: error: structure has no member named `lock'
mod_mem_cache.c:572: error: structure has no member named `lock'
mod_mem_cache.c: In function `remove_url':
mod_mem_cache.c:644: error: structure has no member named `lock'
mod_mem_cache.c:645: error: structure has no member named `lock'
mod_mem_cache.c:654: error: structure has no member named `lock'
mod_mem_cache.c:655: error: structure has no member named `lock'
mod_mem_cache.c: In function `store_body':
mod_mem_cache.c:928: error: structure has no member named `lock'
mod_mem_cache.c:929: error: structure has no member named `lock'
mod_mem_cache.c:964: error: structure has no member named `lock'
mod_mem_cache.c:965: error: structure has no member named `lock'
mod_mem_cache.c: In function `mem_cache_post_config':
mod_mem_cache.c:1034: error: structure has no member named `lock'
mod_mem_cache.c:1034: error: `APR_THREAD_MUTEX_DEFAULT' undeclared (first use in this function)
mod_mem_cache.c:1034: error: (Each undeclared identifier is reported only once
mod_mem_cache.c:1034: error: for each function it appears in.)
...
Stop in /usr/ports/www/apache2/work/httpd-2.0.55/modules/experimental.
*** Error code 1
...

From the error I could deduce that there were problems with the experimental modules. Since I did not need experimental I just removed it for the make options.


$> make -DWITH_LDAP_MODULES -DWITH_MISC_MODULES -DWITH_PROXY_MODULES -DWITH_SSL_MODULES -DWITH_SUEXEC_MODULES -DWITH_THREADS_MODULES install clean

After removing the flag "-DWITH_EXPERIMENTAL_MODULES", old object files needed to be removed as well before make could succeed.

$> make clean
===> Cleaning for libiconv-1.9.2_1
===> Cleaning for autoconf-2.59_2
===> Cleaning for gettext-0.14.5
===> Cleaning for gmake-3.80_2
===> Cleaning for libtool-1.5.20
...

$> make -DWITH_LDAP_MODULES -DWITH_MISC_MODULES -DWITH_PROXY_MODULES -DWITH_SSL_MODULES -DWITH_SUEXEC_MODULES -DWITH_THREADS_MODULES install clean
...
This port has installed the following startup scripts which may cause
these network services to be started at boot time.
/opt/etc/rc.d/apache2.sh
/opt/etc/rc.d/000.apache2libs.sh
...
===> Cleaning for autoconf-2.59_2
===> Cleaning for gettext-0.14.5
===> Cleaning for gmake-3.80_2
===> Cleaning for libtool-1.5.20
...

Well, that did the trick, so I can now work on configuring the config files.

Sunday, November 06, 2005

Upgrading to FreeBSD 6.0-Stable


I recently upgraded my FreeBSD server at home to 6.0-Stable after sticking it through with 5.3 for sometime now.

The upgrade was pretty simple.

Edit: /usr/sup/stable-supfile

Changed:
*default release=cvs tag=RELENG_5 to *default release=cvs tag=RELENG_6

$> cd /usr/src
$> make update
--------------------------------------------------------------
>>> Running /usr/local/bin/cvsup
--------------------------------------------------------------
Parsing supfile "/usr/sup/stable-supfile"
Connecting to cvsup11.FreeBSD.org
Connected to cvsup11.FreeBSD.org
Server software version: SNAP_16_1h
Negotiating file attribute support
Exchanging collection information
Establishing multiplexed-mode data connection
Running
...

I then read over /usr/src/UPDATING (... from 5.x-stable or higher to 6.x-stable.) to make sure there was nothing critical which had to be done before upgrading.


$> make buildworld
$> make kernel

Note that I did not specify KERNCONF. This is because I have this variable defined in make.conf along with others. It is highly recommended to reboot into single at this point, but I choose not to. After make kernel, I proceeded with:

$> mergemaster -p
$> make installworld
$> mergemaster -i

before rebooting the machine. After "make installworld" "mergemaster -i" it is essential that the machine is rebooted, otherwise the system will become unstable real quick. I was releived to see the following when the machine started:

Copyright (c) 1992-2005 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
The Regents of the University of California. All rights reserved.
FreeBSD 6.0-STABLE #0: Sat Nov 5 12:54:51 EST 2005

Thursday, July 21, 2005

Using Portsnap

For as long as I can remember I have been using cvsup to update my ports tree, but until recently I came across a quick excerpt on Richard Bejtlich blog about portsnap. I tried it once then stopped using cvsup for ports. Now I only use cvsup for sources and docs.

$> portsnap fetch
Fetching snapshot tag... done.
Fetching snapshot metadata... done.
Updating from Fri Jul 22 00:57:39 UTC 2005 to Fri Jul 22 02:22:01 UTC 2005.
Fetching 4 metadata patches... done.
Applying metadata patches... done.
Fetching 0 metadata files... done.
Fetching 4 patches... done.
...
Fetching 0 new ports or files... done.

$> portsnap extract
/usr/ports/x11/xtermset/
/usr/ports/x11/xtestpicture/
/usr/ports/x11/xtoolwait/
/usr/ports/x11/xtrlock/
/usr/ports/x11/xtset/
/usr/ports/x11/xvattr/
/usr/ports/x11/xvkbd/
/usr/ports/x11/xwatchwin/
/usr/ports/x11/xwit/
/usr/ports/x11/xxkb/
/usr/ports/x11/xzoom/
/usr/ports/x11/yalias/
/usr/ports/x11/yelp/
/usr/ports/x11/zenity/
Building new INDEX files... done.

$> portsnap update
Removing old files and directories... done.
Extracting new files:
/usr/ports/editors/abiword-devel/
/usr/ports/editors/abiword/
/usr/ports/irc/p5-POE-Component-IRC/
/usr/ports/www/chtml/
Building new INDEX files... done.


The fetch command fetches and stores a compressed snapshot of the ports tree, which is usually around 35MB in size. The compressed snapshot is stored in /usr/local/portsnap for later extraction using the 'extract' command. The extract command does exactly what it says, it extracts the contents of the compressed tree into /usr/ports/. Since this was my first time using portsnap and converting from cvsup, it was required that I extracted the compressed snapshot before I could use the update command to update my ports. Update is pretty fast compared to cvsup.

Now I just needed to see which ports were out dated:

$> pkg_version -L =
...
glib <
gnomekeyring <
iwi-firmware ?
k3b <
libidn <
mozilla <
...

There were about 20 ports which needed to be upgraded. Before I issuded the portupgrade command I needed to check for any stale dependencies and make sure my ports had no broken parts.

$> pkgdb -F

---> Checking the package registry database
Stale origin: 'sysutils/iwi-firmware': perhaps moved or obsoleted.
[Updating the portsdb in /usr/ports ... - 13244 port entries found .........1000.........2000.........3000.........4000.........5000.........6000
.........7000.........8000.........9000.........10000.........11000.........12000
.........13000.. ..... done]
Skip this for now? [yes] yes

The -F option lets you interactively fix the registry database if there appears to be a problem with a particular port. When I ran pkgdb one file was detected to have a stale origin, but I know this is no error as I have manually installed iwi-firmware to enable my ThinkPad wireless BG card to work correctly. iwi-firmware as of FreeBSD 5.4-Release was not included within the ports tree, but I assume that will change soon. I can now safely upgrade my the installed packages which need updating with portupgrade.

When I use portupgrade I like to first fetch all the required packages before compiling. I do a recursive fetch for all the ports which will be needed for the compile:

$> portupgrade -arF
$> portupgrade -ar

The -F option causes portupgrade to just fetch packages and store them in /usr/ports/distfiles for later compilation. -a and -r are for all packages and recursive respectively.