SAP DB2 databases backup with Veeam

In this post I’m going to show you how to do SAP DB2 databases backup on Linux with Veeam. I came across a SAP DB2 installation during one of 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 DB2 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 “/tmp”.

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.

SAP DB2 databases backup with Veeam

The process itself is very well explained in the Veeam Helpcenter. Make sure to have a look there !

How to backup SAP DB2 on Linux with pre-freeze and post-thaw scripts

To process the SAP DB2 with a VMware Veeam job, we need to suspend the SAP DB2 logwriter, prior of a VM snapshot. To achieve this, we need to use the db2 binary of the SAP DB2 database to suspend the logwriter and afterwards resume it again.

If you are running SAP DB2 on Windows, then there is already a pre-freeze and post-thaw example available on the Veeamhub. However, this post focuses on a pre-freeze and post-thaw script for Linux systems.

Here is a pre-freeze and post-thaw script example for backing up SAP DB2 databases on Linux. Make sure to test this on a test environment before you roll this out into production. Furthermore, this script (as all of any community script) comes with no warranty.

Before using the scripts, make sure to adjust it to your needs.

With adjusting, I mean selecting a path where the user you are using is able to write log files to, and the correct database name indicated in the script with “YOUR_DATABASE_NAME_HERE”.

I also uploaded those scripts to Github, because I’m maintaining all my scripts there.

Pre-Freeze Script for SAP DB2 databases backup

Post-Thaw Script for SAP DB2 databases backup

General Advice while using Pre-Freeze and Post-Thaw scripts within Linux

  • Due to the fact, that the script gets copied to “/tmp” of your linux machine, make sure, that the user is allowed to execute scripts from /tmp. Most systems permit doing so.
  • Make sure to use a linux user with permissions to log on the system over SSH and in the same way has permissions to execute the db2 binary.
  • Also make sure to set your sshd_config to allow password authentication of SSH and not to use public key authentication

CRUCIAL: Double check if your Shell Script has the LF format and not the CRLF format in terms of end-of-line-markers. I recommend using Notepad++ to check this, like so:

EOL Conversion Linux Windwos SAP DB2 Database Backup with Veeam

If you are using VSCode like me, then double-check the bottom right bar to see whether LF or CRLF is toggled.

EOL Conversion VSCode

If your Shell script isn’t formatted well you are going to get an error similiar to this one, telling you that there is a “bad character” in your Shell Script.

Veeam Bad Interpreter

I hope this script helps and I always love to hear feedback !

As always, thanks for reading, take care and enjoy your day !

PS: You can find my other Veeam related articles here: Veeam Blog Posts

About Falko Banaszak

Falko is a consultant based in Germany working for SVA GmbH. He has a strong focus on virtualization, data backup, disaster recovery infrastructures and a passion for Microsoft 365 & storage systems. He´s a VMware vExpert & Veeam user group leader in Germany. VCP-DCV, VMCE, VMCA.

Check Also

Veeam Live 2020

Get ready for Veeam LIVE 2020 !

Veeam LIVE 2020 is going to take place on the 20th of October 2020 ! …

Leave a Reply

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