Mass Update/Export of Documentation of Multiple Databases

Running Dataedo from command line allows you to automate the process of updating and exporting your documentation.

However, with large systems containing multiple databases and documentation, you may not want to create a task for each and every operation, but you'd rather have a single process for all your updates and exports.

This article shows how we deal with a lot of files during release tests of Dataedo, which might be useful for you. Skip to the final solution if you’re not interested in how we got there.

The first thing that comes to my mind is making a batch file (.bat) and using it to run the commands.

The simplest version would probably contain calls to every created update or export dataedocmd file:

"C:\Program Files (x86)\Dataedo 5\Dataedo5.exe" /dataedocmd "C:\DataedoUpdates\UpdateFile1.dataedocmd" 
"C:\Program Files (x86)\Dataedo 5\Dataedo5.exe" /dataedocmd "C:\DataedoUpdates\UpdateFile2.dataedocmd" 
... 
"C:\Program Files (x86)\Dataedo 5\Dataedo5.exe" /dataedocmd "C:\DataedoUpdates\ExportFile1.dataedocmd" 
"C:\Program Files (x86)\Dataedo 5\Dataedo5.exe" /dataedocmd "C:\DataedoUpdates\ExportFile2.dataedocmd" 
...

But this would require a lot of manual changes. For example, if you move the Dataedo folder location (e.g., when trying out a new version) you'd need to modify the path for all commands.

Can we fix this? Of course - let's add a variable for Dataedo path:

SET dataedo="C:\Program Files (x86)\Dataedo 5\Dataedo5.exe" 
%dataedo% /dataedocmd "C:\DataedoUpdates\UpdateFile1.dataedocmd" 
%dataedo% /dataedocmd "C:\DataedoUpdates\UpdateFile2.dataedocmd" 
... 
%dataedo% /dataedocmd "C:\DataedoUpdates\ExportFile1.dataedocmd" 
%dataedo% /dataedocmd "C:\DataedoUpdates\ExportFile2.dataedocmd" 
... 

A bit better, but still every time you want to add a new update or export operation, you need to add it to the list. Why not just run all .dataedo files from a current folder?

SET dataedo="C:\Program Files (x86)\Dataedo 5\Dataedo5.exe" 
FOR %%v in (*.dataedocmd) DO ( 
%dataedo% /dataedocmd "%%v" 
) 

This looks a lot nicer, but now my folder looks like this:

Image title

It's almost finding a needle in the haystack. I could really use some subfolders ... Can we run the FOR loop recursively for them? Yes, we can!

SET dataedo="C:\Program Files (x86)\Dataedo 5\Dataedo5.exe" 
FOR /r %%v in (*.dataedocmd) DO ( 
%dataedo% /dataedocmd "%%v" 
) 

But how do we know whether everything ran correctly? We'd need to check each command's log file, which does not sound ideal... Luckily, since each run of Dataedo from command line returns an errorlevel variable (you can find the details in documentation link), we can use just that as a condition:

SET dataedo="C:\Program Files (x86)\Dataedo 5\Dataedo5.exe" 
FOR /r %%v in (*.dataedocmd) DO ( 
%dataedo% /dataedocmd "%%v" 
IF NOT %%errorlevel%%==0 echo Error on %%v >> error.log 
) 

Now all errors will be logged to the error.log file - if it's not empty, it means that one of the operations failed. It will show which one that was, so you know the detailed log to check.

Let's run it and... Whoops! Since this will execute the file from the alphabetically sorted list, exports (named Export from ... by default) will be run before updates (named Update from ... by default) which is obviously not what we want. We want to update databases first and then export documentation to HTML or PDF.

We could fix this by enforcing some naming scheme, but instead let's split our files into two main folders - update and export and specify a single error.log path for both:

SET dataedo="C:\Program Files (x86)\Dataedo 5\Dataedo5.exe" 
SET dataedocmd_update_path="C:\DataedoCommands\UpdateCommands\" 
SET dataedocmd_export_path="C:\DataedoCommands\ExportCommands\" 
SET dataedocmd_error_path="C:\DataedoCommands\error.log" 
cd %dataedocmd_update_path% 
FOR /r %%v in (*.dataedocmd) DO ( 
%dataedo% /dataedocmd "%%v" 
IF NOT %errorlevel%==0 echo Error on update from %%v >> %dataedocmd_error_path% 
) 
REM then from the export folder above 
cd %dataedocmd_export_path% 
FOR /r %%v in (*.dataedocmd) DO ( 
%dataedo% /dataedocmd "%%v" 
IF NOT %%errorlevel%%==0 echo Error on export from %%v >> %dataedocmd_error_path% 
) 

Let’s add some further adjustments for the ease of use:

  • Since I run the .bat file manually during tests, I want to make sure the cmd window doesn't suddenly close while I'm reading through it. For that purpose, I’m adding a PAUSE command. Remove it if you want to automate running the batch.
  • I don't need to see my own commands, so I add an @echo off at the start.
  • It would be nice if the script was at least a bit documented, so I add a few comments with rem.

Final solution

And here's the final file:

@ECHO OFF 
SETLOCAL ENABLEDELAYEDEXPANSION 
REM Dataedo file path - if using Oracle, point to the version according to Oracle Client 
SET dataedo="C:\Program Files (x86)\Dataedo 5\Dataedo5.exe" 
REM Update command file path, will include subfolders 
SET dataedocmd_update_path="C:\DataedoCommands\UpdateCommands\" 
REM Export command file path, will include subfolders 
SET dataedocmd_export_path="C:\DataedoCommands\ExportCommands\" 
REM Error log path 
SET dataedocmd_error_path="C:\DataedoCommands\error.log" 
REM Run commands - first from the update folder above 
CD %dataedocmd_update_path% 
FOR /r %%v in (*.dataedocmd) DO ( 
%dataedo% /dataedocmd "%%v" 
IF NOT %%errorlevel%%==0 ECHO Error on update from %%v >> %dataedocmd_error_path% 
) 
REM then from the export folder above 
CD %dataedocmd_export_path% 
FOR /r %%v in (*.dataedocmd) DO ( 
%dataedo% /dataedocmd "%%v" 
IF NOT %%errorlevel%%==0 ECHO Error on export from %%v >> %dataedocmd_error_path% 
) 
PAUSE 
@ECHO ON 

I hope the explanation above will allow you to create even better scripts for your environment.

If anything isn't clear, or you run into any issues with the above script do not hesitate to comment, or contact us at support@dataedo.com or in our Community forum.

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.