Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 645
  • Last Modified:

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

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.
  • 2
  • 2
2 Solutions
Gary PattersonVP Technology / Senior Consultant Commented:
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.
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.

evel1959Author Commented:
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.
Gary PattersonVP Technology / Senior Consultant Commented:
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
ALCOBJ also nowadays has the CONFLICT() parameter which can be of real use in situations like this thread.


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now