Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-11
5
Medium Priority
?
893 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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

722 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