How do I find all files locked in a specified set of libraries, to ensure my backups run?

Posted on 2009-02-20
Last Modified: 2013-12-06
I am trying to determine how I can obtain a quick report of all files locked in a specific set of libraries.  The reason I need this is that I never know util after my backup runs whether or not there is a lock on a file.  Once the backup is complete, then it's a major issue in some cases to backup only the files that were missed because of file locks.  I have been supporting this AS400 for 6 years and I know enough to keep it running, but am in no way a guru and have not had any significant training on all the commands and how to use them.  It just seems to me that there should be a way to do this.
Question by:evel1959
    LVL 34

    Accepted Solution

    First, if you are responsible for AS/400 backups, take a few minutes and at least skim the Backup and Recovery Guide for your OS version.  Here's a link to the guide for V5R4, since you didn't mention a version:

    The standard practice for basic daily backups (system not in a restricted state), you would be:

    • Notify users
    • End interactive subsystems and jobs.
    • Terminate never-ending batch and server jobs.
    • Wait for running batch jobs to end.
    • Hold job queues for any subsystems not ended
    • Perform backups once system is quiesced
    This practice generally prevents locks from happening, and ensures a clean backup.  The real trick to unattended, daily non-restricted state backups is understanding what processes are incompatible with your backup strategy, and making sure they are ended and restarted properly before and after the backup.  Most shops have a process that runs to prepare the system for backup, run the daily backups, and restart services and subsystems.

    There are lots of ways to handle backups.  Is your backup attended or unattended?  

    If it is attended, then PRECHECK(*YES) is a good alternative:

    All of the backup commands (SAV*) offer a pre-check parameter for just this purpose.  Specifying PRECHK(*YES) guarantees an "all-or-nothing" backup.  If any object is locked, the backup fails and returns an error message to the operations with the name of the failing object.  The operator can take corrective actions, and resubmitthe backup.

    If your backups are unattended, then you want to use the standard process above of ending all the subsystems except the backup subsystem, preventing new jobs from starting, and allowing all currently running jobs to complete.  Once the system is quiesced, you launch the backup, and log any failures that occur.  In an unattended backup, you won't want to precheck, usually.  You will generally want to make as complete a backup as possible, and manually handle any exceptions the next day.

    The SAV* command s also have options for producing reports or output files of objects thate were or were not backed up.  See the OUTPUT and INFTYPE parameters:

    AS/400 backup commands offer options for backing object that are locked or in use (Save-while-active), and strategies for backing up files that are in use by mission critical process that cannot be shut down for backups (journaling, remote journaling).  If you plan to implement these more sophisticated strategies, and have continuous uptime requirements, you probably need to involve and expert.

    Anyway, can be a complicated process, and designing a backup strategy that works requires knowing a lot about the system availability needs of the business, the applications that run on the system, and the backup and recovery capabilites of the system.

    Hope this helps.  Feel free to post back if you have specific questions.

    You'll be amazed at how much you'll learn with even just a quick skim through the Backup and Recovery Manual.  Invest an hour or two.

    - Gary Patterson

    PS.  The CHKOBJ command can be used in a CL program to determine if a particular object is locked.  You can easily write a CL that creates a list of files in a library, and then runs a CHKOBJ on each of those files or objects to see if it is locked:

    DSPOBJD OUTPUT(*OUTFILE) will allow you to dump a list of object names to a file.
    RCVF can be used to read the file one record at a time
    CHKOBJ can check for locks and adequate authority

    The catch is, that if a problem is discovered, manual intervention is almost always needed.
    LVL 26

    Assisted Solution

    Minor note... Using CHKOBJ might not give useful results. Using ALCOBJ might be more appropriate. Also, timing is important. If it takes time to process any list of objects, a new lock from something external can be established on any object near the beginning of the list while objects later in the list are being processed.

    But Gary has given excellent comments as usual. Pay attention to them.


    Author Closing Comment

    Thanks for the guidance.  I appreciate the help.  I was hoping to have something that would quickly check all objects in a library set, but I can see that it would probably be too much work.  I think I'll invest my time in the manual provided.
    LVL 34

    Expert Comment

    by:Gary Patterson
    Tom is right, of course:

    ALCOBJ is a better solution than CHKOBJ in many cases:

    CHKOBJ checks to see if RIGHT AT THAT SECOND a lock exists.

    ALCOBJ actually grabs a lock of the type that you specify on an object, and holds it until you either explicitly release the lock using the DLCOBJ command, or until the job allocating the object ends.

    - Gary Patterson
    LVL 26

    Expert Comment

    ALCOBJ also nowadays has the CONFLICT() parameter which can be of real use in situations like this thread.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction Often we come across situations wherein our batch files would be needing to reboot Windows for a variety of reasons. A few of them would be like: (1) Setup files have been updated whose changes can take effect only after a reboot …
    In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now