Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore archive logs only #55

Open
hsc2013 opened this issue Nov 8, 2022 · 9 comments
Open

Restore archive logs only #55

hsc2013 opened this issue Nov 8, 2022 · 9 comments

Comments

@hsc2013
Copy link

hsc2013 commented Nov 8, 2022

Is it possible to restore only archive logs that are not part of the online backup image?
E.g

Today some logs got archived in the case of db2. I never took the online backup. The next day, I tried to restore only the archive log which was archived the day before.

@tasdevil13
Copy link

First of all, transaction logs contain only the changes in the database.
Every restore needs a base image of the data, before the changes can be applied.
Your database can be in Circular Logging mode (aka only offline backups possible) or Archival Logging mode (aka LOGRETAIN=YES). If you switch a database to Archival Logging mode, you have to take an initial base image.
If you have this base image and all transaction logs since the creation of this image, you can restore the base image and rollforward your database to almost any point in time in your transaction logs.
If you take an online (or offline) backup of your database with Archival Logging enabled, you can also use this intermediate "snapshot" as a later base for restore and rollforward.

I hope this helps to understand the concept.

@hsc2013
Copy link
Author

hsc2013 commented Nov 9, 2022

I am looking to restore a particular transaction log that has been already archived. Let's suppose we have a base image and some logs number C4 and C5 got archived. Now, I need to get C4 and C5 or any archive log. Do we have any procedure to get an archive log that is not part of the online backup?

@tasdevil13
Copy link

There is a utility db2adutl which can retrieve archived logs from Spectrum Protect aka TSM (db2adutl extract logs ...) https://www.ibm.com/docs/en/db2/11.5?topic=sc-db2adutl-managing-db2-objects-within-tsm
But it is not possible to apply just random transaction logs to some base image. They all have to be applied in order.

@kdrodger
Copy link
Member

kdrodger commented Nov 9, 2022

Right, @tasdevil13 is correct and the answer depends on where the logs were archived, @hsc2013 . It's fairly common that most log files and log archives would not included in online backup images. The backup image only includes those log files which were active during the time of the online backup - the minimal set required for roll forward recovery, and even then only to a point of consistency at the end of the backup operation.

The more important question is what you wish to do with the log file and what you need to accomplish, especially without a backup image which is the starting point for roll-forward recovery and the processing of transaction log files.

@hsc2013
Copy link
Author

hsc2013 commented Nov 10, 2022

@kdrodger, I am looking for a feature to restore the archive log separately and we can restore the image to any point in time that might be helpful in case of disaster recovery. Do we have any sample code for reference from the IBM db2 side for restoring the archive log?

@tasdevil13
Copy link

Still it is unclear, why someone really wants to read/restore a log file apart from the base image. It is just bit trash, as usually a log entry is mostly an XOR image of the changed data. So, without knowing the previous value, it is useless.
But maybe @hsc2013 wants to do some log file analysis or extract changes from the file. You might want to have a look at Db2 Recovery Expert, https://www.ibm.com/docs/en/db2reluw/5.1?topic=overview

@hsc2013
Copy link
Author

hsc2013 commented Nov 10, 2022

@tasdevil13, it is unclear from db2 recovery link. Please let us know if there is a sample API code to get the required logs or not?

@tasdevil13
Copy link

First of all: I'm not IBM. I may sound so, but I'm not.

There is an API to read log files: https://www.ibm.com/docs/en/db2/11.5?topic=da-db2readlog-read-log-records
Sample code is just around the corner: https://github.com/IBM/db2-samples/blob/master/c/utilrecov.c

However, I remember the details of the log structure is still private to IBM and may be licensed somehow. For the regular database customer this is kept as a black box for security reasons. Maybe @kdrodger can point you in the right direction.

And you are still talking about "get the required logs". Getting the file is as easy as a piece of cake. Using the information in the file itself is something different. And it is not possible to just have some transaction log file somewhere in the middle of a log chain, read some bytes and -- bing! -- have the data back. It is AFAIK much more complex than that.

@kdrodger
Copy link
Member

That's right. @hsc2013, there is an API to read log file contents but that's not likely what you want.

Db2 transaction logs are not backup images that can be applied to a database, or 'restored' in any sense. You must have a backup, and many backups would likely be wise. If I'm understanding your use-case, transaction logs would only be applied by Db2's own ROLLFORWARD process, and only after a database or tablespace restore for what it sounds like you're doing. They are records of changes which occurred on the database, recorded in this write-ahead log, which are used by the data server to establish correctness and consistency after roll-forward after restore, crash recovery, and more.

Roll forward examples and details can be found, here:
https://www.ibm.com/docs/en/db2/11.5?topic=rollforward-examples

Log file management, including archive and retrieval is discussed at some length, here. In some sense, they're just files so you can copy them however you like. However, they are also vital components of the DBMS so moving or deleting them should only be done very, very carefully and they should never be modified.
https://www.ibm.com/docs/en/db2/11.5?topic=solution-log-file-management

There are also lots of interesting blogs and IDUG presentations on the topic, for instance:
https://datageek.blog/en/2012/07/17/db2-database-restore-and-rollforward-details-of-log-files/
https://www.idug.org/HigherLogic/System/DownloadDocumentFile.ashx?DocumentFileKey=ba593641-2ef8-49c2-9eb7-8825406a7cec

Perhaps what you're after is more like the RECOVER DATABASE command, which is designed to encapsulate all of this and do it all correctly for you -- restoring and rolling forward a database to a specific point in time (or end of logs).
https://www.ibm.com/docs/en/db2/11.5?topic=commands-recover-database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants