Wednesday, September 9, 2009

Tips for dealing with DB2 database samples in your product

In trying to ship a sample of the ITM (IBM Tivoli Monitor) database utilized by our product, we stumbled upon the cross-platform restrictions of the backup/restore commands for DB2, which state:
The supported platforms for DB2 backup and restore operations can be grouped into one of three families:
  • Big-endian Linux® and UNIX®
  • Little-endian Linux and UNIX
  • Windows®
After hours of fiddling with DB2 manuals and succeeding partially in moving the data from an DB2 in AIX 64 bits to a Windows 32 bits machune, I eventually stumbled upon this great developerWorks article, fittingly titled: Using DB2 utilities to clone databases across different platforms.

Essentially it uses a combination of the “db2move” and “db2look” commands, like this:

Exporting the data

To export the contents of the database, change to the directory where the exported directory where the files should be written and run:
db2move WAREHOUS export -sn ITMUSER
db2look -d WAREHOUS -e -a -o db2look.sql
where WAREHOUS is the name of the database I was exporting and ITMUSER the schema for it.

Importing the data

Copy over the files to the target machine and change to the directory where the exported files are. Then run the command:
db2 “create db WAREHOUS”
db2 –tvf db2look.sql

db2move WAREHOUS import
where WAREHOUS is the name of the database you are importing.

You can use a different database name, but you need to edit the first line of the db2look.sql file to match the name.

No comments:

Post a Comment