Solved

How to create a batch file to check if a file is in use by another program?

Posted on 2008-10-11
5
882 Views
Last Modified: 2013-11-10
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.

0
Comment
Question by:Psychoboy
  • 2
  • 2
5 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 22695518

:This script renames the file to determine whether it is still in use.  If it is, the rename will fail.
 
C:
cd C:\backups
if exist file.check copy/y file.check file.prev
del file.check 1>nul 2>nul

:Loop
ren  file.lsb   file.check
if exist file.check goto :commvault
ping -n 600 localhost 1>nul 2>nul
goto :Loop

:commvault
ren  file.check  file.lsb
:do your commvault stuff here
0
 

Author Comment

by:Psychoboy
ID: 22697695
Exactly what I need.  I will try it out and see how it works.

Thanks
0
 

Author Comment

by:Psychoboy
ID: 22817297
knightEknight,

Is it possible to add a log to this script to confirm or deny if the script ran or not?
Thanks
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 22817367
C:
cd C:\backups
if exist file.check copy/y file.check file.prev
if exist file.check del/y file.check 1>nul 2>nul

if exist log.txt ren log.txt log.prev
echo %date% %time% > log.txt
:Loop
ren  file.lsb   file.check
if exist file.check goto :commvault
echo Looping ... >> log.txt
ping -n 600 localhost 1>nul 2>nul
goto :Loop

:commvault
ren  file.check  file.lsb
:do your commvault stuff here

echo Done. >> log.txt
0
 
LVL 6

Accepted Solution

by:
squify earned 500 total points
ID: 23295059
I would suggest not using Litespeed to backup the Database. Simply use the CommVault SQL iData agent to do the backup which will simplify the entire process and reduce the risk of something failing.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VM backups can be lost due to a number of reasons: accidental backup deletion, backup file corruption, disk failure, lost or stolen hardware, malicious attack, or due to some other undesired and unpredicted event. Thus, having more than one copy of …
Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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