How to backup SAP MaxDB with Veeam

This post focuses on how to backup SAP MaxDB databases with Veeam Backup & Replication. I came across a SAP MaxDB installation during my last projects and wanted to share with you how to backup these databases.

Introduction on pre-freeze and post-thaw scripts

Since there is no native integration of SAP MaxDB in Veeam, we need to use pre-freeze and post-thaw scripts within the guest processing options.

Pre-freeze and post-thaw scripts are being used, when an application does not support VSS for example. The pre-freeze script is used to quiesce the VM file system or the application prior Veeam triggers a VMware snapshot. After the VMware snapshot is created, the post-thaw script triggers and brings the VM and the corresponding application back to the initial state.

How do the scripts work ?

Pre-freeze and post-thaw scripts are used on backup jobs, replication jobs and VM copy jobs.

Furthermore, you need to create the scripts beforehand. When the specific job starts, Veeam uploads the script to the guest operating system of your VM and executes it with the credentials you specified in the “Guest OS credentials” section of the job settings. Keep that in mind, as Veeam copies the script to the “admin$” share over the network or by using VIX API to execute them from there (on Windows). So your account needs to have sufficient permissions.

For linux, the scripts are copied over SSH or the VIX API to “/home/<username>” of the credentials you specified in the “Guest OS credentials” section of the job settings.

In addition, make sure that your scripts return a “0” when they execute, because Veeam expects that as successful. Furthermore, the default time period for script executions is 10 minutes.

For Microsoft Windows, the folowing script file formats are supported: “EXE, BAT, CMD, WSF, JS, VBS, and PS1”

For Linux, Veeam supports only shell scripts in the “SH” file format.

In the picture below you can see where to add those scripts for guest processing operations.

backup MaxDB with Veeam

How to backup SAP MaxDB with pre-freeze and post-thaw scripts

To process the SAP MaxDB with a VMware Veeam job, we need to suspend the MaxDB logwriter, prior of a VM snapshot. To achieve this, we need to use the dbmcli of the MaxDB database to suspend the logwriter and afterwards resume it again. The scripts posted below use a code snippet of Ben Gripka to run a script in an elevated command line window. Thanks to Ben for this awesome script ! I had the case, that I was using a service account which didn’t have the proper permissions to run an administrative script from the “admin$” share.

Also, this post in the Veeam forums helped me aswell on achieving my goal to backup the SAP MaxDB databases. I need to add that the solution of disabling the UAC was not usable at the customer where we needed to backup the MaxDB. That’s why I was searching for another solution and used the snippet from Ben Gripka to achieve this !

The SAP MaxDB part of these scripts start at line 26 with the path to the “dbmcli”.

Here is the pre-freeze script to suspend the logwriter prior of the VMware snapshot to backup SAP MaxDB with Veeam.

@echo off
:: BatchGotAdmin
::-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"="
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
::--------------------------------------
<Path_to_DBMCLI>\dbmcli -d <DB_Instance> -u <DB User>,<Password> -uUTL -c util_execute suspend logwriter
exit

After the VMware snapshot is successful, the post-thaw script resumes the logwriter again.

@echo off
:: BatchGotAdmin
::-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"="
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
::--------------------------------------
<Path_to_DBMCLI>\dbmcli -d <DB_Instance> -u <DB User>,<Password> -uUTL -c util_execute resume logwriter
exit

Make sure to provide the correct path to the “dbmcli” and name the correct MaxDB instance. As an example this could look like this:

C:\Program Files\MaxDB\dbmcli -d MY_MAX_DB -u Administrator,Password -uUTL -c util_execute suspend logwriter

AND

C:\Program Files\MaxDB\dbmcli -d MY_MAX_DB -u Administrator,Password -uUTL -c util_execute resume logwriter

Conclusion on how to backup SAP MaxDB

By using these scripts I was able to create image level backups of the SAP MaxDB. A restore test afterwards was successful as well.

You can find these scripts on my Github repository as well: Here is the link to the repository

Furthermore, I’d like to add the recommendation to test out the single “dbmcli” command at first. Simply use the one-liner to suspend the logwriter and a message like “OK” will return. Just make sure to check if the script is working before you waste time with waiting for backup jobs.

As always, thanks for reading, stay safe and have an awesome day !

About Falko Banaszak

Falko is a Consulting Field Solutions Architect for Modern Data Protection based in Germany working at Pure Storage Inc. In the last 12 years he has built a strong focus on virtualization, BCDR and has a passion for Microsoft 365 & storage systems. He's a Veeam Vanguard, a Veeam Certified Engineer, Veeam Certified Architect and a Veeam User Group founder and leader in Germany.

Check Also

vSphere Tagging Tool HTML5

Supercharge Excel with ChatGPT

Introduction and why I Supercharge Excel with ChatGPT When you read “Supercharge Excel with ChatGPT”, …

4 comments

  1. Thank you for the brilliant guide. Would you be so kind as to confirm two more aspects of this that I think could help everybody who wants to use veeam to backup MaxDB for SAP.

    The first is how does one confirm that the backups are successful. By this I would normally schedule backups using backint or let MaxDB dump full db backups with log backups to be picked up on the filesystem backup. But with the veeam method I am not enabling any backup method using MaxDB database studio or database manager cli. Using either of these tools I would be able to see the backup history, but I don’t know how to do that using veeam method mentioned above.

    The second is does the method described above do both log and full db backup only. Or can I enable incremental backups also? I have currently enabled this method for MaxDB 7.9 and I do not have log backups on as we are using veeam and veeam does not have backint for MaxDB. So what kind of backups are available using this method?

    Kind regards

    • Hi Ulfar,
      the pre-freeze and post-thaw scripts only suspend the logwriter prior taking a VMware snapshot. That means, that the database should be in a consistent state while the VMware Snapshot triggers and nothing is beeing written to the logfiles.
      That is the only method for now, as there is no integration in the MaxDB studio.
      So regardless of your backup method within the Veeam job (Synthetic or Active Full and Incrementals) the scripts will only suspend the logwriter to have the database in a consistent state while triggering the VMware snapshot and doing the backup.
      Hope this helps !

  2. Hello,

    even if your solution will most probably work in many cases please note that suspending the log writer is no longer the recommended method to backup MaxDb. Instead MaxDb integrated external backups should be used.

    We offer a VSS Writer for MaxDb that integrates perfectly with Veeam: http://maxback.io

    It works without suspending the log writer.
    It also supports features like log truncation, system copies and many more.

    Best Regards,
    Frank

    • Falko Banaszak

      Hi Frank,
      thanks for posting your maxback.io VSS Writer for Windows based MaxDB databases.
      Pre Freeze and Post Thaw scripts which suspend and resume log writers are most probably always not the “best” thing to do, thats why these scripts are released under MIT license and people are going to know, that we are talking about image-level backups not “database aware” backups when using such scripts.
      Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *