The following article describes how to migrate and export a DB2 Database in a Linux operating system. We all know that DB2 Universal Database™(DB2 UDB) has a very useful tool to help you implement this cross-platform backup and recovery function.
The db2move tool uses the DB2 data movement tool export and import or load to move database tables. However, because the database content is far more than the user table, you need to use other methods to migrate other database objects between different databases, such as constraints, triggers, indexes, sequences, tablespaces, and buffer pools.
This is why the db2look tool appears. With this tool, you can capture the Data Definition Language DDL used to define these objects in the source database) and recreate these objects in the target database using these data definition languages.
1. Environment Description:
DB2 database migration is named sample, SCHEMA is also oatest, and username is oatest
2. Export Steps:
(1) create a new directory. If you need to pay attention to the permission of the directory in linux, the directory should be accessible by db2inst1 users.
- [db2inst1@devsvr2 db2inst1]$ pwd
- /home/db2inst1
- [db2inst1@devsvr2 db2inst1]$ mkdir oatest0303
- [db2inst1@devsvr2 db2inst1]$ ls
- db2inst1 db2test Desktop oatest0303 sqllib
(2) enter this directory
- [db2inst1@devsvr2 db2inst1]$ cd oatest0303/
- [db2inst1@devsvr2 oatest0303]$
(3) Use the database Extraction Tool db2look to export the database structure
Main commands
- db2look -d sample -e -z oatest -l -o oatest.sql
- [db2inst1@devsvr2 oatest0303]$ db2look -d sample -e -z oatest -l -o oatest.sql
No user id is specified. db2look tries to use the environment variable USER
USER: DB2INST1
The specified mode is OATEST.
Create Table DDL
The Mode name of the union is ignored.
Output is sent to the file: oatest. SQL
The script includes the DDL statements used to create bufferpool and tablespace during DB2 database migration.
(4) use the db2move tool to export database data
Main commands
- db2move sample export
- [db2inst1@devsvr2 oatest0303]$ db2move sample export
- ***** DB2MOVE *****
- Action: EXPORT
- Start time: Sun Mar 5 11:00:52 2006
- Connecting to database SAMPLE ... successful! Server: DB2 Common Server V8.2.0
- EXPORT: 0 rows from table "OATEST "."ATTACHFILE"
- EXPORT: 0 rows from table "OATEST "."BASE"
- ……
(5) package and compress the oatest0303/
Main commands:
- tar zcvf oatest0303.tar.gz oatest0303/
- [db2inst1@devsvr2 oatest0303]$ cd ..
- [db2inst1@devsvr2 db2inst1]$ tar zcvf oatest0303.tar.gz oatest0303/
- oatest0303/
- oatest0303/oatest.sql
- oatest0303/EXPORT.out
- oatest0303/db2move.lst
- oatest0303/tab1.msg
- oatest0303/tab1.ixf
- ……
The above content is an introduction to the steps for migrating and exporting DB2 databases on the Linux platform. I hope you will have some gains.