Last active
August 29, 2015 14:22
-
-
Save geo-stanciu/4b55428ee461257eed6f to your computer and use it in GitHub Desktop.
oracle - simple test case for RMAN backup and point in time recovery
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
/* | |
Copyright (c) 2015, Gheorghita Stanciu gheorghita(dot)stanciu(at)gmail(dot)com | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without | |
modification, are permitted provided that the following conditions are met: | |
1. Redistributions of source code must retain the above copyright notice, this | |
list of conditions and the following disclaimer. | |
2. Redistributions in binary form must reproduce the above copyright notice, | |
this list of conditions and the following disclaimer in the documentation | |
and/or other materials provided with the distribution. | |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | |
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
The views and conclusions contained in the software and documentation are those | |
of the authors and should not be interpreted as representing official policies, | |
either expressed or implied, of the FreeBSD Project. | |
*/ | |
-- initialize the test database; | |
cd C:\app\Geo\product\12.1.0\dbhome_1\BIN | |
set ORACLE_SID=db1 | |
sqlplus / as sysdba | |
create tablespace tempdat datafile 'C:\APP\GEO\ORADATA\DB1\TEMPDAT01.DBF' size 50M; | |
create user geo identified by geo quota unlimited on tempdat; | |
alter user geo default tablespace tempdat; | |
grant create table to geo; | |
grant create session to geo; | |
create table geo.t1 (c1 number, c2 varchar2(32), constraint pk_t1 primary key (c1)); | |
insert into geo.t1 values (1, '1'); | |
insert into geo.t1 values (2, '2'); | |
insert into geo.t1 values (3, '3'); | |
commit; | |
exit; | |
rman target / | |
CONFIGURE CONTROLFILE AUTOBACKUP ON; | |
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "d:/backup/rman/db1/ctl_%F"; | |
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT "d:/backup/rman/db1/full_%u_%s_%p" MAXPIECESIZE 2048 M; | |
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 1; | |
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS; | |
CONFIGURE BACKUP OPTIMIZATION ON; | |
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DISK; | |
exit; | |
-------------------------------------------------------------------------------- | |
-- backup: | |
cd C:\app\Geo\product\12.1.0\dbhome_1\BIN | |
set ORACLE_SID=db1 | |
rman target / | |
BACKUP INCREMENTAL LEVEL 0 DATABASE PLUS ARCHIVELOG; | |
--BACKUP INCREMENTAL LEVEL 1 DATABASE PLUS ARCHIVELOG; | |
crosscheck backup; | |
crosscheck archivelog all; | |
delete noprompt expired archivelog all; | |
delete noprompt obsolete; | |
-------------------------------------------------------------------------------- | |
-- restore (on the same machine and the same file paths): | |
cd C:\app\Geo\product\12.1.0\dbhome_1\BIN | |
set ORACLE_SID=db1 | |
rman target / | |
shutdown immediate; | |
startup mount; | |
-- if you need to recover the control file: | |
shutdown immediate; | |
startup nomount; | |
set dbid=<DBID>; | |
restore controlfile from 'D:\backup\rman\db1\CTL_C-<DBID>-20150527-00'; | |
run | |
{ | |
sql 'alter session set NLS_DATE_FORMAT="DD/MM/YYYY HH24:MI:SS"'; | |
set until time="to_date('27/05/2015 20:55:00', 'dd/mm/yyyy HH24:mi:ss')"; | |
restore database; | |
recover database; | |
} | |
exit; | |
sqlplus / as sysdba | |
alter database open resetlogs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment