RMAN使用

1、 数据库状态

打开数据库,检查数据库是否处于归档模式

conn /assysdba

SQL> startup mount

ORACLE instance started.

Total System Global Area    443592704 bytes

FixedSize1337100 bytes

VariableSize335546612 bytes

DatabaseBuffers                    100663296 bytes

Redo Buffers                                6045696 bytes

Databasemounted.

SQL>alterdatabaseopen;

Databasealtered.

检查数据库是否处于归档模式

SQL> archiveloglist;

Databaselogmode                            No Archive Mode

Automatic archival                         Disabled

Archive destination                        USE_DB_RECOVERY_FILE_DEST

Oldest onlinelogsequence         20

Currentlogsequence                     22

调节数据库为归档模式

SQL> startup mount;

ORACLE instance started.

Total System Global Area    443592704 bytes

FixedSize1337100 bytes

VariableSize335546612 bytes

DatabaseBuffers                    100663296 bytes

Redo Buffers                                6045696 bytes

Databasemounted.

SQL>alterdatabasearchivelog;

Databasealtered.

SQL> archiveloglist;

Databaselogmode                            Archive Mode

Automatic archival                         Enabled

Archive destination                        USE_DB_RECOVERY_FILE_DEST

Oldest onlinelogsequence         20

Nextlogsequencetoarchive     22

Currentlogsequence                     22

一般在创建数据库时是不设置为ARCHIVE MODE 的。

将数据库的日志模式设置切换(Archive Mode 和No Archive Mode 之间的切换)的步骤和操作如下:

1. 关闭运行的数据库实例

SQL> shutdown

在进行日志模式切换之前,必须将运行的数据库正常关闭。

2. 备份数据库

该备份跟以后产生的日志一起用于将来的灾难恢复(很重要,如要改为归档日志模式,没有这个数据库备份,仅有日志文件是无法从该时间点恢复的)。

3. 启动数据库实例到mount 状态,但不要打开。

SQL> startup mount

4. 切换数据库日志模式。

SQL> alter database archivelog;(设置数据库为归档日志模式)或

SQL> alter database noarchivelog;(设置数据库为非归档日志模式)

5. 打开数据库

SQL> alter database open;

6. 确认数据库现在处于归档日志模式。

SQL> archive log list;

Database log mode Archive Mode

Automatic archival Enabled

Archive destination for example: $ORACLE_HOME/dbs/arch

Oldest on-line log sequence 275

Next log sequence 277

Current log sequence 278

7. 将这个时间点的redo logs 归档

SQL> archive log all;

8. 确认新产生的日志文件已在相应的归档目录下面。

9、在归档模式下,手动切换, 让在online redolog file里面的数据写到datafile里面去了;不然的话,需要联机重做日志文件满的时候才发生切换。

alter system checkpoint;

10、备份控制文件

alterdatabasebackupcontrolfiletotraceas'/u01/orcle/a.trc';

2、使用RMAN备份数据库

(1)RMAN连接数据库

[oracle@localhost ~]$rman target sys/china1ok nocatalog

(2)全备数据库

RMAN>listbackup;

specification doesnotmatchanybackupinthe repository

RMAN>backupdatabaseformat'/u01/backup/otter/md_%U';

Startingbackupat 10-APR-10

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=29 device type=DISK

channel ORA_DISK_1: startingfulldatafilebackupset

channel ORA_DISK_1: specifying datafile(s)inbackupset

input datafilefilenumber=00001name=/u01/oradata/otter/system01.dbf

input datafilefilenumber=00002name=/u01/oradata/otter/sysaux01.dbf

input datafilefilenumber=00003name=/u01/oradata/otter/undotbs01.dbf

input datafilefilenumber=00005name=/u01/oradata/otter/paul01.dbf

input datafilefilenumber=00004name=/u01/oradata/otter/users01.dbf

channel ORA_DISK_1: starting piece 1 at 10-APR-10

channel ORA_DISK_1: finished piece 1 at 10-APR-10

piece handle=/u01/backup/otter/md_01laom9t_1_1 tag=TAG20100410T074148 comment=NONE

channel ORA_DISK_1:backupsetcomplete, elapsed time: 00:01:56

channel ORA_DISK_1: startingfulldatafilebackupset

channel ORA_DISK_1: specifying datafile(s)inbackupset

includingcurrentcontrolfileinbackupset

includingcurrentSPFILEinbackupset

channel ORA_DISK_1: starting piece 1 at 10-APR-10

channel ORA_DISK_1: finished piece 1 at 10-APR-10

piece handle=/u01/backup/otter/md_02laomdh_1_1 tag=TAG20100410T074148 comment=NONE

channel ORA_DISK_1:backupsetcomplete, elapsed time: 00:00:01

Finishedbackupat 10-APR-10

RMAN> listbackup;

ListofBackupSets

===================

BSKeyType LVSizeDevice Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

1Full1015.33MDISK00:01:55         10-APR-10

BPKey: 1     Status: AVAILABLE    Compressed: NO    Tag: TAG20100410T074148

PieceName: /u01/backup/otter/md_01laom9t_1_1

ListofDatafilesinbackupset1

FileLV Type Ckp SCN        Ckp TimeName

---- -- ---- ---------- --------- ----

1Full1183863        10-APR-10 /u01/oradata/otter/system01.dbf

2Full1183863        10-APR-10 /u01/oradata/otter/sysaux01.dbf

3Full1183863        10-APR-10 /u01/oradata/otter/undotbs01.dbf

4Full1183863        10-APR-10 /u01/oradata/otter/users01.dbf

5Full1183863        10-APR-10 /u01/oradata/otter/paul01.dbf

BSKeyType LVSizeDevice Type Elapsed Time Completion Time

------- ---- -- ---------- ----------- ------------ ---------------

2Full9.36MDISK00:00:04         10-APR-10

BPKey: 2     Status: AVAILABLE    Compressed: NO    Tag: TAG20100410T074148

PieceName: /u01/backup/otter/md_02laomdh_1_1

SPFILE Included: Modification time: 10-APR-10

SPFILE db_unique_name: OTTER

ControlFileIncluded: Ckp SCN: 1183915            Ckp time: 10-APR-10

(3)部分备份数据库

RMAN> reportschema;

Reportofdatabaseschemafordatabasewithdb_unique_name OTTER

ListofPermanentDatafiles

===========================

FileSize(MB) Tablespace                     RB segs DatafileName

---- -------- -------------------- ------- ------------------------

1        680            SYSTEM                             ***         /u01/oradata/otter/system01.dbf

2        550            SYSAUX                             ***         /u01/oradata/otter/sysaux01.dbf

3        95             UNDOTBS1                         ***         /u01/oradata/otter/undotbs01.dbf

4        5                USERS                                ***         /u01/oradata/otter/users01.dbf

5        10             PAUL                                 ***         /u01/oradata/otter/paul01.dbf

ListofTemporaryFiles

=======================

FileSize(MB) Tablespace                     Maxsize(MB) TempfileName

---- -------- -------------------- ----------- --------------------

1        29TEMP32767             /u01/oradata/otter/temp01.dbf

RMAN>backupdatafile 5 format'/u01/backup/otter/otter_%U';

Startingbackupat 10-APR-10

using channel ORA_DISK_1

channel ORA_DISK_1: startingfulldatafilebackupset

channel ORA_DISK_1: specifying datafile(s)inbackupset

input datafilefilenumber=00005name=/u01/oradata/otter/paul01.dbf

channel ORA_DISK_1: starting piece 1 at 10-APR-10

channel ORA_DISK_1: finished piece 1 at 10-APR-10

piece handle=/u01/backup/otter/otter_05laonp1_1_1 tag=TAG20100410T080657 comment=NONE

channel ORA_DISK_1:backupsetcomplete, elapsed time: 00:00:01

Finishedbackupat 10-APR-10

Starting ControlFileandSPFILE Autobackup at 10-APR-10

piece handle=/u01/backup/otter/otter_c-151511358-20100410-00 comment=NONE

Finished ControlFileandSPFILE Autobackup at 10-APR-10

(4)、多路并发备份

run {

allocate channel c1 typedisk;

allocate channel c2 typedisk;

allocate channel c3 typedisk;

allocate channel c4 typedisk;

backupincrementallevel=0

format'/u01/backup/otter/p_%U'

(datafile 1 channel c1 tag=system)

(datafile 2 channel c2 tag=aux)

(datafile 3 channel c3 tag=und)

(datafile 4,5 channel c4 tag=users);

sql'alter system archive log current';

}

执行情况

RMAN> run {

2>    allocate channel c1 typedisk;

3> allocate channel c2 typedisk;

4>    allocate channel c3 typedisk;

5>    allocate channel c4 typedisk;

6>backupincrementallevel=0

7>    format'/u01/backup/otter/p_%U'

8>    (datafile 1 channel c1 tag=system)

9>    (datafile 2 channel c2 tag=aux)

10>    (datafile 3 channel c3 tag=und)

11>    (datafile 4,5 channel c4 tag=users);

12> sql'alter system archive log current';

13> }

allocated channel: c1

channel c1: SID=37 device type=DISK

allocated channel: c2

