cancel
Showing results for 
Search instead for 
Did you mean: 

Recovery LOG Script

Former Member
0 Kudos

Hi we have copied our PRD system into a new box.

The new system is not a standby system of the PRD system, just a copy.

We have build a script that sends logbackups to tape and to this new system for recovery.

Is there a way to recover the log on the copied system with a script without user interaction?

I have tried this but no sucess

dbmcli -d PRD -u superdba,******* recover_start Autologbackup LOG

-24991,ERR_NODBSESSION: no database session available

Any help?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I have read before posting the link you mention but i cannot see how to automate it.

The link explain how to do it inside the DBMCLI with manual steps, what I need is to run a script in unix and restore the log without user interaction in the whole process, not even in DBMCLI.

Thank you.

lbreddemann
Active Contributor
0 Kudos

I see.

Well, there is no one-stop-solution here. MaxDB provides the technical options to create a standby db solution, but not the complete infrastructure for that.

You will have to create program, script or something like that, that knows what log backups are available for recovery and that triggers the recovery via dbmcli.

This is no easy task - I've seen bash scripts of customers doing exactly that, but these are rather complicated and I'm obviously not allowed to post them.

If you want to have a professional solution for that, there are 3rd party vendors, like '[Libelle|http://www.libelle.com/de/index.php?option=com_content&task=view&id=23&Itemid=101]' who provide software for this.

Anyhow, if you're used to shell programming it should be possible to figure this out:

1. find out, what logfiles are available for recovery.

2. find out, what is the current state of recovery (db_restartinfo, backup-history)

3. find out, which of the available logfiles contains the next needed log data (backup-history of the original system)

4. bring db to admin mode

5. get a db session (db_connect)

6. recover the first logfile (recover_start)

7. recover subsequent logiles (recover_replace)

6. stop the recovery (db_cancel) - this brings the db to offline mode

Now, you may start over again.

All the dbm commands should be run via 'dbmcli -U c <command>'.

The script may either prepare a dbmcli-scriptfile and call dbmcli once, or it may use shell-input-output-redirection to emulate interactive commands.

regards,

Lars

Former Member
0 Kudos

Lars

Thank for your help.

I have managed to make a script but now im facing a new problem.

I have managed to make a log restore automatically with the script.

my basic script was

db_admin

db_connect

recover_start Autlogbackup LOG SequenceNr

I can see the restore succesfully in the DBMGUI.

After that I tried to do a second restore with a log backup that wasnt there , so it obviously ended wrong.

Now a new log backup was shipped from original system and Im running my script for the second time.

And I get an Error -7075.

I've been looking around the krnlerr.msg and the error says

The LogIOSequencenumber of the savepoint (134954783) is not in the range from the backup [134954784,135141678]

Last logbackup ended in 134954783 and this new log backup starts in 784 which is the next number but the log restore is skipped.

Since I didnt had the 2 log backups in the same time I coudnt do the recover_replace of the 2nd log backup.

Which would be the procedure to restore a 2nd log backup? Between the 1st and 2nd log backup , 2 data backups have occured , is there a way to restore a 2nd log backup?

dbmcli on PRD>db_restartinfo

OK

Used LOG Page 134954783

First LOG Page 2147483647

Restartable 1

Id Restart Record erpprd:PRD_20070726_163011

Id LOG Info

Consistent 1

Log Volume Enabled 1

Log Auto Overwrite 0

Master Servernode

Converter Version 38497

Oldest Compatible Version 7.6.00.30

Queue Count 1

I see the Firs log page is invalid it should say 134954784 right? How do I fix it, is there a way without restoring the data backup?

Regards & Thanks.

lbreddemann
Active Contributor
0 Kudos

I knew this question would come up...

Fortunately I've written a note on this some time ago.

-


