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


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

Posted on 2008-10-03
Medium Priority
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 1200 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.
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.


Assisted Solution

Hubasan earned 800 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 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