Solved

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

Posted on 2008-10-11
5
862 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article is an update and follow-up of my previous article:   Storage 101: common concepts in the IT enterprise storage This time, I expand on more frequently used storage concepts.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 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

21 Experts available now in Live!

Get 1:1 Help Now