8<--snip----- Restore log delivers message -7075 SAP Note Number: 1008304 Symptom When you reload log backups using recover_start or recover_replace, the system issues message -7075 and does not import the log backups. Other terms -7075, Current SAVE SKIPPED, next is ready to take on this tape, standby DB, shadow database, log shipping Reason and Prerequisites You execute a log recover and receive return message -7075. (This may be the case, for example, for the permanent recovery of a shadow database.) Solution The MaxDB documentation describes the cause of the message stating that instead of the current log backup file (version file) one of the following files should be used. In many cases, this is the correct response because the message can often be traced back to the fact that the log backup currently in use was already imported. However, this is not always correct. The message actually means that, at the current point in the recovery chain, it is not the turn of the log backup currently in use. Therefore, it may be necessary to import a preceding log backup to enable you to import the current log backup. One important feature of the recovery of log backups is that these must always be imported in the same sequence in which they were created. For example: The database generated the log backups LOG.001, LOG.002, LOG.003 and LOG.004. When performing a recovery, they must be imported in the sequence in which they were generated: 001 - 002 - 003 - 004. If the sequence is changed (for example 001 - 003 - 004 - 002), the MaxDB issues the following message for log 003: "-3004,invalid log-backup: IOSequence mismatch". However, this is valid only if the recovery was not interrupted in the meantime (restore_cancel). If you stop the recovery and start it again for log 003, the MaxDB returns the output: OK Returncode -7075 Date Time Server Database Kernel version Pages Transferred 0 Pages Left 0 Volumes Medianame Location Errortext Label Is Consistent First LOG Page Last LOG Page DB Stamp 1 Date DB Stamp 1 Time DB Stamp 2 Date DB Stamp 2 Time Page Count 0 Devices Used Database ID Max Used Data Page Converter Page Count Although log 002 is required here, the system issues message -7075. To determine which log backup is required next, the MaxDB uses the log pages in the log backup and the "First LOG Page" in the log area of the DB. In the backup history, you can determine which log pages are contained in a log backup - for example in dbmcli: backup_history_open backup_history_list -c LABEL,FIRSTLOG,LASTLOG -l LOG The output then appears roughly as follows: LOG_00001| 0| 995| LOG_00002| 996| 1914| ... As you can easily see, log backup 1 contains the log pages 0 to 995 and log backup 2 seamlessly follows on with log pages 996 to 1914. You can use the command db_restartinfo to determine which log pages are still in the log area of the DB: db_restartinfo Used LOG Page 5245 First LOG Page 2147483647 (* see below) Therefore, the DB has a status that is more advanced than log backup 1 or 2. Therefore, you must import a log backup to which the following applies: "FIRSTLOG" <= "Used LOG Page". This functions in the same way if the log backups were imported in succession "in one go"; that is, in a recovery session. If the recovery was stopped in the meantime (recover_cancel), the DB requires a known starting point for the next time the recovery is started. This is the last imported log page, that is "Used LOG Page". However, this last imported log page is in the last recovered log backup and not in the next logical one. Therefore: If the log backup is started again (after a recover_cancel), you must first reimport the last imported log backup to provide the DB with the starting point. Therefore, if a shadow database (standby DB) was provided with log backups using a script, the sequence should be as follows: db_admin recover_start <medium name> LOG <X-1> recover_replace <medium name> <path for the log backup> <X> recover_cancel In doing so, keep in mind that log backup X must be imported here. Since the preceding log backup is already imported, it contains the starting point and therefore must be reentered (X-1) beforehand. (*) Comment: This value for "First LOG Page" occurs if the log area of the DB was not yet described or there is a history-lost situation. -
>8--snap---

I hope this helps.

regards,

Lars

Former Member
0 Kudos

Thank you again Lars.

I was able to do it thank you.

lbreddemann
Active Contributor
0 Kudos

HI Daniel,

good to hear that you made it.

I guess there will be much interest in your solution from the other readers of this forum.

So, do you think that you can provide your coding to the public?

best regards,

Lars

Former Member
0 Kudos

Well here it is, it consist in 2 files: restore.txt and restore_script. It only restores 1 log backup on each run.

So you probably add it to a cron. It was made in Solaris 5.10.

the logbackups should have 666 rights on it so prdadm can delete them after restore.

Restore.txt has the commands that the dbmcli should execute once inside the dbmcli.

Contents of restore.txt

db_admin

db_connect

recover_start Autologbackup LOG 1

recover_replace Autologbackup /sapdb/PRD/logbackups/logbackupPRD 2

recover_cancel

The restore_script has the logic for changing restore.txt before executing it

#!/bin/bash

IND=`ls /sapdb/PRD/logbackups/logbackupPRD* | cut -d. -f2 | sort -r | tail +2 | sort -r`

for i in $IND; do

ANT=`echo $i - 1 | bc`

POS=`echo $i + 1 | bc`

