How to create a batch file to check if a file is in use by another program?
Posted on 2008-10-11
Here is an overview of what the problem is and how I can resolve this (with your help)
Everynight a SQL DB gets backed up to local disk (flat file) using Quest Litespeed. I also need to backup the backup file to tape using Commvault. Each night the DB backup flat file gets overwritten with the new backup so at any given time, we have one DB backup on disk.
The problem is that sometimes the Litespeed backup runs longer than it should, and when the scheduled Commvault backup to tape kicks off, it skips the Litespeed backup because it is being used by another process.
Commvault has feature called pre-backup process. This can be a script or program that will run and must complete before the tape backup will begin.
Basically If we can write a simple batch file that can do these things, i can ensure that I backup my backup every day.
1. The script should check to see if file.lsb (lsb is the extension of the LiteSpeed backup) is in use.
2. If it is in use, the batch file will stay open but start a loop to check after X number of minutes if the file is still in use.
3. Once the check finds the file.lsb is not in use, it can close gracefully. I am assuming commvault will see that the prebackup process is done and it can continue its tape backup.
Your help is greatly appreciated.