Examples of schema copy by using the db2move utility

Use the db2move utility with the -co COPY action to copy one or more schemas from a source database to a target database. After a model schema is established, you can use it as a template for creating new versions.

Example 1: Using the -c COPY options
The following example of the db2move -co COPY options copies the schema BAR and renames it FOO from the sample database to the target database:
    db2move sample COPY -sn BAR -co target_db  target schema_map 
      "((BAR,FOO))" -u userid -p password                      

The new (target) schema objects are created by using the same object names as the objects in the source schema, but with the target schema qualifier. It is possible to create copies of tables with or without the data from the source table. The source and target databases can be on different systems.

Example 2: Specifying table space name mappings during the COPY operation
The following example shows how to specify specific table space name mappings to be used instead of the table spaces from the source system during a db2move COPY operation. You can specify the SYS_ANY keyword to indicate that the target table space must be chosen by using the default table space selection algorithm. In this case, the db2move utility chooses any available table space to be used as the target:
    db2move sample COPY -sn BAR -co target_db  target schema_map      
      "((BAR,FOO))" tablespace_map "(SYS_ANY)" -u userid -p password
The SYS_ANY keyword can be used for all table spaces, or you can specify specific mappings for some table spaces, and the default table space selection algorithm for the remaining:
    db2move sample COPY -sn BAR -co target_db  target schema_map "   
      ((BAR,FOO))" tablespace_map "((TS1, TS2),(TS3, TS4), SYS_ANY)" 
      -u userid -p password                                         
This indicates that table space TS1 is mapped to TS2, TS3 is mapped to TS4, but the remaining table spaces use a default table space selection algorithm.
Example 3: Changing the object owners after the COPY operation
You can change the owner of each new object created in the target schema after a successful COPY. The default owner of the target objects is the connect user. If this option is specified, ownership is transferred to a new owner as demonstrated:
    db2move sample COPY -sn BAR -co target_db  target schema_map
      "((BAR,FOO))" tablespace_map "(SYS_ANY)" owner jrichards
      -u userid -p password
The new owner of the target objects is jrichards.

The db2move utility must be started on the target system if source and target schemas are found on different systems. For copying schemas from one database to another, this action requires a list of schema names to be copied from a source database, separated by commas, and a target database name.

To copy a schema, issue db2move from an operating system command prompt as follows:
     db2move dbname COPY -co COPY-options 
      -u userid -p password