Migrating SAP ERP 6 on IBM Db2 to IBM Power Virtual Server
Use the following guide to migrate your SAP Enterprise Resource Planning 6 (ERP) system from an IBM Db2 to an IBM Power Virtual Server. You have different options to migrate IBM Db2 databases to a target system.
IBM Db2 SAP migration options
For SAP ERP on IBM Db2, you have two migration options:
-
Migration option 1 - Back up and restore is based on standard administrative tasks such as start, stop, backup, and restore. It is a less complicated approach, but it requires downtime during migration.
-
Migration option 2 - IBM Db2 high availability and disaster recovery (HADR) is a downtime-optimized approach for SAP production systems. It is based on IBM Db2 High Availability and Disaster Recovery (IBM Db2 HADR) Database Synchronization and an online back up. The system downtime is minimized, but the method requires a higher configuration approach compared to option 1.
Migration option 1 - Back up and restore
Back up and restore is a typical option to migrate development or test SAP systems. This migration option is based on a backup of the database from the source system and a database restore to fill the database on a preinstalled target system.
The following steps are required to complete the migration:
- Preparing for migration
- Shutting down the SAP application and deactivating the database on the source server
- Using the IBM Db2 offline backup on the source system
- Transferring the backup files
- Restoring the database on the target system
- Starting the SAP target system
Characteristics of the Migration Option 1 - Back up and Restore approach:
- Downtime: a planned downtime of the SAP system is required because the SAP system is not available during the migration process.
- Fallback: no changes were made to the source SAP system. The fallback action if required, stops the migration and restarts the source SAP system.
- Complexity: is based on standard administrative tasks. This migration option is the least complicated.
Preparing for migration
Use the following steps to prepare for the migration.
You need all the defined environment variables on both the source and target server. Save the commands to a temporary text file while you run them on the source SAP server. The exact same commands are required on the target server as shown in chapter Restoring the database on the target system.
Set the following environment variables according to your needs.
-
Start a C shell session as
root
user on the source system:csh
The command syntax for defining environment variables depends on the shell type. Default shell type for Db2 and SAP administrator users
db2<sid>
and<sid>adm
is the C shell. When using the same shell, you can copy the command examples and paste them into your session environment. -
Define the hostname of the target migration system (example:
cdb6ecc1
) and replace it with your target hostname:set TARGETSERVER=cdb6ecc1
Make sure that the same versions of SAP ERP Software and IBM Db2 database are running on the source and target SAP systems.
-
Define the SAP instance administrator (this example is for the SAP instance
th1
) and change it to match your system.set SIDADM=th1adm
-
Define the IBM Db2 database name - again
th1
is the example, and change it to match your system:set DBNAME=th1
-
Define the IBM Db2 database administrator:
set DB2ADM=db2th1
-
Define a directory to store the backup files:
set BACKUPDIR=/db2/backup
-
Create the following directory if it does not exist:
mkdir -p $BACKUPDIR
and transfer the ownership of the backup directory to the Db2 administrator:
chown $DB2ADM $BACKUPDIR
This backup directory needs enough space to store the compressed backup files. Determine the current IBM Db2 database size by calling the
GET_DBSIZE_INFO
procedure. For more information, see the GET_DBSIZE_INFO procedure.
Shutting down the SAP application and deactivating the database on the source server
Use the following steps to shut down the SAP application and deactivate the database on the source server.
-
To start or stop the SAP system, use the SAP instance administrator account
$SIDADM
:su - $SIDADM
-
To stop the SAP system and keep the database running, use the following command:
stopsap r3
Optionally, you can check whether the SAP is in the required state by running the following command:
stopsap check
The expected output looks like the following example:
Checking db6 Database Database is running ------------------------------------------- Checking SAP TH1 Instance ASCS01 ------------------------------------------- Instance ASCS01 is not running Checking SAP TH1 Instance D00 ------------------------------------------- Instance D00 is not running
-
For the Db2 commands, end the
$SIDADM
user session:exit
-
Switch to the
$DB2ADM
user:su - $DB2ADM
Optionally, you can check whether any applications are still connected to the database before you deactivate the database by running the following command:
db2 list applications
The following example is the expected output.
SQL1611W No data was returned by Database System Monitor.
If applications are still listed, stop the applications and check again. Only if the external applications still don't stop, try disconnecting applications from the database server with
db2 force applications all
. -
Define the environment variables for the DB2ADM user again:
set DBNAME=th1
set BACKUPDIR=/db2/backup
-
The IBM Db2 offline backup requires that the database is deactivated. Use the following command to deactivate the database:
db2 deactivate database $DBNAME
The following output is expected.
DB20000I The DEACTIVATE DATABASE command completed successfully.
Using the IBM Db2 offline backup on the source system
Use the following steps to use the Db2 offline backup on the source system.
A backup directory to store the compressed offline backup was created in the preparation step Preparation for Migration.
-
Verify that the backup directory offers sufficient available space to store backup files:
df -m $BACKUPDIR
-
Start the IBM Db2 offline backup:
db2 backup database $DBNAME to $BACKUPDIR compress
This command runs for a long time, depending on the database size.
Backup progress can be tracked with the command
db2 list utilities show detail
You can find a timestamp at the end of the backup command output. This timestamp is required to Restoring the database on the target system.
Example output:
Backup successful. The timestamp for this backup image is : 20240730170709
Memorize this timestamp, you need to refer to it in the next two steps.
-
Use an environment variable to store the timestamp:
set TIMESTAMP=<your timestamp>
The IBM Db2 backup timestamp has the format YYYMMDDHHMMSS (Year-Month-Day-Hour-Minute-Second) and looks like
20240730170709
. This timestamp is needed on the target SAP server again. Append thisTIMESTAMP
definition command to the list of saved commands that are from Preparation for Migration. -
Change to the backup folder by using the following command:
cd $BACKUPDIR
-
Check for files that contain your timestamp in their name:
ls -l *$TIMESTAMP*
Example output:
TH1.0.db2th1.DBPART000.20240730170709.001
Files that are listed in the output are the backup files that are transferred to the target system in the next step.
Transferring the backup files
Use the following steps to transfer the backup files.
-
Copy the backup files from the source SAP system to the target:
scp ${BACKUPDIR}/*${TIMESTAMP}* \ ${TARGETSERVER}:${BACKUPDIR}
This example uses secure copy (SCP), a slower version of data transfer. You can transfer backup files either directly to an IBM AIX LPAR in PowerVS, or to IBM Cloud Object Storage. If you use SCP or SFTP with IBM Cloud Object Storage, it assumes that you are using an IBM FileManage Gateway service or installed and configured an SFTP server within or next to the target IBM PowerVS environment to receive the transfer.
The faster option is IBM’s high-performance Aspera product for data transfer. In many situations, IBM Aspera can transfer data several times faster than traditional TCP-based protocols. For more information, see IBM Aspera Technologies.
This reference also contains the Accelerated network transfer migration guide.
Restoring the database on the target system
Use the following steps to restore a database on the target system.
-
Log in to the target server to start the restore procedure:
ssh $DB2ADM@$TARGETSERVER
The target server can't know the environment variables that are defined on the source system. But variables
$DBNAME
,$TIMESTAMP
and$SIDADM
are needed on the target system. To define these variables, run the list of commands that you saved in step Preparing for migration and Using the IBM Db2 offline backup on the source system or define the environment variables again. -
The full restore procedure requires a deactivated IBM Db2 database. Use the same steps as before on the preinstalled target SAP system:
db2 list applications
The following output is expected:
SQL1611W No data was returned by Database System Monitor.
-
Deactivate the IBM Db2 database:
db2 deactivate database $DBNAME
-
Do a full database restore:
db2 restore database $DBNAME \ from $BACKUPDIR \ taken at $TIMESTAMP
Appending
replace existing
to the restore command avoids the overwrite prompt. -
Db2 command asks if you want to overwrite the existing database by restoring the backup:
SQL2523W Warning! Restoring to an existing database that is different from the database on the backup image, but have matching names. The target database is overwritten by the backup version. The Roll-forward recovery logs associated with the target database is deleted. Do you want to continue ? (y/n)
Enter
y
and press Enter.The following output is expected:
DB20000I The RESTORE DATABASE command completed successfully.
If the restore did not succeed, drop the database on the target system in advance with
db2 drop database $DBNAME
and redo the restore command. -
To complete the restore, use the following command:
db2 rollforward db $DBNAME to end of backup and stop
The target database now contains the source system data.
Starting SAP target system
Use the following steps to start the target system,
-
Switch to the SAP instance administrator:
login $SIDADM
-
Start the SAP application:
startsap
The following example is the expected output:
Checking db6 Database Database is running ------------------------------------------- Starting Startup Agent sapstartsrv OK Instance Service on host <TARGET> started ------------------------------------------- starting SAP Instance ASCS01 Startup-Log is written to /home/th1adm/startsap_ASCS01.log ------------------------------------------- /usr/sap/TH1/ASCS01/exe/sapcontrol -prot NI_HTTP -nr 01 -function Start Instance on host <TARGET> started Starting Startup Agent sapstartsrv OK Instance Service on host <TARGET> started ------------------------------------------- starting SAP Instance D00 Startup-Log is written to /home/th1adm/startsap_D00.log ------------------------------------------- /usr/sap/TH1/D00/exe/sapcontrol -prot NI_HTTP -nr 00 -function Start Instance on host <TARGET> started
Adjust the SAP system DNS record to point to the target SAP server to make sure that client systems (the running SAP Logon GUI) are connected to the target server.
The migration is complete.
- SAP system on the source server is down
- SAP system on the target server is up and running
Migration option 2 - IBM Db2 high availability and disaster recovery (HADR)
Migration option 2 is a downtime-optimized procedure. It is a combination of backup, recovery, and synchronization of the databases on both sides by using IBM Db2 HADR. If databases are in sync and the environment is prepared for migration, the core migration switches to the preinstalled target SAP server.
If the source system uses an IBM Db2 cluster or has IBM Db2 HADR enabled, migration extends the existing HADR configuration. Special case - Migrating a source IBM Db2 cluster describes and links to the required steps.
If IBM Db2 HADR is not enabled on the source side, the following steps are required:
- Preparing for migration
- Making sure that IBM Db2 archive logging is enabled
- Creating an online backup from the source system database
- Transferring backup files to the target system
- Restoring the target system
- Defining HADR local and remote service ports on the target and source system
- Configuring HADR on the target and source systems
- Starting HADR and checking the synchronized data
- Running the core migration step
Characteristics of Migration Option 2 -IBM Db2 HADR:
- Downtime, general: it has a short downtime when the server switches from source to target. Before the switch, the source SAP system is running. After the switch, the target SAP system takes over.
- Downtime, circular logging: HADR requires that the IBM Db2 database is in
archive logging
mode. If your IBM Db2 database is incircular logging
mode, you need to migrate the IBM Db2 database toarchive logging
mode before you use HADR. This step enforces a one-time database downtime. - Fallback: means that the source SAP system is running during the complete migration until it switches. Before you make the switch, no special fallback option is required. If steps before or after the switch are unsuccessful, you can reverse the steps to bring the source SAP system up and running again.
Special case - Migrating a source IBM Db2 cluster
If the source SAP system is an IBM Db2 HADR cluster, the HADR configuration needs to extend to include the target server. The steps are easier in this case.
Most of the configuration steps that are described are already set up. The target system needs to be added as an auxiliary node to the existing IBM Db2 HADR configuration. For more information, see the Steps for adding a new Auxiliary Standby to an existing Db2 HADR Pair IBM Db2 Support Article.
Preparing for migration
Use the following steps to prepare the SAP system for migration.
Keep the following information in mind as you prepare for the migration.
-
You need to define two TCP port numbers to use in your setup.
-
Synchronizing with HADR requires two open network ports:
- A local port for outgoing traffic
- A remote port for incoming traffic
-
Both port are configured on each of the two IBM Db2 systems, but with interchanged order. This example uses port number
5920/tcp
and5921/tcp
, but you can adapt these ports to your needs. -
Firewalls must allow TCP traffic between the source and target system. Make sure that the required firewall rules are configured on all involved firewalls and on the source and target system.
Set the following environment variables according to your configuration.
All environment variables that are defined are needed on both the source and target server. Save the commands while you run them on the source SAP server to a temporary text file. The same commands are required on the target server as noted in Restoring the database on the target system.
-
Define the hostname for the target migration system.
cdb6ecc1
is an example and replace it with your target hostname by using the following command:set TARGETSERVER=cdb6ecc1
Make sure that your target server is running SAP ERP Software and IBM Db2 database with the same version as the source SAP system.
-
Define the SAP instance administrator and change it to match your system by using the following command (this example is for the SAP instance
th1
):set SIDADM=th1adm
-
Define the IBM Db2 database name - again
th1
is an example. Change it to match your system:set DBNAME=th1
-
Define the IBM Db2 database administrator:
set DB2ADM=db2th1
-
Define a directory to store backup files:
set BACKUPDIR=/db2/backup
-
Create the following directory if it does not exist:
mkdir -p $BACKUPDIR
and transfer the ownership of the backup directory to the Db2 administrator:
chown $DB2ADM $BACKUPDIR
This backup directory needs enough space to store the compressed backup files. Determine the current IBM Db2 database size by calling the
GET_DBSIZE_INFO
procedure. For more information, see GET_DBSIZE_INFO procedure.
Making sure that IBM Db2 archive logging is enabled
IBM Db2 High Availability and Disaster Recovery (HADR) requires archive logging
to be enabled.
circular logging
is enabled by default after you install IBM Db2 HADR. Most SAP systems on IBM Db2 have archive logging
enabled.
Checking the archive logging methods
To check which logging method is configured, use the following steps.
-
Switch to the IBM Db2 database admin:
su - $DB2ADM
-
Retrieve both log archive method configuration options:
db2 get db cfg for th2 | grep LOGARCHMET
-
Continue with the next section, if at least one of the log archive methods is set to
ON
. Make sure that both are not set toOFF
. This example shows what the output for enabled archive logging looks like:First log archive method (LOGARCHMETH1) = DISK:/db2/logarch/ Second log archive method (LOGARCHMETH2) = OFF
-
If both log archive methods are
OFF
, you need to configure archive logging first. The following example is the output:First log archive method (LOGARCHMETH1) = OFF Second log archive method (LOGARCHMETH2) = OFF
Configuring archive logging
Archive logging is required for IBM Db2 HADR. If LOGARCHMETH1 and LOGARCHMETH2 are set to OFF
, use the following steps to enable archive logging.
A downtime is required to enable archive logging.
-
Start as SAP admin user to stop the SAP system:
su - $SIDADM
-
Stop the SAP system, but leave the database running:
stopsap r3
-
Quit the SAP administrative user:
exit
-
Switch to the IBM Db2 administration account:
su - $DB2ADM
-
Use the saved commands to ensure environment variables like
DBNAME
andBACKUPDIR
are set. -
Define a directory for log archive files:
set LOGARCHDIR=/db2/log_archive
If possible, create the log archive directory on a separate partition. The archive log partition depends on the LPARs disk setup, which is out of the scope of this document. Keep in mind that if the source system is an IBM Db2 cluster, the log archive is a shared directory between the nodes.
-
Create the log archive directory, at minimum with this command:
mkdir $LOGARCHDIR
-
Check the created directory:
ls -ld $LOGARCHDIR
Sample output:
drwxr-xr-x 7 db2th1 dbth1adm 256 Aug 30 11:24 /db2/log_archive
-
Verify whether the directory owner is the Db2 administrator, which is
db2th1
in sample output. Then, check that the owner has full permissionsrwx
. -
Configure Db2 to use a disk device with this directory for archive logging method 1:
db2 "update db cfg for $DBNAME using LOGARCHMETH1 DISK:$LOGARCHDIR"
Expected output:
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
IBM Db2 database enforces a backup after this change:
db2 backup database $DBNAME to $BACKUPDIR compress
The backup takes a while to complete, depending on the database size.
-
Use the SAP admin account $SIDADM to start database and SAP system again:
su - $SIDADM
startsap
Creating an online backup from the source system database
To minimize SAP system downtime, create an online Db2 database backup.
-
Switch to the Db2 admin user:
su - $DB2ADM
-
Start the online backup, including log files:
db2 backup db $DBNAME online to $BACKUPDIR compress include logs
Keep in mind that the backup takes some time to complete.
When the backup is complete, a timestamp is printed:
Backup successful. The time stamp for this backup image is : 20240913091058
Memorize this timestamp. You need it in the next two steps.
-
Use an environment variable to store the timestamp:
set TIMESTAMP=<your timestamp>
The IBM Db2 backup timestamp uses the format YYYMMDDHHMMSS (Year-Month-Day-Hour-Minute-Second) and looks like
20240913091058
. This timestamp is needed on the target SAP server again. Append thisTIMESTAMP
definition command to the list of saved commands from step Preparation for Migration.
Transferring backup files to the target system
Use the following steps to transfer the backup files to the target system.
-
Copy the backup files from the source SAP system to the target system:
scp ${BACKUPDIR}/*${TIMESTAMP}* \ ${TARGETSERVER}:${BACKUPDIR}
Restoring the target system
Use the following steps to restore the target system.
-
The database restore is done on the target server:
ssh $DB2ADM@$TARGETSERVER
The target server cannot know the environment variables that are defined on the source system. But the variables
$DBNAME
,$TIMESTAMP
and$SIDADM
are needed on the target system. To define these variables, run the list of commands that you saved in step Preparing for migration and Creating an online backup from the source system database or define the environment variables again. -
Use the online backup to restore to the database.
db2 restore database $DBNAME \ from $BACKUPDIR \ taken at $TIMESTAMP
Db2 command asks if you want to overwrite the existing database by restoring the backup:
SQL2523W Warning! Restoring to an existing database that is different from the database on the backup image, but have matching names. The target database will be overwritten by the backup version. The Roll-forward recovery logs associated with the target database will be deleted. Do you want to continue? (y/n)
-
Enter
y
and press Enter.The following example is the expected output:
DB20000I The RESTORE DATABASE command completed successfully.
If the recovery was not successful, drop the database on the target system in advance with
db2 drop database $DBNAME
and redo the restore command.In contrast to option 1, do not roll forward archive logs. HADR takes this state to synchronize changed data that is in the next step. If the source SAP system is operational, source data changes.
To transfer the latest changes, configure IBM Db2 HADR database synchronization.
Defining HADR local and remote service ports on the target and source system
Use the following steps to define HADR local and remote service ports on the target and source system.
HADR uses two TCP ports to synchronize data.
-
Check that
/etc/services
does not contain these TCP port numbers on both systems. Configure port numbers in this file on both servers.If local and remote HADR ports are configured in
/etc/services
, IBM Db2 configuration is more readable by using service names instead of numbers.In the example, ports
5920/tcp
and5921/tcp
are used, but you can define different ports.Overview table of the port numbers to configure:
TCP port assignment in /etc/services on both servers Services name Value on source server Value on target server Comment db2th1ha_l 5921/tcp
5920/tcp
Local port db2th1ha_r 5920/tcp
5921/tcp
Remote port -
Use your favorite editor to change
/etc/services
on both servers. -
Review if the configuration files are correct, by using the following command:
grep -e '592[01]/' /etc/services
The following lines are the expected output on the source server:
db2th1ha_l 5921/tcp # Db2 HADR local port db2th1ha_r 5920/tcp # Db2 HADR remote port
Port numbers must be enabled on the target server. The following example is the expected output on the target node:
db2th1ha_l 5920/tcp # Db2 HADR local port db2th1ha_r 5921/tcp # Db2 HADR remote port
Configuring HADR on the target and source system
HADR needs the following set of configurations.
Db2 HADR parameter | Value on source server | Value on target server | Comment |
---|---|---|---|
HADR_LOCAL_HOST | <source hostname> | <target hostname> | Hostname of the system that you are on |
HADR_LOCAL_SVC | db2th1ha_l | db2th1ha_l | Local port as defined in /etc/services |
HADR_REMOTE_HOST | <target hostname> | <source hostname> | The other host's hostname |
HADR_REMOTE_SVC | db2th1ha_r | db2th1ha_r | Remote port as defined in /etc/services |
HADR_REMOTE_INST | <db2 instance name> | <db2 instance name> | The other node's IBM Db2 instance name (not the database name) |
LOGINDEXBUILD | ON |
ON |
Set to ON on for both hosts |
HADR_SYNCMODE | <a valid sync mode> | <a valid sync mode> | See HADR Synchronization Mode |
Local and remote hostnames (HADR_LOCAL_HOST
and HADR_REMOTE_HOST
) must be turned on for both systems. HADR_LOCAL_HOST
is always the hostname of the node. The configuration command is run on and the remote
host is the hostname of the respective other system.
Local and remote service entries (HADR_LOCAL_SVC
and HADR_REMOTE_SVC
) are identical because the switch is already configured in /etc/services
.
High availability disaster recovery (HADR) synchronization mode explains different IBM Db2 HADR synchronization options and their benefits.
Use the following commands to configure both systems:
-
Local host is the system that the
hostname
command reports to:db2 "update db cfg for $DBNAME using HADR_LOCAL_HOST `hostname`"
-
Local port is the local port definition from
/etc/services
:db2 "update db cfg for $DBNAME using HADR_LOCAL_SVC db2th1ha_l"
-
For the remote host, verify that
$TARGETSERVER
points to the other server:db2 "update db cfg for $DBNAME using HADR_REMOTE_HOST $TARGETSERVER"
-
The remote port is the remote port definition from
/etc/services
:db2 "update db cfg for $DBNAME using HADR_REMOTE_SVC db2th1ha_r"
-
Configure the remote IBM Db2 instance.
As orientation, if the database name is
th1
, then the instance name looks likedb2th1
:db2 "update db cfg for $DBNAME using HADR_REMOTE_INST $DBINST"
-
Make sure that the log index build is set to ON on both systems:
db2 "update db cfg for $DBNAME using LOGINDEXBUILD ON"
-
Define the HADR synchronization mode. The value
async
is an example, change it to match the HADR Synchronization Mode suitable for your environment:db2 "update db cfg for $DBNAME using HADR_SYNCMODE async"
Starting HADR and checking the synchronized data
Use the following steps to start HADR and to check whether the data is syncing.
-
Start HADR on the target server in standby. Switch to the target server as
$DB2ADM
, and run the following command:db2 start hadr on db $DBNAME as standby
Expected output looks like the following example:
DB20000I The START HADR ON DATABASE command completed successfully.
-
Start HADR on the source server as the primary. Switch to the source server as
$DB2ADM
and run the following command:db2 start hadr on db $DBNAME as primary
Expected output looks like the following example:
DB20000I The START HADR ON DATABASE command completed successfully.
-
Verify the HADR state with:
db2pd -d $DBNAME -hadr
And check for these fields:
HADR Status Values, both servers Field Source server Target server HADR_ROLE PRIMARY
STANDBY
HADR_STATE PEER
PEER
HADR_CONNECT_STATUS CONNECTED
CONNECTED
Running the core migration
Use the following steps to start migrating the SAP system from source server to the target server.
Adjust the SAP system DNS record to point to the target SAP server. This adjustment makes sure that client systems (such as the system that runs the SAP logon GUI) connect to the target server.
-
Stop the source servers SAP system that includes the Db2 database.
On the source system login as
$SIDADM
and run the following command:stopsap
Wait for the command to complete.
-
Switch to the target server as
$DB2ADM
and initiate a takeover by using the following command:db2 takeover hadr on database $DBNAME
The takeover command has an option
by force
that can help if the source system wasn't cleanly shut down. For more information, see TAKEOVER HADR command. -
As
$DB2ADM
on the target server. Verify that the IBM Db2 HADR role changed fromstandby
toprimary
by using the following command:db2pd -d th2 -hadr | grep ROLE
-
If the IBM Db2 HADR role is
primary
on the target server, you can start the SAP system on the target server. Switch to the$SIDADM
user and run the following command:startsap
The IBM Db2 database synchronization is still configured, although not active at this stage.
Leave HADR configuration as is if the target system is planned to migrate back (as for a disaster scenario). If the source system is removed after the migration, remove the HADR configuration as described in How to remove existing HADR configuration.
The migration is complete.
- SAP system on the source server is down
- SAP system on the target server is up and running