Friday, August 9, 2024

Revisited: Db2 backup to S3 / Object Storage

Db2 backup in an S3 bucket
One of the popular posts I have written is on Db2 and S3-compatible Cloud Object Storage, a follow-up from an older article on that same topic. Because things change and I recently set up my new test environment, I just tested backing up a Db2 database to an S3-compatible bucket in my IBM Cloud storage service. Here are my notes.

Db2 test environment

For the tests, I am using the Db2 Community Edition for Docker on the current version 11.5. The S3-compatible storage bucket is located in Frankfurt and managed as part of my IBM Cloud Object Storage instance

Db2 requires an active keystore to store the storage credentials (security!). Thus, I created and configured a local keystore. The steps are linked to from the usage notes of the CATALOG STORAGE ACCESS command documentation.

Register the storage service

With the setup in place I could register (catalog) the storage service:

CATALOG STORAGE ACCESS alias mys3 VENDOR S3 SERVER s3.eu-de.cloud-object-storage.appdomain.cloud user 'access key' password 'secret key'

The command above creates a new alias "mys3" for an S3-compatible service with the given endpoint (server) and the user/password combination. The latter actually are the access key and secret key taken out of the HMAC credentials which I created for my IBM Cloud Storage Object instance.

Note that I did not specify a storage object. When done, I do not need to provide a bucket name when using commands and statements referring to the storage alias.

Perform a Db2 backup

After the registration I could perform a backup:

db2 => backup db cattest to DB2REMOTE://mys3/db2bucket/cattest

Backup successful. The timestamp for this backup image is : 20240808094119

In the BACKUP DATABASE command I can refer to the S3 storage (remote storage) with the DB2REMOTE clause as shown above. The given URL includes the storage alias "mys3", then the bucket (container) name "db2bucket", and the actual object. After a while, the command completes successfully. The timestamp of the backup image is also included in the object I can see in the IBM Cloud Object Storage console for my bucket:


I could also obtain the history of backup operations and get details on the recent one. It shows what tablespace data is included and that the backup was saved to the remote storage location into my S3 bucket:

db2 => list history backup all for cattest

                    List History File for cattest

Number of matching file entries = 2

...

 Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log  Backup ID
 -- --- ------------------ ---- --- ------------ ------------ --------------
  B  D  20240808094119001   F    D  S0000000.LOG S0000000.LOG                
 ----------------------------------------------------------------------------
  Contains 3 tablespace(s):

 00001 SYSCATSPACE
 00002 USERSPACE1
 00003 SYSTOOLSPACE
 ----------------------------------------------------------------------------
    Comment: DB2 BACKUP CATTEST OFFLINE
 Start Time: 20240808094119
   End Time: 20240808094227
     Status: A
 ----------------------------------------------------------------------------
  EID: 3 Location: DB2REMOTE://mys3/cbrbucket/cattest

 

That's it for today. If you have feedback, suggestions, or questions about this post, please reach out to me on Mastodon (@data_henrik@mastodon.social) or LinkedIn.