HADR- DB2 DB restore failed due to "SQL2062N An error occurred while accessing media "libdb2encr.so". Reason code: "1""

When you try to restore an encrypted backup taken from source DB, the below error appears when something is wrong with encryption files(keystrores)

manoj@db2drserver~]$ db2 restore database TEST redirect generate script restore_test.sql

SQL2062N  An error occurred while accessing media "libdb2encr.so".  Reason

code: "1".
====================================================== 

Follow the below steps to resolve this issue. 

1. check keystore location "KEYSTORE_LOCATION" in primary DB and it's contents. 

[manoj@db2primserver ~]$  db2 get dbm cfg | grep -i key

 SSL server keydb file                   (SSL_SVR_KEYDB) =

 SSL client keydb file                  (SSL_CLNT_KEYDB) =

 Keystore type                           (KEYSTORE_TYPE) = PKCS12

 Keystore location                   (KEYSTORE_LOCATION) = /opt/test/ENCRYPT/keystore.p12

[manoj@db2primserver~]$ cd /opt/test/ENCRYPT/
[manoj@db2primserver~]$ gsk8capicmd_64 -keydb -list -db /opt/test/dbdata/drinst1/ENCRYPT/keystore.p12 -stashed

[manoj@db2primserver~]$ gsk8capicmd_64 -cert -list all -db keystore.p12 -stashed


2. Transfer the keystore files from source to target. 

scp -i db2-server-key.pem /tmp/keystore.* manoj@db2drserver:/tmp/

keystore.sth
keystore.p12

 3. Create a directory and place encryption key files. 

 db2 get dbm cfg | grep -i key
gsk8capicmd_64 -cert -list all -db keystore.p12 -stashed

4. Update the file.

[manoj@db2drserver~]$cd /opt/test/dbdata/db2inst1/ENCRYPT
-->> db2 update dbm config using KEYSTORE_LOCATION /opt/test/dbdata/db2inst1/ENCRYPT/keystore.p12 KEYSTORE_TYPE PKCS12

-->> db2 update dbm cfg using KEYSTORE_TYPE PKCS12

-->>  db2 terminate
-->>db2stop
-->>db2start

5. Generate the restore script from backup location and create the required path which will be mentioned in the script. 

[manoj@db2drserver~]$cd /mnt/backup/
[manoj@db2drserver~]$db2 restore database TEST redirect generate script restore_DR.sql
DB20000I  The RESTORE DATABASE command completed successfully.

7. make a copy of generated scripts and modify it according to the path. 

cp restore_DR.sql res.sql

[manoj@db2drserver~]$ nohup db2 -tvf res.sql &

[1] 489880

[manoj@db2drserver~]$nohup: ignoring input and appending output to 'nohup.out'

[manoj@db2drserver~]$

---->>> Updated db2 Restore command will be-

RESTORE DATABASE TEST FROM '/mnt/backup' TAKEN AT 20250716094612 ON '/opt/test/dbdata/db2inst1/db2inst1/dbpath' DBPATH ON '/opt/test/dbdata/db2inst1/db2inst1/dbpath' INTO TEST LOGTARGET '/opt/test/dbdata/db2inst1/db2inst1/log/' NEWLOGPATH '/opt/test/dbdata/db2inst1/db2inst1/log/' WITH 35 BUFFERS BUFFER 8096 REPLACE EXISTING REDIRECT ENCRYPT

SQL1277W  A redirected restore operation is being performed. During a table

space restore, only table spaces being restored can have their paths

reconfigured. During a database restore, storage group storage paths and DMS

table space containers can be reconfigured.

DB20000I  The RESTORE DATABASE command completed successfully.






Comments

Popular Posts