Monday, December 9, 2013

Backup Script for Postgresql in Linux

#!/bin/bash

# Location to place backups.
BACKUP_DIR="/home/adempiere-backup/"

# Database User
PGUSER=postgres

#PGPASSWORD
PGPASSWORD=password

#SET User name and Password
export PGUSER PGPASSWORD

#String to append to the name of the backup files
BACKUP_DATE=`date +%Y%m%d%H%M%S`.dump

#Numbers of days you want to keep of copy databases
#NO_OF_DAY=30

#LIST DATABASES
DATABASE=`psql -l -t | cut -d'|' -f1 | sed -e 's/ //g' -e '/^$/d'`
for i in $DATABASE; do
  if [ "$i" != "template0" ] && [ "$i" != "template1" ] && [ "$i" != "postgres" ]; then
    echo Dumping $i to $BACKUP_DIR$i\_$BACKUP_DATE
    pg_dump -Fc $i > $BACKUP_DIR$i\_$BACKUP_DATE
  fi
done
#find $BACKUP_DIR -type f -prune -mtime +$NO_OF_DAY -exec rm -f {} \;

#Clear PGUSER and PGPASSWORD
PGUSER=""
PGPASSWORD=""
export PGUSER PGPASSWORD
#End

Wednesday, December 4, 2013

How to install and setup Oracle JAVA JDK in CentOS 6.4

The machine was running the CentOS 6.4 GNU/Linux distribution and the installation of JAVA JDK was fairly straight forward.
But, I wanted to write this down so that it serves as a proper how-to installation of Oracle’s JAVA in CentOS 6.4. The procedure should be almost (if not completely) the same for CentOS 5 and distros alike .
Ok, enough said. The tutorial is split into the following sections:
  1. Update the system
  2. Remove any installed versions
  3. Download JAVA JDK6 or JDK7
  4. Install JAVA JDK6 or JDK7
  5. Set-up JAVA JDK6 or JDK7
  6. Confirm JAVA JDK6 or JDK7 installation

1. The first thing I’ve done was to make sure the CentOS 6.4 system is fully up-to-date, so I ran:
# yum update
2. Once the update completed, I then checked the system for any other installed JAVA packages using:
# rpm -qa | grep -E '^open[jre|jdk]|j[re|dk]'
there was the ‘java-1.6.0-openjdk-1.6.0.0-1.56.1.11.8.el6_3.i686‘ package already installed so I removed it by running:
# yum remove java-1.6.0-openjdk
3. The next step was to go and download the required JAVA JDK package for the system I was working on. It was a 32 bit CentOS 6.4 so I needed to get the 32 bit JAVA JDK package from Oracle’s JAVA download page.
Note that I needed to install an older version of JAVA JDK since it was specific to the software I was setting up.
Download JAVA JDK6 at:
http://www.oracle.com/technetwork/java/javase/downloads/jdk6u35-downloads-1836443.html
Download JAVA JDK7 at:
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
4. Once the JAVA JDK package got downloaded I proceeded with installing the package.
a) Installing the JAVA JDK6 package in CentOS 6.4

set executable bit using:
# chmod +x jdk-6u35-linux-i586-rpm.bin
and installed the JAVA JDK6 package by running:
# ./jdk-6u35-linux-i586-rpm.bin

b) Installing the JAVA JDK7 package in CentOS 6.4

