Solved

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

Posted on 2008-10-11
5
885 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

710 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