dbimport

Aus Mikiwiki
Wechseln zu: Navigation, Suche

Der Informix-Online-Befehl dbimport kann mit dbexport aus einer Informix-Datenbank entladene Daten in eine andere Informix-Datenbank einspielen. Der Befehl wird durch den Benutzer "informix" aufgerufen.

Verwendung

Vorgehen im Fall des Testrechners der ABG

1. Sichern der Datenbank.

 # su - informix
 $ ontape -s -L 0

2. Der Informixserver muss laufen.

3. Löschen der vorhandenen Datenbank "sisis".

 # su - informix
 $ dbaccess - -
 > drop database sisis;
 CTRL+C

4. Da nicht genug Platz für die Daten der ABG vorhanden war, musste ein zusätzlicher chunk angelegt und zum bereits bestehenden Dbspace "sisisdbs" hinzugefügt werden. Die Grösse wird dabei in KB angegeben.

 # su - informix
 $ cd /home/informix
 $ cat /dev/null > sisisdbs2
 $ chmod 660 sisisdbs2
 $ onspaces -a sisisdbs -p /home/informix/sisisdbs -o 0 -s 2000000

5. Danach wird die Umgebung gesetzt und die unter "/home/sisis" stehenden dbexport-Daten (die Dateien "sisis.exp" und "dbexport.out") werden mittels dbimport in die neu anzulegende Datenbank "sisis" im Dbspace "sisisdbs" geladen.

 # su - sisis
 # DBMONEY=.; export DBMONEY
 # DBDATE=DMY4.; export DBDATE
 # cd /home/sisis
 # dbimport -d sisisdbs sisis

6. Danach müssen die vorhandenen SQL-Dateien mit dem Skript "/home/sisis/sc/patch.sh" für den Dbspace "sisisdbs" angepasst werden.

 $ cd /home/sisis/sc
 $ vi patch.sh
 HOMESISIS=`egrep "sisis:" /etc/passwd | awk -F\: ' { print $6; } '`
 #HOMESISIS=$SISISHOME
 $ ./patch.sh sisisdbs

7. Sichern der Datenbank.

 # su - informix
 $ ontape -s -L 0

8. Es waren zwei "tapes" nötig - die Datei "dbsich" musste zwischendurch weggesichert werden.

9. Zum Schluss muss unter Informix-OnLine WGS 7.20 das Skript "/opt/lib/sisis/bin/loadBLOB.sh" ausgeführt werden. Die Anleitung zur Verwendung des Skripts steht im Skript selber:

#!/bin/sh
#
# $Id: loadBLOB.sh,v 1.1.2.4 2000/07/21 15:52:28 baj Exp $

# co guru@Sisis.de, 1999

# the Informix tool dbimport has a bug which damages all BLOBS
# this tool allows you to re-load the tables from the unload
# files in the dbimport area

cat << EOF-EOF-EOF

# IMPORTANT
# the script assumes that:
# 1.  you're in the dbimport area itself as current working dir,
#     e.g. in ..../$DATABASE.exp
# 2.  you have the SQL files for creating tables below
#     \$SISISHOME/sql/siskis/*.sql and they are prepared
#     for right DBSPACE and EXTEND values
# 3.  the SQL files in \$SISISHOME/sql/siskis/*.sql must have an ";" on
#     one line as the terminator of the create-table statement; the
#     semicolon is used to split the SQL file into two parts - one for
#     creating the table and one for creating the index;
# 4.  you should have a level-0 backup of your server too (as usual)

EOF-EOF-EOF

if [ "$DATABASE" = "" ]; then
  DATABASE=${1:-'sisis'} export DATABASE
fi
INFORMIXSERVER=${INFORMIXSERVER:-'sisis'} export INFORMIXSERVER