# rpm -Uvh jdk-7u15-linux-i586.rpm
5. Once the JAVA JDK package is installed I then needed to configure it on the system using the `alternatives` command. This is in order to tell the system what are the  default commands for JAVA. Most _sys_admins_ aren’t aware about this and I think that it is a vital part when setting the JAVA package.
a) Setting up the JAVA JDK6 package
# alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_35/jre/bin/java 20000
# alternatives --install /usr/bin/jar jar /usr/java/jdk1.6.0_35/bin/jar 20000
# alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_35/bin/javac 20000
# alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.6.0_35/jre/bin/javaws 20000
# alternatives --set java /usr/java/jdk1.6.0_35/jre/bin/java
# alternatives --set javaws /usr/java/jdk1.6.0_35/jre/bin/javaws
# alternatives --set javac /usr/java/jdk1.6.0_35/bin/javac
# alternatives --set jar /usr/java/jdk1.6.0_35/bin/jar
this set the default commands for JAVA JDK7 and listing the ‘/etc/alternatives/’ directory showed the following:
# ls -lA /etc/alternatives/
total 0
lrwxrwxrwx. 1 root root 29 Feb 22 03:39 jar -> /usr/java/jdk1.6.0_35/bin/jar
lrwxrwxrwx. 1 root root 34 Feb 22 03:39 java -> /usr/java/jdk1.6.0_35/jre/bin/java
lrwxrwxrwx. 1 root root 31 Feb 22 03:39 javac -> /usr/java/jdk1.6.0_35/bin/javac
lrwxrwxrwx. 1 root root 36 Feb 22 03:39 javaws -> /usr/java/jdk1.6.0_35/jre/bin/javaws

b) Setting up the JAVA JDK7 package
# alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_15/jre/bin/java 20000
# alternatives --install /usr/bin/jar jar /usr/java/jdk1.7.0_15/bin/jar 20000
# alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0_15/bin/javac 20000
# alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0_15/jre/bin/javaws 20000
# alternatives --set java /usr/java/jdk1.7.0_15/jre/bin/java
# alternatives --set javaws /usr/java/jdk1.7.0_15/jre/bin/javaws
# alternatives --set javac /usr/java/jdk1.7.0_15/bin/javac
# alternatives --set jar /usr/java/jdk1.7.0_15/bin/jar
this set the default commands for JAVA JDK7 and listing the ‘/etc/alternatives/’ directory showed the following:
# ls -lA /etc/alternatives/
total 0
lrwxrwxrwx. 1 root root 29 Feb 22 03:39 jar -> /usr/java/jdk1.7.0_15/bin/jar
lrwxrwxrwx. 1 root root 34 Feb 22 03:39 java -> /usr/java/jdk1.7.0_15/jre/bin/java
lrwxrwxrwx. 1 root root 31 Feb 22 03:39 javac -> /usr/java/jdk1.7.0_15/bin/javac
lrwxrwxrwx. 1 root root 36 Feb 22 03:39 javaws -> /usr/java/jdk1.7.0_15/jre/bin/javaws
6. Finally I verified the installed version of JAVA via:
# java -version
java version "1.7.0_15"
Java(TM) SE Runtime Environment (build 1.7.0_15-b03)
Java HotSpot(TM) Client VM (build 23.7-b01, mixed mode, sharing)
and
# java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) Server VM (build 20.10-b01, mixed mode)
I know this how-to will serve me as a quick reference for installing JAVA in the future and I truly hope this will help someone else too.

Sunday, December 1, 2013

Joined Tables

The possible types of qualified join are:
INNER JOIN
For each row R1 of T1, the joined table has a row for each row in T2 that satisfies the join condition with R1.
LEFT OUTER JOIN
First, an inner join is performed. Then, for each row in T1 that does not satisfy the join condition with any row in T2, a joined row is added with null values in columns of T2. Thus, the joined table always has at least one row for each row in T1.
RIGHT OUTER JOIN
First, an inner join is performed. Then, for each row in T2 that does not satisfy the join condition with any row in T1, a joined row is added with null values in columns of T1. This is the converse of a left join: the result table will always have a row for each row in T2.
FULL OUTER JOIN
First, an inner join is performed. Then, for each row in T1 that does not satisfy the join condition with any row in T2, a joined row is added with null values in columns of T2. Also, for each row of T2 that does not satisfy the join condition with any row in T1, a joined row with null values in the columns of T1 is added.