on 10-14-2008 9:22 PM
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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
I knew this question would come up...
Fortunately I've written a note on this some time ago.
-
I hope this helps.
regards,
Lars
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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"
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
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
> 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.