Windows Scripting to execute BUTIL command for PSQL on multiple files based on conditions containing wildcards

Posted on 2008-10-03
Last Modified: 2013-12-25
We need to use a utility from Pervasive SQL to put data files into continuous operations mode for backup purposes. The following works to put "file" into continous mode, however, the command does not support wildcards.

butil -startbu C:\data\files\file

Their utility does not support wildcards. We need to put any file ending with EXA into continuous mode, and "butil -startbu C:\data\files\*EXA" will return a syntax error.

The butil utility supports using a text file as a list, so that might help up work around this limitation. The butil only properly supports absolute paths, not relative. Initially my idea was to run a "dir *EXA /B > temp.txt" and use that file as a list, however it does not output absolute path names.

Would be best way to do this be with a batch file or a vb script? I am not too familiar with VB scripts.
The command syntax is as follows:
BUTIL -STARTBU <sourceFile | @listFile> [/UID<name> </PWD<word>> [/DB<name>]]

Open in new window

Question by:bradl3y
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
  • 4
  • 3
  • 2
LVL 28

Expert Comment

by:Bill Bach
ID: 22637084
    DIR *.EXA /s /b <files.lst
Then, edit the resulting file to remove any files that you do not want, or to add any others that you do.  Finally, call BUTIL with a command like this:
    BUTIL -STARTBU @files.lst

More detail, if this gets used as a solution:

A good white paper on Continuous Operations mode can be found here:
(Get the white paper on obtaining proper database backups.)

In short, the ways to do this include:
1) Use the Pervasive Backup Agent.  Supported on PSQLV8 and newer, this automatically  puts any open files into continuous mode for backup.  
2) Use BUTIL with a list file.  Doing this requires that you create a list file first, as it looks like you are trying to do, but the pathnames must be "engine-relative".  You can create this list with the aforementioned command easily enough.
3) Use a command-line script.  Something like this would also work,
    for %f in (*.EXA) do BUTIL -STARTBU %f
Although it is not as "correct":, since each file gets put into continuous mode independently, and related files may have different timestamps, leading to data issues.
4) Use a program to do the same thing.  A tool from Goldstar Software called GSBackup can help automate this process, and can even accept *.* as an option, as it examines each file before putting it into ContOps mode for you.

Author Comment

ID: 22637111
I found that using the /S flag with dir will output full path names.

There is still a problem in that if there is any entry in the list which fails, the entire command fails. In this case, it seems some of the files arent MicroKernel data files, causing the command to fail.

There is no way to tell from the file name that i know of which are microkenrel files. The best way to workaround this that i can think of would be to create a script to run the command on each entry in the list individually. I would not know how to create a batch file to do that.

Is there a better solution that anyone can think of or can someone show me how such a script would work? To read a file line by line and put the contents of that line into a command?
LVL 28

Accepted Solution

Bill Bach earned 300 total points
ID: 22637185
You are correct -- all files in the list MUST be present, and all MUST be Btrieve files.  Otherwise the command fails.  The tool HoldOpen, available at accepts the SAME file as BUTIL, and it reports which files fail to open properly.  You can use this to quickly pare down thye list to only those files that are "real" database files.

If you choose to run a scriupt to do each file separately, please remember that the files will no longer all share the same "snapshot".  For example, in a banking scenario, this means that the Savings accounts file could be different by one or more minutes from the Checking Accounts file.  If someone did a transfer from one to the other during the backup window, and you had to rely on this backup, you might find that the money was pulled out of one account (because that files was snapshotted AFTER the transfer), but never added to the other (because that file was snapshotted BEFORE the transfer).  I admit that the time difference may be small, but just keep this in mind.

To answer your last question, the tool MakeBAT can be found at the same location.  A command like this would also work for you:
    MAKEBAT "BUTIL -STARTBU " <files.lst >batchscript.bat

Luckily, no matter what you do, using BUTIL -ENDBU /A will close ALL files out of ContOps mode.
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.


Assisted Solution

Hubasan earned 200 total points
ID: 22637325
Hi bradl3y,

If you want to run your command on each individual file that has EXA extension in that particular folder you can use this script:
' List All the Files in a Folder
Set oWS = CreateObject("")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
    ExecQuery("Select * from CIM_DataFile where Drive = 'C:' and Path = '\\data\\files\\'")
For Each objFile in colFiles
	sFilePath = objFile.Name
	sExt = ".exa"
	If InStr(sFilePath, sExt) Then
		oWS.Run "%comspec% /c BUTIL -STARTBU " & sFilePath & " >> C:\Logfile.log",2,True
	End If

Open in new window


Expert Comment

ID: 22637374
One more thing. Please modify the script in this line to tell it where exactly your BUTIL executable is:

oWS.Run "%comspec% /c BUTIL -STARTBU " & sFilePath & " >> C:\Logfile.log",2,True

Modifiy above line just before "BUTIL" to include the path to the utility (example would be C:\Utilities\BUTIL)
so if that was the path your entire line would be like this:

oWS.Run "%comspec% /c C:\Utilities\BUTIL -STARTBU " & sFilePath & " >> C:\Logfile.log",2,True

Author Comment

ID: 22682015
Sorry for the lack of response. I have had a chance to try these suggestions yet . The method involving HoldOpen seems like the most proper way (other than using the backup agent which isn't working). I will give that a try.
LVL 28

Expert Comment

by:Bill Bach
ID: 22682805
Did you try the Backup Agent?  If so, what problems did you have?  

Author Comment

ID: 22688724
Once backup agent was enabled, our software would throw errors when users tried to use it, relating to not being able to access certain files. From what the support of our software company said, they said the Backup Agent must be having files with data files being created after the backup starts. The software apparently creates many temporary data files, and it seems Backup Agent, while running, does not handle newly created files properly. I spent much time with their support trying to resolve this, but was unable to.
LVL 28

Expert Comment

by:Bill Bach
ID: 22689021
Depending on your database version, you may be able to leverage the "black list" capabilities of BA1.1.  However, I suspect that Pervasive's tech support would have already suggested this, and perhaps it doesn't work for you due to the file names or directories they are using for temp files.  Some applications just don't like the way BA messes with them, to be sure.

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

622 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