printf "\nBLOB-loader for SISIS-sunRISE version 1.0\n\n"
printf "... pre-selected database \"${DATABASE}\"\n"
printf "... pre-selected server   \"${INFORMIXSERVER}\"\n"
printf "... you should be in      \"..../${DATABASE}.exp\" as current dir\n"
printf "\n"
printf "    We'll DROP all TABLE containing BLOBS and reload them\n"
printf "    from a dbimport-area -- is this what you really want to do?\n\n"
printf "... Let's start and hit ENTER to CONTINUE or interrupt "
read x
printf "    Anyway: LAST chance to interrupt, sleeping 3 seconds "
printf "." ; sleep 1
printf "." ; sleep 1
printf "." ; sleep 1
printf "\n... now scribbling in database (you were warned).\n"

# set the environment

SISISROOT=`pkgparam sisisbase SISISROOT` export SISISROOT
      DBS=${DBS:-`pkgparam sisisbase DBS`}

. $SISISROOT/etc/$DBS.rc

egrep "^sisis:" /etc/passwd > /dev/null 2>&1
if [ $? -ne 0 ]; then
    printf "\nPANIC: no user \"sisis\" in /etc/passwd -- exit.\n"
    exit 1
fi

if [ "$SISISHOME" = "" ]; then
  SISISHOME=`egrep "^sisis:" /etc/passwd | awk -F\: ' { print $6; } '`
fi

for tabName in       \
         koe_daten   \
         koe_kette   \
         per_daten   \
         per_kette   \
         pool_daten  \
         pool_kette  \
         swd_daten   \
         swd_kette   \
         sys_daten   \
         sys_kette   \
         titel_daten \
         titel_kette
    do
    
    rm -f /tmp/line.$$ /tmp/creat.$$ /tmp/index.$$ /tmp/error.$$

    # check for db-schema SQL file
    test -f $DATABASE.sql || {
        printf "\nPANIC: no file $DATABASE.sql in current dir -- exit.\n"
        exit 1
    }

    # check for SQL file to re-creat table
    test -f $SISISHOME/sql/sikis/$tabName.sql || {
        printf \
	"\nPANIC: file $SISISHOME/sql/sikis/$tabName.sql not found -- exit.\n"
        exit 1
    }

    ed -s $DATABASE.sql << EOF-EOF-EOF > /dev/null
    1
    /TABLE.*$tabName /
    +,+w /tmp/line.$$
    q
    EOF-EOF-EOF

    file=`cut -f 6 -d ' ' /tmp/line.$$`

    test -f $file || {
        printf "\nPANIC: file $file not found -- exit.\n"
        exit 1
    }

    printf "... running for table $tabName: "
    printf "drop table $tabName;\n" | \
      $INFORMIXDIR/bin/dbaccess $DATABASE >/tmp/error.$$ 2>&1

    printf " droped "

    ed -s $SISISHOME/sql/sikis/$tabName.sql << EOF-EOF-EOF > /dev/null
    1
    /^;/
    1,.w /tmp/creat.$$
    +,\$w /tmp/index.$$
    q
    EOF-EOF-EOF

    $INFORMIXDIR/bin/dbaccess $DATABASE < /tmp/creat.$$ > /tmp/error.$$ 2>&1

    test $? -ne 0 && {
        printf "\nPANIC: sql error -- exit.\n"
        tail /tmp/error.$$
        exit
    }

    printf "load from $file insert into $tabName;\n" | \
      $INFORMIXDIR/bin/dbaccess $DATABASE >/tmp/error.$$ 2>&1

    test $? -ne 0 && {
        printf "\nPANIC: sql error -- exit.\n"
        tail /tmp/error.$$
        exit
    }

    printf " loaded "
    $INFORMIXDIR/bin/dbaccess $DATABASE < /tmp/index.$$ > /tmp/error.$$ 2>&1

    test $? -ne 0 && {
        printf "\nPANIC: sql error -- exit.\n"
        tail /tmp/error.$$
        exit
    }

    printf " indexes created\n"
    rm -f /tmp/line.$$ /tmp/creat.$$ /tmp/index.$$ /tmp/error.$$
    
    done