Saving and restoring spooled files

You can use any of the methods that are described here to save and restore spooled files.

Table 1. Save and restore spooled files
Save Methods Restore Methods Spooled file attributes preserved
SAVLIB, SAVOBJ, SAVCHGOBJ, SAVRSTLIB, SAVRSTOBJ, SAVRSTCHG commands RSTLIB, RSTOBJ, SAVRSTLIB, SAVRSTOBJ, SAVRSTCHG commands Data and all attributes
QSRSAVO API QSRRSTO API Data and all attributes
Save menu options 21-23 Restore menu options 21-23 Data and all attributes
QSPOPNSP, QSPGETSP, QUSRSPLA APIs QSPCRTSP, QSPPUTSP, QSPCLOSP APIs Data, but not all attributes1
CPYSPLF, SAVOBJ commands CPYF command Textual data only1

1For releases before IBM® i V5R4, you must use one of these methods for saving and restoring spooled files. These methods do not preserve all of the spooled file attributes.

When you save an output queue with the SAVLIB or SAVOBJ commands, SAVE menu, or QSRSAVO API, you can choose to save all its spooled files. You can do this by specifying *ALL for the Spooled file data (SPLFDTA) command parameter, menu prompt, or API key.

When you save an output queue with the SAVCHGOBJ command, you can choose to save its new spooled files that were created after the reference date and time. You can do this by specifying *NEW for the Spooled file data (SPLFDTA) command parameter.

When you restore output queues with the restore commands, menu, or QSRRSTO API, you can choose to restore any saved spooled files that do not already exist on the system. You can do this by specifying *NEW for the SPLFDTA parameter, prompt, or key.

With the QSRSAVO and QSRRSTO APIs, you can also choose to save or restore spooled files by using a set of selection criteria. If you save spooled files with the QSRSAVO API using selection criteria and the *SPLF special library value, then you must use the QSRRSTO API with the *SPLF special library value to restore the spooled files.

The QSRSAVO and QSRRSTO APIs also allow you to change the expiration date of the spooled files. The QSRRSTO API also allows you to restore spooled files to a different output queue and allows you to create an additional copy of existing spooled files.

This example describes how to save spooled files:
  1. Create an output queue to store the spooled files.
    CRTOUTQ  OUTQ(lib-name/que-name) 
  2. Use the Work with Spooled File (WRKSPLF) command to list the spooled files.
  3. Use option 2, Change Spooled File Attributes (CHGSPLFA) command to move the spooled files you want to save to the output queue you created.
  4. Use the Save Object (SAVOBJ) command to save the spooled file data.
    SAVOBJ  OBJ(que-name) LIB(lib-name) DEV(dev-name) OBJTYPE(*OUTQ) SPLFDTA(*ALL)
This example describes how to restore spooled files:
  1. Restore spooled files that are not already on the system.
    RSTOBJ  OBJ(que-name) SAVLIB(lib-name) DEV(dev-name) 
            OBJTYPE(*OUTQ) SPLFDTA(*NEW)

Using spooled file APIs

If your source or target system is earlier than V5R4, you can use spooled file APIs as an indirect method to save and restore spooled files. This method preserves the spooled file data stream but not all of the attributes.

To save spooled files:
  • The spooled files are opened using the Open Spooled File (QSPOPNSP) API.
  • The spooled file data is retrieved using the Get Spooled File Data (QSPGETSP) API.
  • The spooled file attributes are retrieved using the User Spooled File Attributes (QUSRSPLA) API.
To restore spooled files:
  1. The spooled files are created using the Create Spooled File (QSPCRTSP) API.
  2. The spooled file data is written to a new spooled file using the Put Spooled File Data (QSPPUTSP) API.
  3. The spooled file is closed using the Close Spooled File (QSPCLOSP) API.

You can find an example and a tool for using these APIs in the QUSRTOOL library in the TSRINFO member of the QATTINFO file.

Copying spooled files to database files

If your source or target system is earlier than V5R4, you can copy data between spooled files and database files as an indirect method to save and restore spooled files. This method copies textual data only and not advanced function attributes such as graphics and variable fonts. This method does not provide a complete solution for saving your spooled files.

The Copy Spooled File (CPYSPLF) command saves spooled file data to a database file. The Copy File (CPYF) command can copy data from a database file to a spooled file.