sed '/recover_start/s/'$ANT'/'$i'/g' /home/prdadm/restore.txt | sed '/recover_replace/s/'$i'/'$POS'/g' > /tmp/restore.$i.tmp

DIF=`diff /home/prdadm/restore.txt /tmp/restore.$i.tmp | wc -l`

if [ $DIF -eq 0 ]; then

echo "Error"

exit 1

else

cp /tmp/restore.$i.tmp /home/prdadm/restore.txt

dbmcli -U c -i /home/prdadm/restore.txt

if [ $? -eq 0 ]; then

rm /sapdb/PRD/logbackups/logbackupPRD.$i

rm /tmp/restore.$i.tmp

else

echo "Error"

exit 1

fi

fi

done

exit 0

Edited by: Daniel Rajmanovich on Oct 17, 2008 5:23 PM

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi all

And if anyone need a small script for windows environment:

(obviously, you will need to change the program paths, users and password - which you can also store in a file)

D:\sapdb\programs\pgm\dbmcli.exe -n localhost -d LDP -u SUPERDBA,xxxx db_admin

for /f "usebackq tokens=1,2,3,4 delims= " %%a in (`"D:\sapdb\programs\pgm\dbmcli.exe -n localhost -d LDP -u SUPERDBA,xxxx db_restartinfo |findstr /c:"Used LOG Page""`) do (set current_page=%%d)

set current_page="%current_page:* =%"

pause

for /f "usebackq tokens=1,2 delims=." %%a in (`"dir I:\LClogbackup\lc. /b /o:e"`) do (

for /f "usebackq tokens=1,2,3,4 delims= " %%g in (`"D:\sapdb\programs\pgm\dbmcli.exe -n localhost -d LDP -u SUPERDBA,xxxx medium_labeloffline lclogbackup %%b |findstr /c:"Last LOG Page""`) do (

call :find_backup_page %%j %%a %%b

)

)

:exit_loop

for /f "usebackq tokens=1,2 delims=." %%a in (`"dir I:\LClogbackup\lc. /b /o:e"`) do (

if /i %%b gtr %first_file% (echo recover_replace LClogbackup "I:\LClogbackup\LClogbackup" %%b >> c:\temp\import_script.txt))

D:\sapdb\programs\pgm\dbmcli.exe -n localhost -d LDP -u SUPERDBA,xxxx -i "c:\temp\import_script.txt"

goto end

:find_backup_page

set /i backup_page="%1"

if /i %current_page% equ "%1" (

echo db_connect > c:\temp\import_script.txt

echo recover_start LClogbackup LOG %3 >> c:\temp\import_script.txt

set first_file=%3

pause

goto exit_loop

)

:end

hope it will help anyone who need to do automatic log shipping for maxdb.

It is not the smartest script but it does the trick.

Eitan

Former Member
0 Kudos

Hello Eitan,

thank you for posting your script for the logshipping issue.

We've tried to adapt the code for our system landscape but when we execute the script we're running into an error:

") was unexpected at this time."

Can you please have a look again at your code; perhaps there's a mistype in it?!

Thank you in advance

...and a happy new year!

Peter

Former Member
0 Kudos

To make a more complete and automated Windows script, I have made some amendments so as it will generate a recovery file, using the logs it needs to get up to the last avilable log file page number, compared to its current log page number, and apply it, each time it is run, and then shut the db back down ready to be put back to admin mode for more log applications at a later point. It also looks at the live host to find out what backup page it is up to.

This needs to be run as a batch file rather than from the command line, due to the difference in the way windows interprets the %% variables between the two modes.

This can then be scheduled to run at set times and keeps the standby up to date. The script is in three sections, which gets around the issue of it trying to import the recovery script before it has finished.

The scripts need to be saved separately, and called from the central batch file on the standby server.

To adapt this script the database name needs changing from CSP, password needs setting where xxxx is present after SUPERDBA. Also the LiveDB variable needs setting to the FQDN of the live host server i.e. ADCB-EF-1.domain. Obviously if the locations of you dbmcli.exe and things are different they need to be amended also.

The command which searches for the logs (`"dir E:\Backup\CSP\Log\Auto\au. /b /o:e"`) would need to have the File\Device path for the log backup and the first couple of letters of the file name as would the name of the defined backup medium, in this case Auto_Log_Backup

**************************************************************

Script 1 u2013 Top level script to call the others and delete any previous import script file.

