"Dave Hughes" <da*********@wa veform.plus.com > wrote in message news:<xn******* *********@usene t.plus.net>...
Unfortunately, this will only transfer *tables* from one schema to
another (db2move doesn't handle anything else), though as the manual
page specifies, the db2look tool can be used to export DDL to re-create
other objects. I suspect modifying db2look's output to replace the
schema would be more difficult - though not impossible.
Does anyone else know of a better way to go about doing this?
Well, db2move is a nice little tool, but it isn't difficult to write
your own version. This gives you the ability to include additional
functionality, like:
- runstats
- deletions
- extract selection criteria
- change schema/table names
- force connections
- lock tables
- audit trail
- notification
- etc
I've written a few of these for moving data between a warehouse and
its data marts. A stripped-down version of one is included below.
Here's how it would typically work:
- extract version (not provided but very similar) is scheduled to
run at a regular time
- transport process (not provided) automatically pushes extract file
to mart
- mart load (included below) is scheduled to run every minute -
looking continuously for a file to load
The following version is intended to show how this would work, rather
than be a complete solution - though 90% of the code is there. I
basically took a functional process, then removed just a little
application-specific & manageability code. It's written in korn shell
- so should run fine on unix. Should also run fine in bash for linux.
Would work with minimal changes in cygwin on windows. Same concept
works just fine in perl/python/tcl/rexx/etc.
#!/usr/bin/ksh
#----------------------------------------------------------------------------
# Load config values:
#----------------------------------------------------------------------------
data_dir=$HOME/data/mart3
temp_dir=$HOME/data/mart3/temp
archive_dir=$HO ME/archive/mart3
log_dir=$HOME/logs/mart3
script_name=mar t3_load.ksh
.. $HOME/.profile
#----------------------------------------------------------------------------
# Note:
# 1. assumes that $log_dir is defined
#----------------------------------------------------------------------------
function load_table
{
load_data_dir=$ 1
file_name=$2
table_name=$3
operation=$4
file_type=$5
echo " loading table: $table_name"
echo " loading table: $table_name" >> ${log_dir}/details.log
db2 " LOAD FROM ${load_data_dir }/${file_name} \
OF ${file_type} \
MESSAGES ${log_dir}/mart3_messages. dat \
WARNINGCOUNT 1 \
$operation INTO ${table_name} \
ALLOW READ ACCESS "\
${log_dir}/details.log
rc=$?
if [ $rc -gt 2 ]; then
print " load error in ${table_name}: rc=$rc"
exit 1
fi
}
#----------------------------------------------------------------------------
# IDENTIFY NEXT LOAD FILE
#----------------------------------------------------------------------------
source_file=`ls ${data_dir}/mart3_ld-????????.dat.ta r.gz | head -n 1`
export logical_date=`e cho $source_file | cut -c44-51`
#----------------------------------------------------------------------------
# BEGIN PRINTING AUDIT TRAIL
#----------------------------------------------------------------------------
echo "============== =============== ======" > ${log_dir}/details.log
echo "= mart3_load starting =" >> ${log_dir}/details.log
echo "= logical date: $logical_date =" >> ${log_dir}/details.log
echo "= source file: $source_file =" >> ${log_dir}/details.log
echo "============== =============== ======" >> ${log_dir}/details.log
echo " " >> ${log_dir}/details.log
#----------------------------------------------------------------------------
# UNCOMPRESS FILE
#----------------------------------------------------------------------------
cp ${data_dir}/mart3_ld-${logical_date) .dat.tar.gz ${temp_dir}
cd ${temp_dir}
`gzip -d ${temp_dir}/mart3_ld-${logical_date) .dat.tar.gz `
rc=$?
if [ $rc -ne 0 ]; then
print " gzip failed with rc=$rc"
exit 1
fi
#----------------------------------------------------------------------------
# UN-TAR FILE
#----------------------------------------------------------------------------
`tar -xvf ${temp_dir}/mart3_ld-${logical_date) .dat.tar`
rc=$?
if [ $rc -ne 127 ]; then
print " tar failed with rc=$rc"
exit 1
fi
#----------------------------------------------------------------------------
# CONNECT TO DATABASE
#----------------------------------------------------------------------------
db2 CONNECT TO mart3
if [ $? -ne 0 ]; then
print " error on database connect"
exit 1
fi
#----------------------------------------------------------------------------
# LOAD FILES
# args: dir, file, table, op, filetype
#----------------------------------------------------------------------------
load_table $temp_dir dim_location.ix f mart3.dim_locat ion replace ixf
load_table $temp_dir dim_state.ixf mart3.dim_state replace ixf
load_table $temp_dir dim_time.ixf mart3.dim_time replace ixf
load_table $temp_dir dim_supplier.ix f mart3.dim_suppl ier replace ixf
load_table $temp_dir dim_customer.ix f mart3.dim_custo mer replace ixf
load_table $temp_dir dim_product.ixf mart3.dim_produ ct replace ixf
load_table $temp_dir fac_labor.ixf mart3.fact_labo r insert ixf
load_table $temp_dir fac_material.ix f mart3.fact_mate rial insert ixf
load_table $temp_dir fac_project.ixf mart3.fact_proj ect insert ixf
load_table $temp_dir fac_revenue.ixf mart3.fact_reve nue insert ixf
#----------------------------------------------------------------------------
# TERMINATE
#----------------------------------------------------------------------------
db2 CONNECT RESET
if [ $? -ne 0 ]; then
print " error on database connect reset at end of process"
exit 1
fi
rm ${temp_dir}/*.dat
rm ${temp_dir}/*.tar
rm ${temp_dir}/*.gz
mv ${data_dir}/mart3_ld-${logical_date) .dat.tar.gz ${archive_dir}
echo "============== =============== ==" > ${log_dir}/details.log
echo "= mart3_load terminating =" >> ${log_dir}/details.log
echo "============== =============== ==" >> ${log_dir}/details.log
echo " " >> ${log_dir}/details.log
mail -s "mart3_load results"
ma***@rpt.acme. com <
${log_dir}/details.log
echo "terminatin g normally"
exit 0