Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 17, 2016
0 parents
commit 2a84be7
Showing
66 changed files
with
1,018 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Freeware License, some rights reserved | ||
|
||
Copyright (c) 2013 Darl Kuhn, Sam Alapati, and Arup Nanda | ||
|
||
Permission is hereby granted, free of charge, to anyone obtaining a copy | ||
of this software and associated documentation files (the "Software"), | ||
to work with the Software within the limits of freeware distribution and fair use. | ||
This includes the rights to use, copy, and modify the Software for personal use. | ||
Users are also allowed and encouraged to submit corrections and modifications | ||
to the Software for the benefit of other users. | ||
|
||
It is not allowed to reuse, modify, or redistribute the Software for | ||
commercial use in any way, or for a user�s educational materials such as books | ||
or blog articles without prior permission from the copyright holder. | ||
|
||
The above copyright notice and this permission notice need to be included | ||
in all copies or substantial portions of the software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#Apress Source Code | ||
|
||
This repository accompanies [*RMAN Recipes for Oracle Database 12c*](http://www.apress.com/9781430248361) by Darl Kuhn, Sam Alapati, and Arup Nanda (Apress, 2013). | ||
|
||
![Cover image](9781430248361.jpg) | ||
|
||
Download the files as a zip using the green button, or clone the repository to your machine using Git. | ||
|
||
##Releases | ||
|
||
Release v1.0 corresponds to the code in the published book, without corrections or updates. | ||
|
||
##Contributions | ||
|
||
See the file Contributing.md for more information on how you can contribute to this repository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Contributing to Apress Source Code | ||
|
||
Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. | ||
|
||
## How to Contribute | ||
|
||
1. Make sure you have a GitHub account. | ||
2. Fork the repository for the relevant book. | ||
3. Create a new branch on which to make your change, e.g. | ||
`git checkout -b my_code_contribution` | ||
4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. | ||
5. Submit a pull request. | ||
|
||
Thank you for your contribution! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SELECT | ||
dest_name | ||
,destination | ||
FROM v$archive_dest | ||
WHERE destination is not null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Beginning of Script | ||
# Start of Configurable Section | ||
export ORACLE_HOME=/opt/oracle/10.2/db_1 | ||
export ORACLE_SID=PRODB1 | ||
export TOOLHOME=/opt/oracle/tools | ||
export BACKUP_MEDIA=DISK | ||
export BACKUP_TYPE=FULL_DB_BKUP | ||
export MAXPIECESIZE=16G | ||
# End of Configurable Section | ||
# Start of site specific parameters | ||
export BACKUP_MOUNTPOINT=/oraback | ||
export DBAEMAIL="dbas@proligence.com" | ||
export DBAPAGER="dba.ops@proligence.com" | ||
export LOG_SERVER=prolin2 | ||
export LOG_USER=oracle | ||
export LOG_DIR=/dbalogs | ||
export CATALOG_CONN=${ORACLE_SID}/${ORACLE_SID}@catalog | ||
# End of site specific parameters | ||
export LOC_PREFIX=$BACKUP_MOUNTPOINT/loc | ||
export TMPDIR=/tmp | ||
export NLS_DATE_FORMAT="MM/DD/YY HH24:MI:SS" | ||
export TIMESTAMP=`date +%T-%m-%d-%Y` | ||
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/lib | ||
export LIBPATH=$ORACLE_HOME/lib:/usr/lib:/lib | ||
export SHLIB_PATH=$ORACLE_HOME/lib:/usr/lib:/lib | ||
export LOG=${TOOLHOME}/log | ||
LOG=${LOG}/log/${ORACLE_SID}_${BACKUP_TYPE}_${BACKUP_MEDIA}_${TIMESTAMP}.log | ||
export TMPLOG=$TOOLHOME/log/tmplog.$$ | ||
echo `date` "Starting $BACKUP_TYPE Backup of $ORACLE_SID \ | ||
to $BACKUP_MEDIA" > $LOG | ||
export LOCKFILE=$TOOLHOME/${ORACLE_SID}_${BACKUP_TYPE}_${BACKUP_MEDIA}.lock | ||
if [ -f $LOCKFILE ]; then | ||
echo `date` "Script running. Exiting ..." >> $LOG | ||
else | ||
echo "Do NOT delete this file. Used for RMAN locking" > $LOCKFILE | ||
$ORACLE_HOME/bin/rman log=$TMPLOG <<EOF | ||
connect target / | ||
connect catalog $CATALOG_CONN | ||
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '${ORACLE_HOME}/dbs/SNAPSHOT_${ORACLE_SID}_${TIMESTAMP}_CTL'; | ||
run | ||
{ | ||
allocate channel c1 type disk | ||
format '${LOC_PREFIX}1/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}_%p_%s.rman' | ||
maxpiecesize ${MAXPIECESIZE}; | ||
allocate channel c2 type disk | ||
format '${LOC_PREFIX}2/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}_%p_%s.rman' | ||
maxpiecesize ${MAXPIECESIZE}; | ||
allocate channel c3 type disk | ||
format '${LOC_PREFIX}3/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}_%p_%s.rman' | ||
maxpiecesize ${MAXPIECESIZE}; | ||
allocate channel c4 type disk | ||
format '${LOC_PREFIX}4/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}_%p_%s.rman' | ||
maxpiecesize ${MAXPIECESIZE}; | ||
allocate channel c5 type disk | ||
format '${LOC_PREFIX}5/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}_%p_%s.rman' | ||
maxpiecesize ${MAXPIECESIZE}; | ||
allocate channel c6 type disk | ||
format '${LOC_PREFIX}6/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}_%p_%s.rman' | ||
maxpiecesize ${MAXPIECESIZE}; | ||
allocate channel c7 type disk | ||
format '${LOC_PREFIX}7/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}_%p_%s.rman' | ||
maxpiecesize ${MAXPIECESIZE}; | ||
allocate channel c8 type disk | ||
format '${LOC_PREFIX}8/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}_%p_%s.rman' | ||
maxpiecesize ${MAXPIECESIZE}; | ||
backup | ||
incremental level 0 | ||
tag = 'LVL0_DB_BKP' | ||
database | ||
include current controlfile; | ||
release channel c1; | ||
release channel c2; | ||
release channel c3; | ||
release channel c4; | ||
release channel c5; | ||
release channel c6; | ||
release channel c7; | ||
release channel c8; | ||
allocate channel d2 type disk format '${LOC_PREFIX}8/CTLBKP_${ORACLE_SID}_${TIMESTAMP}.CTL'; | ||
backup current controlfile; | ||
release channel d2; | ||
} | ||
exit | ||
EOF | ||
RC=$? | ||
cat $TMPLOG >> $LOG | ||
rm $LOCKFILE | ||
echo `date` "Script lock file removed" >> $LOG | ||
if [ $RC -ne "0" ]; then | ||
mailx -s "RMAN $BACKUP_TYPE $ORACLE_SID $BACKUP_MEDIA Failed" \ | ||
$DBAEMAIL,$DBAPAGER < $LOG | ||
else | ||
cp $LOG ${LOC_PREFIX}1 | ||
mailx -s "RMAN $BACKUP_TYPE $ORACLE_SID $BACKUP_MEDIA Successful" \ | ||
$DBAEMAIL < $LOG | ||
fi | ||
scp $LOG ${LOG_USER}@${LOG_SERVER}:${LOG_DIR}/${ORACLE_SID}/. | ||
rm $TMPLOG | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
create script full_disk_db | ||
comment 'Full Backup as Backupset to Disk' | ||
{ | ||
allocate channel c1 type disk | ||
format 'c:\backup\rman_%U.rman'; | ||
backup | ||
database | ||
include current controlfile; | ||
release channel c1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
00 11 * * 0 /opt/oracle/tools/rman_full.disk.sh > /opt/oracle/tools/rman_full.disk.log 2>&1 | ||
00 11 * * 0 /opt/oracle/tools/rman_arc.disk.sh > /opt/oracle/tools/rman_arc.disk.log 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
@ECHO OFF | ||
:: Beginning of Script | ||
:: Start of Configurable Section | ||
set ORACLE_HOME=C:\oracle\product\12.1\db_1 | ||
set ORACLE_SID=MOBDB10 | ||
set TOOLHOME=C:\TOOLS | ||
set BACKUP_MEDIA=DISK | ||
set BACKUP_TYPE=FULL_DB_BKUP | ||
set MAXPIECESIZE=16G | ||
set BACKUP_MOUNTPOINT=c:\oracle\flash | ||
set DBAEMAIL="dbas@proligence.com" | ||
set DBAPAGER="dba.ops@proligence.com" | ||
set CATALOG_CONN=%ORACLE_SID%/%ORACLE_SID%@catalog | ||
set MS=mail.proligence.com | ||
:: | ||
:: end of Configurable Section | ||
:: | ||
set BACKUP_LOC_PREFIX=%BACKUP_MOUNTPOINT%\loc | ||
set TMPDIR=C:\temp | ||
set NLS_DATE_FORMAT="MM/DD/YY HH24:MI:SS" | ||
realdate /d /s="set curdate=" > %TOOLHOME%\tmp_dt.bat | ||
realdate /t /s="set curtime=" > %TOOLHOME%\tmp_tm.bat | ||
call %TOOLHOME%\tmp_dt.bat | ||
call %TOOLHOME%\tmp_tm.bat | ||
:: | ||
:: | ||
set LOG=%TOOLHOME%\%ORACLE_SID%_%BACKUP_TYPE%_%BACKUP_MEDIA%_%CURDATE%_%CURTIME%.log | ||
set TMPLOG=%TOOLHOME%\tmplog.$$ | ||
:: | ||
:: Build the Command File | ||
set FORMATSTRING=%BACKUP_LOC_PREFIX%1\%ORACLE_SID%_%%u_%%p.rman | ||
set CMDFILE=%TOOLHOME%\%ORACLE_SID%.rman | ||
echo run { > %CMDFILE% | ||
echo allocate channel c1 type disk >> %CMDFILE% | ||
echo format '%FORMATSTRING%' >> %CMDFILE% | ||
echo maxpiecesize %MAXPIECESIZE%; >> %CMDFILE% | ||
echo backup >> %CMDFILE% | ||
echo tablespace users; >> %CMDFILE% | ||
echo release channel c1; >> %CMDFILE% | ||
echo } >> %CMDFILE% | ||
:: End of Command File Generation | ||
:: | ||
echo Starting the script > %LOG% | ||
%ORACLE_HOME%\bin\rman target=/ catalog=%CATALOG_CONN% @%CMDFILE% log=%TMPLOG% | ||
:: | ||
:: Merge the Logfiles | ||
type %TMPLOG% >> %LOG% | ||
:: Check for errors | ||
:: | ||
echo THE OUTPUT WAS %ERRORLEVEL% >> %LOG% | ||
findstr /i "error" %LOG% | ||
if errorlevel 0 if not errorlevel 1 bmail -s %MS% -t %DBAPAGER% "Database" -m %LOG% | ||
@echo on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
create script full_disk_db | ||
{ | ||
allocate channel c1 type disk | ||
format '+DG1/%U.rmb'; | ||
backup | ||
database | ||
include current controlfile; | ||
release channel c1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
create global script gs_arc_disk_bkup | ||
comment 'Global Script to Backup Arc Logs Delete Input' | ||
{ | ||
allocate channel c1 type disk | ||
format 'C:\oraback\%U.rman'; | ||
backup | ||
archivelog | ||
all | ||
delete input; | ||
release channel c1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
replace script full_disk_db | ||
{ | ||
allocate channel c1 type disk | ||
format 'c:\backup\rman_%U.rman'; | ||
backup | ||
database | ||
include current controlfile; | ||
release channel c1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
COL dbid NEW_VALUE hold_dbid | ||
SELECT dbid FROM v$database; | ||
exec dbms_system.ksdwrt(2,'DBID: '||TO_CHAR(&hold_dbid)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
DECLARE | ||
finished BOOLEAN; | ||
v_dev_name VARCHAR2(75); | ||
BEGIN | ||
-- Allocate a channel, when disk then type = null | ||
-- If tape then type = sbt_tape. | ||
v_dev_name := dbms_backup_restore.deviceAllocate(type=>null, ident=>'d1'); | ||
-- | ||
dbms_backup_restore.restoreSetDatafile; | ||
-- Destination and name for restored control file. | ||
dbms_backup_restore.restoreControlFileTo(cfname=>'/tmp/control01.ctl'); | ||
-- | ||
-- Backup piece location and name. | ||
dbms_backup_restore.restoreBackupPiece( | ||
'/u01/rman/c-3412777350-20120722-00', finished); | ||
-- | ||
if finished then | ||
dbms_output.put_line('Control file restored.'); | ||
else | ||
dbms_output.put_line('Problem'); | ||
end if; | ||
-- | ||
dbms_backup_restore.deviceDeallocate('d1'); | ||
END; | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
SELECT | ||
a.thread#, b.open_mode, a.status, | ||
CASE | ||
WHEN ((b.open_mode='MOUNTED') AND (a.status='OPEN')) THEN | ||
'Crash Recovery req.' | ||
WHEN ((b.open_mode='MOUNTED') AND (a.status='CLOSED')) THEN | ||
'No Crash Rec. req.' | ||
WHEN ((b.open_mode='READ WRITE') AND (a.status='OPEN')) THEN | ||
'Inst. already open' | ||
WHEN ((b.open_mode='READ ONLY') AND (a.status='CLOSED')) THEN | ||
'Inst. open read only' | ||
ELSE 'huh?' | ||
END STATUS | ||
FROM v$thread a | ||
,gv$database b | ||
WHERE a.thread# = b.inst_id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
SET LINES 132 | ||
COL name FORM a40 | ||
COL status FORM A8 | ||
COL file# FORM 9999 | ||
COL control_file_SCN FORM 999999999999999 | ||
COL datafile_SCN FORM 999999999999999 | ||
-- | ||
SELECT | ||
a.name | ||
,a.status | ||
,a.file# | ||
,a.checkpoint_change# control_file_SCN | ||
,b.checkpoint_change# datafile_SCN | ||
,CASE | ||
WHEN ((a.checkpoint_change# - b.checkpoint_change#) = 0) THEN 'Startup Normal' | ||
WHEN ((b.checkpoint_change#) = 0) THEN 'File Missing?' | ||
WHEN ((a.checkpoint_change# - b.checkpoint_change#) > 0) THEN 'Media Rec. Req.' | ||
WHEN ((a.checkpoint_change# - b.checkpoint_change#) < 0) THEN 'Old Control File' | ||
ELSE 'what the ?' | ||
END datafile_status | ||
FROM v$datafile a -- control file SCN for datafile | ||
,v$datafile_header b -- datafile header SCN | ||
WHERE a.file# = b.file# | ||
ORDER BY a.file#; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
select file#, status, error,recover from v$datafile_header; | ||
select file#, online_status, error from v$recover_file; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
SET SERVEROUTPUT ON | ||
DECLARE | ||
finished BOOLEAN; | ||
v_dev_name VARCHAR2(10); | ||
TYPE v_filestable IS TABLE OF varchar2(500) INDEX BY BINARY_INTEGER; | ||
BEGIN | ||
-- Allocate channel, when disk then type = null, if tape then type = sbt_tape. | ||
v_dev_name := dbms_backup_restore.deviceAllocate(type=>null, ident=> 'd1'); | ||
-- Set beginning of restore operation (does not restore anything yet). | ||
dbms_backup_restore.restoreSetDatafile; | ||
-- Define datafiles and locations for this backup piece. | ||
dbms_backup_restore.restoreDatafileTo(dfnumber=>1, | ||
toname=>'/u01/dbfile/o12c/system01.dbf'); | ||
dbms_backup_restore.restoreDatafileTo(dfnumber=>4, | ||
toname=>'/u01/dbfile/o12c/users01.dbf'); | ||
dbms_backup_restore.restoreDatafileTo(dfnumber=>5, | ||
toname=>'/u01/dbfile/o12c/tools01.dbf'); | ||
-- Restore the datafiles in this backup piece. | ||
dbms_backup_restore.restoreBackupPiece(done => finished, | ||
handle=>'/u01/app/oracle/product/12.1.0.1/db_1/dbs/38nhakpe_1_1', | ||
params=>null); | ||
IF finished THEN | ||
dbms_output.put_line('Datafiles restored'); | ||
ELSE | ||
dbms_output.put_line('Problem'); | ||
END IF; | ||
-- | ||
dbms_backup_restore.deviceDeallocate('d1'); | ||
END; | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
set head off feed off verify off echo off pages 0 trimspool on | ||
set lines 132 pagesize 0 | ||
spo newname.sql | ||
-- | ||
select 'run{' from dual; | ||
-- | ||
select | ||
'set newname for datafile ' || file# || ' to ' || '''' || name || '''' || ';' | ||
from v$datafile; | ||
-- | ||
select | ||
'restore database;' || chr(10) || | ||
'switch datafile all;' || chr(10) || | ||
'}' | ||
from dual; | ||
-- | ||
spo off; |
Oops, something went wrong.