<Standby.bat> -

**************************************************************

del D:\Batch\Recovery_Script\import_script.txt /f /q

call d:\batch\Recovery_Builder.bat

sleep 5

call d:\batch\Recovery_Apply.bat

**************************************************************

Script 2 u2013 Sets DB to Admin mode and then builds the import list and exports to script file.

<Recovery_Builder.bat>

**************************************************************

rem %%a = Logfile Name

rem %%b = log file number

rem %%j = Page number

Set LiveDB=xxxxxx

D:\sapdb\programs\pgm\dbmcli.exe -n localhost -d CSP -u SUPERDBA,xxxxx db_admin

for /f "usebackq tokens=1,2,3,4 delims= " %%a in (`"D:\sapdb\programs\pgm\dbmcli.exe -n localhost -d CSP -u SUPERDBA,xxxxx db_restartinfo |findstr /c:"Used LOG Page""`) do (set current_page=%%d)

for /f "usebackq tokens=1,2 delims=." %%a in (`"dir E:\Backup\CSP\Log\Auto\au. /b /o:e"`) do (

for /f "usebackq tokens=1,2,3,4 delims= " %%g in (`"D:\sapdb\programs\pgm\dbmcli.exe -n %LiveDB% -d CSP -u SUPERDBA,xxxxx medium_label Auto_log_Backup %%b |findstr /c:"Last LOG Page""`) do (

call :find_backup_page %%j %%a %%b

)

)

:exit_loop

for /f "usebackq tokens=1,2 delims=." %%a in (`"dir E:\Backup\CSP\Log\Auto\au. /b /o:e"`) do (

if %%b GTR %first_file% (

echo recover_replace Auto_log_Backup "E:\Backup\CSP\Log\Auto\Autolog" %%b >> D:\Batch\Recovery_Script\import_script.txt))

goto end

:find_backup_page

set backup_page=%1

if %current_page% EQU %1 (

echo db_connect >> D:\Batch\Recovery_Script\import_script.txt

echo db_admin >> D:\Batch\Recovery_Script\import_script.txt

echo recover_start Auto_log_Backup LOG %3 >> D:\Batch\Recovery_Script\import_script.txt

set first_file=%3

if %current_page% GTR %1 goto exit_loop

)

:end

**************************************************************

Script 3 u2013 Imports the generated script and then sets the DB back to offline.

<Recovery_Apply.bat>

**************************************************************

D:\sapdb\programs\pgm\dbmcli.exe -n localhost -d CSP -u SUPERDBA,xxxxx -i "D:\Batch\Recovery_Script\import_script.txt"

lbreddemann
Active Contributor
0 Kudos

Hi all,

I took the freedom to copy the two script solutions to the SDN Wiki for MaxDB: [HowTo - Standby DB log shipping|https://wiki.sdn.sap.com/wiki/x/soVMB].

I suggest to make changes or additions directly to the Wiki page from now on, as it will be easier to find than this thread.

Thanks again for the contributions!

best regards,

Lars

Former Member
0 Kudos

I've spent quite some time now figuring this out and this script really works like a charm. Quite impressive.

I've posted a question here, but tested wrong. So my question is already answered. Remains the compliments to the 'scriptwriters'.

Edited by: Martin Loohuizen on Feb 24, 2009 4:54 PM

Former Member
0 Kudos

Hi,

When I tried to use script suggested by Daniel Rajmanovich  Oct 17, 2008 5:29 PM  in this thread, it is taking restore from log 001 but in my case I have already restored 700 logs now I want automatic restore through script should be started from 701 instead of 001.

Hope you got my point.

Awaiting for the response.

Regards,

Rohit

lbreddemann
Active Contributor
0 Kudos

> We have build a script that sends logbackups to tape and to this new system for recovery.

Ok, so the logshipping is done.

> Is there a way to recover the log on the copied system with a script without user interaction?

Sure - and you know what? They even documented it...

[Setting Up and Updating Standby Instances|http://maxdb.sap.com/doc/7_6/43/6799434c355f6ce10000000a1553f6/content.htm]

> I have tried this but no sucess

> dbmcli -d PRD -u superdba,******* recover_start Autologbackup LOG

> -24991,ERR_NODBSESSION: no database session available

Yeah, well - you did it wrong.

> Any help?

s.a.

regards,

Lars