RAMN备份和恢复测试

为backup数据库用户创建默认表空间和temporary表空间
create tablespace backup datafile '/oradata/orcl/backup01.dbf' size 100M autoextend on maxsize 5G;
alter tablespace backup add datafile '/oradata/orcl/backup02.dbf' size 10M autoextend on maxsize 1G;
create temporary tablespace tmp_backup tempfile '/oradata/orcl/tmp_backup01.dbf' size 50M autoextend on maxsize 3G;
create user backup identified by backup default tablespace backup temporary tablespace tmp_backup;
grant connect,resource to backup;

SQL> create tablespace backup datafile '/oradata/orcl/backup01.dbf' size 100M autoextend on maxsize 5G;

Tablespace created.

SQL> alter tablespace backup add datafile '/oradata/orcl/backup02.dbf' size 10M autoextend on maxsize 1G;

Tablespace altered.

SQL> create temporary tablespace tmp_backup tempfile '/oradata/orcl/tmp_backup01.dbf' size 50M autoextend on maxsize 3G;

Tablespace created.

SQL> create user backup identified by backup default tablespace backup temporary tablespace tmp_backup;

User created.

SQL> grant connect,resource to backup;

Grant succeeded.

SQL>
SQL> conn backup/backup
$vi loop.sql
-- loop.sql

-- set echo off

drop table team1;

create table team1
(col1  number, col2 date);

drop sequence team1_seq;

create sequence team1_seq start with 1;

truncate table team1;

begin
for i in 1..100 loop    
      for i in 1..200 loop
       insert into team1
       values(team1_seq.nextval, sysdate);
   end loop;
commit;
end loop;
end;
/
-- end
SQL>@loop.sql
 
run
{
shutdown immediate;
startup mount;
backup database format '/home/oracle/temp/db_%U';
shutdown immediate;
startup;
}

SQL> select count(*) from team1;

  COUNT(*)
----------
     20000
     
RMAN> run
2> {
3> shutdown immediate;
4> startup mount;
5> backup database format '/home/oracle/temp/db_%U';
6> shutdown immediate;
7> startup;
8> }

database closed
database dismounted
Oracle instance shut down

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     242208768 bytes

Fixed Size                     2227176 bytes
Variable Size                184550424 bytes
Database Buffers              50331648 bytes
Redo Buffers                   5099520 bytes

Starting backup at 11-AUG-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oradata/orcl/system01.dbf
input datafile file number=00002 name=/oradata/orcl/sysaux01.dbf
input datafile file number=00005 name=/oradata/orcl/example01.dbf
input datafile file number=00006 name=/oradata/orcl/backup01.dbf
input datafile file number=00003 name=/oradata/orcl/undotbs01.dbf
input datafile file number=00007 name=/oradata/orcl/backup02.dbf
input datafile file number=00004 name=/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 11-AUG-15
channel ORA_DISK_1: finished piece 1 at 11-AUG-15
piece handle=/home/oracle/temp/db_07qebh80_1_1 tag=TAG20150811T162327 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:16
Finished backup at 11-AUG-15

Starting Control File and SPFILE Autobackup at 11-AUG-15
piece handle=/home/oracle/c-1414669689-20150811-01 comment=NONE
Finished Control File and SPFILE Autobackup at 11-AUG-15

database dismounted
Oracle instance shut down

connected to target database (not started)
Oracle instance started
database mounted
database opened

Total System Global Area     242208768 bytes

Fixed Size                     2227176 bytes
Variable Size                184550424 bytes
Database Buffers              50331648 bytes
Redo Buffers                   5099520 bytes

RMAN>


RMAN> list backup by file;


List of Datafile Backups
========================

File Key     TY LV S Ckp SCN    Ckp Time  #Pieces #Copies Compressed Tag
---- ------- -  -- - ---------- --------- ------- ------- ---------- ---
1    6       B  F  A 1137633    11-AUG-15 1       1       NO         TAG20150811T162327
     1       B  F  A 1098557    04-AUG-15 1       1       NO         TAG20150804T232713
2    6       B  F  A 1137633    11-AUG-15 1       1       NO         TAG20150811T162327
     1       B  F  A 1098557    04-AUG-15 1       1       NO         TAG20150804T232713
