Solved

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

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

816 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

7 Experts available now in Live!

Get 1:1 Help Now