The DB2 COPY utility

COPY is how DB2 for z/OS takes image copies of table spaces and copyable indexes. RECOVER later restores those data sets and applies the log. This page covers COPY TABLESPACE, COPY INDEX, COPYDDN / RECOVERYDDN, full versus incremental copies, and SHRLEVEL.

Db2 utilities
Progress0 of 0 lessons

COPY TABLESPACE

Name the database and table space. Optional DSNUM copies one partition or data set. LIST copies a LISTDEF of objects in one utility statement.

text
1
2
3
4
COPY TABLESPACE HRDB.HRTS COPYDDN(SYSCOPY) FULL YES SHRLEVEL REFERENCE

JCL needs SYSIN, SYSPRINT, and the COPYDDN data set (traditional name SYSCOPY). Many shops use TEMPLATE with GDG (+1) so each copy is a new generation. The utility inserts a row in SYSIBM.SYSCOPY with DSNAME, ICTYPE, SHRLEVEL, START_RBA / PIT_RBA, TIMESTAMP, and DSNUM.

COPY INDEX

Indexes are created COPY NO by default. ALTER INDEX … COPY YES (or CREATE INDEX COPY YES) makes the index space eligible for COPY and RECOVER instead of only REBUILD INDEX. Incremental copies of indexes are not supported: if a LIST mixes a table space FULL NO with an index, COPY takes a full copy of the index and does not fail the list. A statement that names only an index with FULL NO fails.

text
1
2
3
4
COPY INDEX HR.XEMP1 COPYDDN(IXCOPY) FULL YES SHRLEVEL REFERENCE

COPYDDN and RECOVERYDDN

Both options take one or two names: primary and optional backup.

  • COPYDDN(dd1, dd2) — local site image copies
  • RECOVERYDDN(dd1, dd2) — recovery-site copies for disaster restart

You do not have to take local and remote copies in the same job. If remote copies are less frequent, DR recovery uses an older full copy plus more log. IBM documents that incremental COPY for a site can fail RC 8 if the full/incremental history is not aligned between local and recovery sites—take a fresh full for both, or incremental only for the site you are on.

text
1
2
3
4
5
6
TEMPLATE LOC DSN HR.COPY.&DB..&TS..L.&DATE. TEMPLATE REM DSN HR.COPY.&DB..&TS..R.&DATE. COPY TABLESPACE HRDB.HRTS COPYDDN(LOC) RECOVERYDDN(REM) FULL YES SHRLEVEL REFERENCE

Full image copies

FULL option
OptionMeaning
FULL YESAll allocated pages; resets COPY-pending; valid for table spaces and COPY YES indexes
FULL NOIncremental: pages changed since last copy; not valid for indexes; needs TRACKMOD for speed

A full copy is a complete backup of the pages in the object (or partition). It is the base of every recovery chain. After LOAD LOG NO, REORG LOG NO, or other COPY-pending events, you need a full copy (or an inline COPYDDN on the utility) before the object is backup-clean. FlashCopy image copies are data-set-level full copies; they are not incremental.

Incremental image copies

FULL NO copies pages that changed since the last full or incremental copy. Space maps (when TRACKMOD YES) let COPY skip unchanged pages, which is why incrementals are faster on large, lightly updated spaces. TRACKMOD NO still produces a smaller sequential file but may scan more like a full copy.

IBM prerequisites:

  • A full image copy already exists
  • COPY-pending is not on
  • The last copy did not use the CONCURRENT option
text
1
2
3
COPY TABLESPACE DSN8D12A.DSN8S12E FULL NO SHRLEVEL CHANGE

MERGECOPY later merges incrementals into a new full copy so RECOVER does not need a long incremental chain. Some catalog/directory objects always force a full copy.

SHRLEVEL options

COPY SHRLEVEL
OptionMeaning
SHRLEVEL REFERENCERead-only during COPY; default in IBM teaching for consistent copies
SHRLEVEL CHANGERead and write allowed; copy is fuzzy; plan PIT_RBA for recover

REFERENCE drains writers so SELECT can run but UPDATE cannot. It is the copy you want if you plan to RECOVER TOCOPY / TOLASTCOPY. CHANGE claims the read class so inserts and updates continue; do not treat the data set as a crash-consistent instant. CONCURRENT (DFSMSdss concurrent copy) has extra page-size versus CI-size rules: SHRLEVEL CHANGE is not allowed for some large page sizes when the CI does not match.

A DELETE without WHERE on a segmented space is a documented exception that can conflict with COPY SHRLEVEL CHANGE—know that restriction before you schedule overnight copies during batch.

JCL sketch

text
1
2
3
4
5
6
7
8
9
10
//COPYTS EXEC DSNUPROC,SYSTEM=DB2T,UID='HR.COPY.HRTS' //SYSCOPY DD DSN=HR.COPY.HRTS(+1),DISP=(NEW,CATLG,DELETE), // UNIT=SYSDA,SPACE=(CYL,(50,10),RLSE) //SYSPRINT DD SYSOUT=* //SYSIN DD * COPY TABLESPACE HRDB.HRTS COPYDDN(SYSCOPY) FULL YES SHRLEVEL REFERENCE /*

REPORT RECOVERY and a SELECT from SYSIBM.SYSCOPY are how you verify the copy landed before you need it. The RECOVER utility page shows how those SYSCOPY rows are consumed.

Explain It Like I'm Five

COPY is taking a photograph of the classroom. A full photo shows every desk. An incremental photo shows only desks that changed since the last picture. COPYDDN is the album you keep at school; RECOVERYDDN is the album you mail to the backup school. SHRLEVEL REFERENCE means “nobody move while I take the picture.” SHRLEVEL CHANGE means “keep playing; the photo might show a kid in two places.” RECOVER later uses the album plus the diary (the log) to rebuild the room.

Exercises

  1. Write COPY FULL YES SHRLEVEL REFERENCE for a table space with a GDG COPYDDN.
  2. List three reasons FULL NO would be rejected.
  3. Explain when you would add RECOVERYDDN in the same job versus a later COPYTOCOPY.
  4. Query SYSIBM.SYSCOPY for your table space and identify ICTYPE, DSNAME, and SHRLEVEL.
  5. Find an index that is COPY NO and write the ALTER needed before COPY INDEX.

Quiz

Test Your Knowledge

1. FULL YES versus FULL NO on COPY means:

  • YES copies indexes only
  • YES is a full image copy; NO is incremental (changed pages since the last copy). FULL NO is not valid for indexes
  • NO skips SYSIBM.SYSCOPY
  • YES requires the table space to be dropped

2. COPYDDN names:

  • Only the BSDS
  • Local-site primary and optional backup image-copy data sets (ddname1, ddname2)
  • Only archive logs
  • Only SYSUT1

3. SHRLEVEL REFERENCE allows:

  • Updates during COPY
  • Read-only concurrent access; writers are drained
  • No SQL at all including SELECT
  • Only LOAD

4. A prerequisite for incremental COPY is:

  • No full copy has ever been taken
  • A full image copy exists and COPY-pending is not on (and the last copy was not CONCURRENT)
  • The index is COPY NO
  • You must specify FROMCOPY

5. COPY INDEX requires:

  • Nothing special
  • The index defined or altered COPY YES
  • FULL NO always
  • DSNDB07