3    6       B  F  A 1137633    11-AUG-15 1       1       NO         TAG20150811T162327
     1       B  F  A 1098557    04-AUG-15 1       1       NO         TAG20150804T232713
4    6       B  F  A 1137633    11-AUG-15 1       1       NO         TAG20150811T162327
     1       B  F  A 1098557    04-AUG-15 1       1       NO         TAG20150804T232713
5    6       B  F  A 1137633    11-AUG-15 1       1       NO         TAG20150811T162327
     1       B  F  A 1098557    04-AUG-15 1       1       NO         TAG20150804T232713
6    6       B  F  A 1137633    11-AUG-15 1       1       NO         TAG20150811T162327
7    6       B  F  A 1137633    11-AUG-15 1       1       NO         TAG20150811T162327

List of Archived Log Backups
============================

Thrd Seq     Low SCN    Low Time  BS Key  S #Pieces #Copies Compressed Tag
---- ------- ---------- --------- ------- - ------- ------- ---------- ---
1    6       1095649    04-AUG-15 3       A 1       1       NO         TAG20150804T234227
1    7       1099283    04-AUG-15 3       A 1       1       NO         TAG20150804T234227
1    8       1099286    04-AUG-15 3       A 1       1       NO         TAG20150804T234227
1    9       1099289    04-AUG-15 3       A 1       1       NO         TAG20150804T234227
1    10      1099294    04-AUG-15 3       A 1       1       NO         TAG20150804T234227
1    11      1099297    04-AUG-15 3       A 1       1       NO         TAG20150804T234227
1    12      1099300    04-AUG-15 3       A 1       1       NO         TAG20150804T234227
1    13      1099303    04-AUG-15 3       A 1       1       NO         TAG20150804T234227

List of Control File Backups
============================

CF Ckp SCN Ckp Time  BS Key  S #Pieces #Copies Compressed Tag
---------- --------- ------- - ------- ------- ---------- ---
1137633    11-AUG-15 7       A 1       1       NO         TAG20150811T162443
1133752    11-AUG-15 5       A 1       1       NO         TAG20150811T154207
List of SPFILE Backups
======================

Modification Time BS Key  S #Pieces #Copies Compressed Tag
----------------- ------- - ------- ------- ---------- ---
05-AUG-15         7       A 1       1       NO         TAG20150811T162443
05-AUG-15         5       A 1       1       NO         TAG20150811T154207

RMAN>


SQL> select RECID, STAMP, COMPLETION_TIME, INCREMENTAL_LEVEL from v$backup_set;

     RECID      STAMP COMPLETIO INCREMENTAL_LEVEL
---------- ---------- --------- -----------------
         1  886894105 04-AUG-15
         3  886894947 04-AUG-15
         5  887470928 11-AUG-15
         6  887473477 11-AUG-15
         7  887473485 11-AUG-15

SQL> select RECID,SET_STAMP, TAG, STATUS, HANDLE from v$backup_piece order by SET_STAMP;

     RECID  SET_STAMP TAG                              S HANDLE
---------- ---------- -------------------------------- - --------------------------------------------------
         1  886894033 TAG20150804T232713               A /home/oracle/temp/02qdpreh_1_1
         2  886894109 TAG20150804T232713               D
         3  886894947 TAG20150804T234227               A /home/oracle/temp/04qdpsb3_1_1
         4  886895034 TAG20150804T234354               D
         5  887470927 TAG20150811T154207               A /home/oracle/c-1414669689-20150811-00
         6  887473408 TAG20150811T162327               A /home/oracle/temp/db_07qebh80_1_1
         7  887473483 TAG20150811T162443               A /home/oracle/c-1414669689-20150811-01

7 rows selected.

SQL>

SQL>  select TYPE, RECORDS_TOTAL, RECORDS_USED
  2   from v$controlfile_record_section
  3   where type like '%BACKUP%';

TYPE                         RECORDS_TOTAL RECORDS_USED
---------------------------- ------------- ------------
BACKUP SET                             409            7
BACKUP PIECE                           200            7
BACKUP DATAFILE                        245           16
BACKUP REDOLOG                         215            8
BACKUP CORRUPTION                      371            0
BACKUP SPFILE                          131            3

6 rows selected.