channel c2: SID=40 device type=DISK

allocated channel: c3

channel c3: SID=43 device type=DISK

allocated channel: c4

channel c4: SID=44 device type=DISK

Startingbackupat 10-APR-10

channel c1: starting incrementallevel0 datafilebackupset

channel c1: specifying datafile(s)inbackupset

input datafilefilenumber=00001name=/u01/oradata/otter/system01.dbf

channel c1: starting piece 1 at 10-APR-10

channel c2: starting incrementallevel0 datafilebackupset

channel c2: specifying datafile(s)inbackupset

input datafilefilenumber=00002name=/u01/oradata/otter/sysaux01.dbf

channel c2: starting piece 1 at 10-APR-10

channel c3: starting incrementallevel0 datafilebackupset

channel c3: specifying datafile(s)inbackupset

input datafilefilenumber=00003name=/u01/oradata/otter/undotbs01.dbf

channel c3: starting piece 1 at 10-APR-10

channel c4: starting incrementallevel0 datafilebackupset

channel c4: specifying datafile(s)inbackupset

input datafilefilenumber=00005name=/u01/oradata/otter/paul01.dbf

input datafilefilenumber=00004name=/u01/oradata/otter/users01.dbf

channel c4: starting piece 1 at 10-APR-10

channel c3: finished piece 1 at 10-APR-10

piece handle=/u01/backup/otter/p_0blaooqu_1_1 tag=UND comment=NONE

channel c3:backupsetcomplete, elapsed time: 00:00:06

channel c4: finished piece 1 at 10-APR-10

piece handle=/u01/backup/otter/p_0claooqv_1_1 tag=USERS comment=NONE

channel c4:backupsetcomplete, elapsed time: 00:00:03

channel c2: finished piece 1 at 10-APR-10

piece handle=/u01/backup/otter/p_0alaooqt_1_1 tag=AUX comment=NONE

channel c2:backupsetcomplete, elapsed time: 00:01:30

channel c1: finished piece 1 at 10-APR-10

piece handle=/u01/backup/otter/p_09laooqt_1_1 tag=SYSTEM comment=NONE

channel c1:backupsetcomplete, elapsed time: 00:01:51

Finishedbackupat 10-APR-10

Starting ControlFileandSPFILE Autobackup at 10-APR-10

piece handle=/u01/backup/otter/otter_c-151511358-20100410-02 comment=NONE

Finished ControlFileandSPFILE Autobackup at 10-APR-10

sql statement:altersystem archivelogcurrent

released channel: c1

released channel: c2

released channel: c3

released channel: c4

(5)、删除备份集

RMAN>deletebackupset 3,4,5,6,7,8,9,10,11,12,13;

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=37 device type=DISK

ListofBackupPieces

BPKeyBSKeyPc# Cp# Status            Device Type PieceName

------- ------- --- --- ----------- ----------- ----------

3             3             1     1     AVAILABLEDISK/u01/backup/otter/md_03laon1k_1_1

4             4             1     1     AVAILABLEDISK/u01/backup/otter/md_04laon5h_1_1

5             5             1     1     AVAILABLEDISK/u01/backup/otter/otter_05laonp1_1_1

6             6             1     1     AVAILABLEDISK/u01/backup/otter/otter_c-151511358-20100410-00

7             7             1     1     AVAILABLEDISK/u01/flash_recovery_area/OTTER/backupset/2010_04_10/o1_mf_nnndf_TAG20100410T081203_5vzjlmnz_.bkp

8             8             1     1     AVAILABLEDISK/u01/backup/otter/otter_c-151511358-20100410-01

9             9             1     1     AVAILABLEDISK/u01/backup/otter/p_0blaooqu_1_1

10            10            1     1     AVAILABLEDISK/u01/backup/otter/p_0claooqv_1_1

11            11            1     1     AVAILABLEDISK/u01/backup/otter/p_0alaooqt_1_1

12            12            1     1     AVAILABLEDISK/u01/backup/otter/p_09laooqt_1_1

13            13            1     1     AVAILABLEDISK/u01/backup/otter/otter_c-151511358-20100410-02

Do you really wanttodeletethe above objects (enter YESorNO)?yes

deletedbackuppiece

backuppiece handle=/u01/backup/otter/otter_05laonp1_1_1 RECID=5 STAMP=715939617

deletedbackuppiece

backuppiece handle=/u01/backup/otter/otter_c-151511358-20100410-00 RECID=6 STAMP=715939619

deletedbackuppiece

backuppiece handle=/u01/flash_recovery_area/OTTER/backupset/2010_04_10/o1_mf_nnndf_TAG20100410T081203_5vzjlmnz_.bkp RECID=7 STAMP=715939923

