Admin Alert: A Simple Save While Active Backup Program
June 17, 2009 Joe Hertvik
The problem with 24×7 environments is that it’s difficult to make time to run complete system backups. Modern processing needs dictate that you can rarely, if ever, take down your machine to back up the entire system. This week, I’ll look at a hybrid backup scheme that lets you achieve the dual goal of performing occasional full system backups while still saving all your critical system and user data.
A Simple Strategy
The following is a simple save strategy that you may be able to use in your shop. It consists of two system backup elements that allow you to occasionally perform a complete system backup while maintaining nightly backups of your most important data.
While this scheme does not provide complete 24×7 availability because you still need to run occasional full system backups, it does provides most of the tools you’ll need to backup your system with minimal disruption.
The Full System Backup
i5/OS full system backups are performed by running option 21 off the Save menu (GO SAVE). A full system backup provides a baseline picture of your system that can be used to restore the entire system in the event of a disaster. To perform a full system backup, simply select option 21, Entire System, off the Save menu and the operating system will prompt you for all the parameters it needs to take a complete snapshot of your entire system. For a complete picture of how an option 21 backup works, check out this article that discusses in detail how an option 21 save works.
Between the Full Backups
The problem with an option 21 save is that you may not be able to save your entire system every night, due to processing commitments. To fill in the gaps and to make sure that I can restore most objects that are changed between full system backups, I wrote the following CL program that saves all critical and changed objects every night. The name of the program is NGHTLYBKP and this is the code I use to back up the system on off-nights.
0001.00 PGM PARM(&TAPDEV) 0002.00 0003.00 DCL VAR(&TAPDEV) TYPE(*CHAR) LEN(6) 0004.00 DCL VAR(&TAPDEVLNG) TYPE(*CHAR) LEN(40) + 0005.00 VALUE('/QSYS.LIB/') 0006.00 DCL VAR(&TAPDEVEND) TYPE(*CHAR) LEN(5) + 0007.00 VALUE('.DEVD') 0008.00 0009.00 CHGVAR VAR(&TAPDEVLNG) VALUE(&TAPDEVLNG *TCAT + 0010.00 &TAPDEV *TCAT &TAPDEVEND) /* set up + 0011.00 parameter for saving to tape device in + 0012.00 the SAV command */ 0013.00 0014.00 CLRMSGQ MSGQ(QUSRSYS/SAVEMSGQ) /* Clear out old save + 0015.00 messages before starting */ 0016.00 0017.00 SAVSECDTA DEV(&TAPDEV) ENDOPT(*LEAVE) /* Save user + 0018.00 profiles, private authorities, and other + 0019.00 security data */ 0020.00 0021.00 SAVCFG DEV(&TAPDEV) ENDOPT(*LEAVE) /* Save all + 0022.00 current configurations */ 0023.00 0024.00 SAVCHGOBJ OBJ(*ALL) LIB(*ALLUSR) DEV(&TAPDEV) + 0025.00 OBJJRN(*YES) ENDOPT(*LEAVE) UPDHST(*NO) + 0026.00 SAVACT(*SYNCLIB) SAVACTWAIT(60) + 0027.00 SAVACTMSGQ(QUSRSYS/SAVEMSGQ) ACCPTH(*YES) + 0028.00 QDTA(*DTAQ) + 0029.00 OUTPUT(*OUTFILE) + 0030.00 OUTFILE(QUSRSYS/SAVCHGOBJ) INFTYPE(*ERR) + 0031.00 /* Save all library objects that were + 0032.00 changed since the last backup */ 0033.00 MONMSG MSGID(CPF3778) /* Ignore message CPF3778 - + 0034.00 Not all objects saved from all libraries */ 0035.00 0036.00 0037.00 SAVDLO DLO(*SEARCH) DEV(&TAPDEV) + 0038.00 REFCHGDATE(*SAVDLOALL) ENDOPT(*LEAVE) + 0039.00 SAVACT(*YES) SAVACTWAIT(60) /* Save all + 0040.00 Document Library objects changed since + 0041.00 last backup */ 0042.00 MONMSG MSGID(CPF906B) 0043.00 0044.00 SAV DEV(&TAPDEVLNG) OBJ(('/*') ('/QSYS.LIB' + 0045.00 *OMIT) ('/QDLS' *OMIT)) SAVACT(*SYNC) + 0046.00 OUTPUT(*PRINT) ENDOPT(*LEAVE) + 0047.00 SAVACTMSGQ('/QSYS.LIB/QUSRSYS.LIB/SAVEMSGQ.+ 0048.00 MSGQ') INFTYPE(*ALL) CHGPERIOD(*LASTSAVE) + 0049.00 /* Save all IFS objects except for the + 0050.00 QSYS.LIB folder and the DLO objects */ 0051.00 MONMSG MSGID(CPF3837) 0052.00 0053.00 DSPJOBLOG OUTPUT(*PRINT) /* Print out the joblog for + 0054.00 review later on */ 0055.00 0056.00 0057.00 DSPTAP DEV(&TAPDEV) DATA(*SAVRST) OUTPUT(*PRINT) /* + 0058.00 Display tape contents for review, if + 0059.00 needed */ 0060.00 0061.00 ENDPGM
Here’s what each piece of code does.
Line 1.00–The calling user passes in the name of the backup media device to use in the &TAPDEV parameter. By passing in the device name, I can easily change the media save device name by changing the program call statement, instead of changing and recompiling the program.
Lines 3.00-12.00–Program variables are defined for the media device name (&TAPDEV), as well as for the AS/400 Integrated File System (AS/400 IFS) name of the media device name (&TAPDEVLNG). An AS/400 IFS name consists of a specific designation that pinpoints exactly where in the IFS the device is located. Lines 9.00-12.00 build the AS/400 IFS name of the device where I will be saving the data.
Lines 14.00-15.00–Clears out the message queue that will contain any messages arising from the programs save commands. In this CL, all messages are saved to the SAVEMSGQ message queue in library QUSRSYS. Saving messages to a separate message queue allows you to view the messages apart from messages in other public message queues on the system, such as QSYSOPR. Before attempting to run this program, make sure to create the SAVEMSGQ message queue.
Lines 17.00-22.00–These commands save critical system data that may change from day to day. Lines 17.00-18.00 save all the system security data (user profiles, private authorities, etc.) by using the Save Security Data (SAVSECDTA) command, while lines 21.00-22.00 save all the device configuration data (display devices, printer devices, RF devices, etc) by using the Save Configuration (SAVCFG) command. Since user profiles and devices can be created on the system every day, you need to back them up between your full system backups.
Lines 24.00-32.00–The Save Changed Objects (SAVCHGOBJ) command saves all the user library objects (*ALLUSR) that have changed since the last time those objects were saved during the full system backup. Furthermore, this command will save objects while they are in use. All of the objects and the libraries saved by this command reach their save checkpoints together and they are saved in a consistent state in relationship to each other (they are saved as a set). Here’s how each of the SAVCHGOBJ parameters affect command execution:
Line 33.00-35.00–Contains a Monitor Message (MONMSG) command that tells the program to ignore message CPF3778 (not all objects saved from all libraries) if that message is issued as a result of the SAVCHGOBJ command. CPF3778 is an informational message that has no effect on command processing.
Lines 37.00-41.00–Using the Save Document Library Object (SAVDLO) command, this code saves all the changed Document Library Object (DLO) objects that were updated or added since the last backup. It designates that it should save all newly changed objects by designating *SEARCH in the Document Library Object (DLO) parameter and *SAVDLOALL in the Last Changed Date (REFCHGDATE) parameter. *SAVDLOALL tells the command to save all objects that have been added or updated since the last backup. This command also saves objects while they are active (Save Active parameter = *YES) and it will give up trying to save held objects after 60 seconds (Save Active Wait Time parameter = 60).
Line 42.00–The program uses another MONMSG command to prevent the CPF906B message (No document library objects saved) from holding up program execution, if it is generated by the SAVDLO command.
Lines 44.00-50.00–The Save (SAV) command is used to save AS/400 IFS objects that have changed since the last full system backup. It does this by setting the Time Period for Last Change (CHGPERIOD) parameter to *LASTSAVE, which tells the command to save any object that was changed since the last time the object had its Update History parameter turned on. In addition, this command synchronizes the backup so that all changed objects are saved even if they are in use; that all saved objects reach their save checkpoint at the same time (Save Active parameter = *SYNC); and that all messages are sent out to the message queue specified in the Save Active Message Queue (SAVACTMSGQ) parameter.
Line 51.00–Like the other save commands, the program monitors the SAV command to ignore message CPF3837 (&1 objects saved, &2 not saved) if it is issued, so that the program does not stop if that message is displayed.
Lines 53.00-59.00–These lines output the job’s job log information, through the Display Job Log (DSPJOBLOB) command, to a printer file. They also output the Save Restore information on the tape to a spooled file, through the Display Tape (DSPTAP) command. These reports allow the operator to review the results of the save whenever he wishes.
Line 61.00–The End Program (ENDPGM) command ends program processing.
By running the NGHTLYBKP program on a daily basis, you can save most updated configuration and user objects to media on a save-while-active basis without disrupting system processing. With the option 21 save and this save-while-active backup shell, you have two different sets of backup media that contain a baseline of your system along with any database or configuration changes that were made after the option 21 media was created. This minimizes the amount of downtime you need to securely back up your system while other people are using it.