[oracle@xuh orcl]$ ls -g
total 2025168 -rw-r-----. 1 oinstall 104865792 Aug 11 16:25 backup01.dbf
-rw-r-----. 1 oinstall  10493952 Aug 11 16:25 backup02.dbf
-rw-r-----. 1 oinstall   9748480 Aug 11 16:47 control01.ctl
-rw-r-----. 1 oinstall   9748480 Aug 11 16:47 control02.ctl
-rw-r-----. 1 oinstall 328343552 Aug 11 16:25 example01.dbf
-rw-r-----. 1 oinstall  52429312 Aug 11 16:25 redo01.log
-rw-r-----. 1 oinstall  52429312 Aug 11 16:25 redo02.log
-rw-r-----. 1 oinstall  52429312 Aug 11 16:47 redo03.log
-rw-r-----. 1 oinstall 576724992 Aug 11 16:45 sysaux01.dbf
-rw-r-----. 1 oinstall 744497152 Aug 11 16:45 system01.dbf
-rw-r-----. 1 oinstall  30416896 Aug 11 13:37 temp01.dbf
-rw-r-----. 1 oinstall  52436992 Aug 11 15:34 tmp_backup01.dbf
-rw-r-----. 1 oinstall  99622912 Aug 11 16:45 undotbs01.dbf
-rw-r-----. 1 oinstall   5251072 Aug 11 16:25 users01.dbf
[oracle@xuh orcl]$ rm *
[oracle@xuh orcl]$ ls -g
total 0

run
{
restore database;
recover database noredo;
alter database open resetlogs;
}

[oracle@xuh ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Tue Aug 11 17:29:48 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (not mounted)

RMAN> restore controlfile from '/home/oracle/c-1414669689-20150811-01';

Starting restore at 11-AUG-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oradata/orcl/control01.ctl
output file name=/oradata/orcl/control02.ctl
Finished restore at 11-AUG-15

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN> run
2> {
3> restore database;
4> recover database noredo;
5> alter database open resetlogs;
6> }

Starting restore at 11-AUG-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /oradata/orcl/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /oradata/orcl/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /oradata/orcl/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /oradata/orcl/backup01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /oradata/orcl/backup02.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/temp/db_07qebh80_1_1
channel ORA_DISK_1: piece handle=/home/oracle/temp/db_07qebh80_1_1 tag=TAG20150811T162327
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:56
Finished restore at 11-AUG-15

Starting recover at 11-AUG-15
using channel ORA_DISK_1

Finished recover at 11-AUG-15

database opened

RMAN>

[oracle@xuh orcl]$ ls -g
total 2000688
-rw-r-----. 1 oinstall 104865792 Aug 11 17:31 backup01.dbf
-rw-r-----. 1 oinstall  10493952 Aug 11 17:31 backup02.dbf
-rw-r-----. 1 oinstall   9748480 Aug 11 17:36 control01.ctl
-rw-r-----. 1 oinstall   9748480 Aug 11 17:36 control02.ctl
-rw-r-----. 1 oinstall 328343552 Aug 11 17:31 example01.dbf
-rw-r-----. 1 oinstall  52429312 Aug 11 17:35 redo01.log
-rw-r-----. 1 oinstall  52429312 Aug 11 17:31 redo02.log
-rw-r-----. 1 oinstall  52429312 Aug 11 17:31 redo03.log
-rw-r-----. 1 oinstall 576724992 Aug 11 17:31 sysaux01.dbf
-rw-r-----. 1 oinstall 744497152 Aug 11 17:31 system01.dbf
-rw-r-----. 1 oinstall  20979712 Aug 11 17:32 temp01.dbf
-rw-r-----. 1 oinstall  52436992 Aug 11 17:32 tmp_backup01.dbf
-rw-r-----. 1 oinstall  99622912 Aug 11 17:31 undotbs01.dbf
-rw-r-----. 1 oinstall   5251072 Aug 11 17:31 users01.dbf
[oracle@xuh orcl]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Tue Aug 11 17:36:16 2015

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> conn backup/backup
Connected.
SQL> select count(*) from team1;

  COUNT(*)
----------
     20000

SQL>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30310891/viewspace-1768870/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30310891/viewspace-1768870/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值