deletedbackuppiece

backuppiece handle=/u01/backup/otter/otter_c-151511358-20100410-01 RECID=8 STAMP=715939940

deletedbackuppiece

backuppiece handle=/u01/backup/otter/p_0blaooqu_1_1 RECID=9 STAMP=715940704

deletedbackuppiece

backuppiece handle=/u01/backup/otter/p_0claooqv_1_1 RECID=10 STAMP=715940706

deletedbackuppiece

backuppiece handle=/u01/backup/otter/p_0alaooqt_1_1 RECID=11 STAMP=715940702

deletedbackuppiece

backuppiece handle=/u01/backup/otter/p_09laooqt_1_1 RECID=12 STAMP=715940701

deletedbackuppiece

backuppiece handle=/u01/backup/otter/otter_c-151511358-20100410-02 RECID=13 STAMP=715940831

Deleted 9 objects

RMAN-06207: WARNING: 2 objects couldnotbe deletedforDISKchannel(s) due

RMAN-06208:tomismatched status.UseCROSSCHECK commandtofix status

RMAN-06210: ListofMismatched objects

RMAN-06211: ==========================

RMAN-06212:     Object TypeFilename/Handle

RMAN-06213:--------------- ---------------------------------------------------

RMAN-06214:BackupPiece        /u01/backup/otter/md_03laon1k_1_1

RMAN-06214:BackupPiece        /u01/backup/otter/md_04laon5h_1_1

(6)、备份多份文件

RMAN>backupcopies 2 datafile 4 format'/u01/backup/otter/b1/b1_%U','/u01/backup/otter/b2/b2_%U';

(7)、对备份集做备份

3、备份各种常用文件

备份datafile

bacup datafile '/u01/oradata/otter/user01.dbf' format '/u01/backup/user_%U';

备份tablespace

select tablespace_name, content from dba_tablespace;

bacup tablespace example,users format '/u01/backup/tbs_%U';

备份controlfile

configure controlfile autobackup clear;

show all;

configure controlfile autobackup on;时, 用rman备份其他文件的时候,则会自动备份controlfile和spfile文件

或使用include指令把控制文件进行备份,如:backup datafile 4 include current controlfile;

或RMAN>sql "alter database backup control file to ' '/temp/control.bin''";

备份spfile

controlfile autoback = on;时会自动产生备份

或backup spfile backup '/u01/backup/sp_%U';

备份归档日志文件archive log files

backup format '/u01/backup/ar_$t_%s_%p' archivelog alldelete all input;//防止重复备份,有则删掉

按时间进行备份

backup archivelog from time "sysdate-15" until time "sysdate-7";

按sequence number进行备份

------------------------------------------------------------------------------------------------------------------------------------------------

让系统处于自动归档方式:

1、查看系统所处的状态

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     20

Next log sequence to archive   22

Current log sequence           22

2、查看归档日志存储的路径

SQL> show parameter db_recovery_file

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_recovery_file_dest                string      /home/oracle/base/flash_recove

ry_area

db_recovery_file_dest_size           big integer 2G

3、手动切换重做日志文件,回写磁盘上面

SQL> alter system archive log current;

System altered.

4、查看磁盘上面的文件

[oracle@136_20 2010_04_15]$ ll -h

total 32M

-rw-r----- 1 oracle oinstall  32M Apr 15 09:56 o1_mf_1_15_5wdwm0pb_.arc

-rw-r----- 1 oracle oinstall  26K Apr 15 10:04 o1_mf_1_16_5wdx2cs0_.arc

-rw-r----- 1 oracle oinstall 1.0K Apr 15 10:05 o1_mf_1_17_5wdx2dpx_.arc

-rw-r----- 1 oracle oinstall 1.5K Apr 15 10:05 o1_mf_1_18_5wdx2hh5_.arc

-rw-r----- 1 oracle oinstall 1.0K Apr 15 10:05 o1_mf_1_19_5wdx2jrj_.arc

-rw-r----- 1 oracle oinstall 1.0K Apr 15 10:05 o1_mf_1_20_5wdx2lh5_.arc

-rw-r----- 1 oracle oinstall 1.0K Apr 15 10:05 o1_mf_1_21_5wdx2md6_.arc

-rw-r----- 1 oracle oinstall 734K Apr 15 10:08 o1_mf_1_22_5wdx8031_.arc

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,222评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,455评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,720评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,568评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,696评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,879评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,028评论 3 409
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,773评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,220评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,550评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,697评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,360评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,002评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,782评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,010评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,433评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,587评论 2 350

推荐阅读更多精彩内容