#!/usr/bin/ksh
print " Generate script to Export Tables for $(id -un) using IXF format files"

ixfdir=${HOME}/backup/ixf
lobdir=${HOME}/backup/ixf/bulkLOB


if [[ ! -d $ixfdir ]]

then
  mkdir $ixfdir
fi

if [[ ! -d $lobdir ]]

then
  mkdir $lobdir
fi


print "#ixfdir=$ixfdir" | tee  exportscript.ksh
print "#lobdir=$lobdir" | tee -a  exportscript.ksh

db2 "connect to $(id -un)"
print "db2 \"connect to $(id -un)\"" | tee  -a exportscript.ksh

db2 "list tables" | awk '($3=="T") {print $1}' |

while read table

do

if [[ $table = "FHVBULKDATA" ]]
then
print "db2 \"export to ${ixfdir}/${table}.IXF of IXF select * from $table where length(data) < 32700 \"" | tee -a  exportscript.ksh
else
print "db2 \"export to ${ixfdir}/${table}.IXF of IXF select * from $table\"" | tee -a  exportscript.ksh
fi
done

db2 "connect reset"
print "db2 \"connect reset\"" | tee -a exportscript.ksh

print "exportscript.ksh generated"
