Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 939
  • Last Modified:

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

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

  • 4
  • 3
  • 2
2 Solutions
Bill BachPresidentCommented:
    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.
bradl3yAuthor Commented:
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?
Bill BachPresidentCommented:
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 www.goldstarsoftware.com/tools.asp 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.
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!

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("wscript.shell")
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

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
bradl3yAuthor Commented:
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.
Bill BachPresidentCommented:
Did you try the Backup Agent?  If so, what problems did you have?  
bradl3yAuthor Commented:
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.
Bill BachPresidentCommented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now