Walker News

How To Backup DB2 Database To Shared Folder?

Imagine that tape drive is not available and the local disk space is not enough for creating a full database backup. Can you mount a shared folder and create database backup to this network resource?

Certainly, the answer is YES! Now, let’s see how to do this:
A) DB2 9.7 running on RHEL5.9, host name: mydb2

B) Samba 3.5 running on RHEL6.3, host name: myrh63, shared folder: myshr, Samba login: mylin

Steps To backup database to network shared folder

1. Login to mydb2 as root and create a directory in /tmp (e.g. /tmp/smbres).

2. Mount the network shared folder to local disk filesystem at /tmp/smbres (the mount point):
mount -t cifs -o user=mylin //myrh63/myshr /tmp/smbres
Note, you can also use a Windows shared folder, but please remember to replace the backslash with forward slash (i.e. the Linux style of slash character). For example, Windows host name: mywin, shared folder: dump, domain: mydom, domain id: myid:
mount -t cifs -o user=mydom/myid //mywin/dump /tmp/smbres

After mounting the Linux shared folder, you’ll notice the ownership of mount point (/tmp/smbres) has changed from root to other user ID. This UID is actually reflecting the shared folder ownership at Samba file server, despite it appears belong to a local user (if the UID at Samba server also exists in the DB2 server).

3. Ignore the ownership change, but please change the mount point access permission to allow all users read and write on it:
chmod 777 /tmp/smbres

This chmod is indeed changing the access permission of shared folder at Samba server!

4. Switch to the DB2 user ID that is used to create database backup, e.g. su - db2inst.

5. Create a pipe file, e.g. mkfifo $HOME/bakpipe

6. Run this command as background process – cat the pipe file content to shared folder:
cat $HOME/bakpipe >/tmp/smbres/db2bakimg &

7. Start to backup DB2 database called mydb to the pipe file which its content being redirected to the shared folder:
db2 backup db mydb to $HOME/bakpipe

8. Once the database backup completes successfully, run this command:
db2ckbkp -H /tmp/smbres/db2bakimg

To restore the DB2 database image backup file from shared folder, you may need to explicitly specify the image backup timestamp and must rename the /tmp/smbres/db2bakimg to the proper file name (all this info are in the db2ckbkp -H command output). Otherwise, DB2 can’t restore that image backup file and throw error code SQL2542N that says “No match for a database image file was found based on the source”.

Besides, make sure the backup image file access permission in shared folder is at least 644 (-rw-r–r–) or you’ll get error code SQL2061N which means access is denied.

Custom Search

  1. Dennis Miller 15-05-13@19:09

    Good Information

2016  •  Privacy Policy