Oracle RMAN 学习:三思笔记
1 进入rman
Rman--物理备份(结构/数据)
1 本地db
Cmd
set oracle_sid=orcl
1 rman target /
Rman>
2 也可以先直接进入rman
然后>connect target /
2 远程db(有效的service_name,本地的tns中有该service的正确配置)
Cmd
Rman target sys/xxxxx@orcl111
3 退出rman
直接exit
在启用rman时,可以指定日志输出
Rman target / log f:mydb man_log.txt
2 熟悉rman操作
Rman的备份跟恢复,db都必须启动实例并加载数据库
Nomount---mount---open
Oracle如果是db处于open状态(open read write),则db要处于归档状态,否则在备份操作的时候有可能出现ora—19602错误
1 启动和关闭数据库
Rman target /
Rman>shutdown immediate;
Rman>startup;
启动关闭命令跟sqlplus环境下 相同
2 执行操作系统命令
Rman支持在rman命令下使用host命令暂时退出rman
Rman>host;
执行完操作系统命令后,可以通过exit命令切换到rman提示符
3 执行sql语句
在rman提示符下,
RMAN
[ TARGET connectStringSpec
| { CATALOG connectStringSpec }
| LOG ['] filename ['] [ APPEND ]
.
.
.
]...
connectStringSpec::=
['] [userid] [/ [password]] [@net_service_name] [']
Rman> sql ‘select sysdate from dual’ 此时执行不会有结果输出
Rman>sql ‘alter system archive log all’
可以通过host命令切换到操作系统,然后conn / as sysdba等进行操作,然后exit到rman
Linux下:
Last login: Wed Oct 23 09:47:15 2013 from 192.168.2.187
[root@localhost ~]# su - oracle
[oracle@localhost ~]$ rman target/
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Oct 24 09:51:20 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: GRS (DBID=325518186)
RMAN> host;
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 24 09:51:51 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected.
SQL> select sysdate from dual;
SYSDATE
------------
24-OCT-13
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@localhost ~]$ exit
exit
host command complete
RMAN>
12c rman
RMAN> select sysdate from dual;
SYSDATE
-------------------
2015-08-05 00:03:27
4 rman备份类型
1 镜像复制:copy,将一一系列文件copy
2备份集:优势(备份时只读取数据库中已使用的数据块)
5 rman命令执行方式
1 单个执行命令
Rman>backup database;
2 批处理方式
Rman>run{
………..},将多个单个命令组合到一起,其中任何一个命令失败都将停止(后面的命令不在执行),有些特殊命令不能放到批处理中(list ,report。)
3 运行脚本
A 用命令方式调用os中保存的脚本
Rman target / @backup_db.rman
或者 rman target / cmdfile=backup_db.rman
B 在rman中执行脚本
Rman> @backup_db.rman
C 运行存储在catalog中的脚本(首先为rman创建恢复目录)
Rman> run {execute script backup_db};
3 rman 初级演练
1 整个库的备份
Rman>backup database;--对所有数据文件进行备份,
Rman>backup database format ‘f:mydbackupack_db%u’;
此时没归档,报错ora-19602,改为archived模式,正常执行
alter system set log_archive_dest_1='location= /data/u02/app/frarea';
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 10/24/2013 10:34:34
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
可以用list backup of database;来查看全部备份的文件
RMAN> backup database format '/u01/oracle/backup/back_%U';
Starting backup at 24-OCT-13
using channel ORA_DISK_1
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 10/24/2013 10:56:39
ORA-01013: user requested cancel of current operation
continuing other job steps, job failed will not be re-run
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/oracle/backup/back_04on6v77_1_1 tag=TAG20131024T105639 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 10/24/2013 10:56:39
ORA-01013: user requested cancel of current operation
RMAN> exit
Recovery Manager complete.
[oracle@localhost ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Oct 24 10:57:04 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: GRS (DBID=325518186)
RMAN> list backup of database;
using target database control file instead of recovery catalog
RMAN> backup database format '/u01/oracle/backup/back_%U';
Starting backup at 24-OCT-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/grs/system01.dbf
input datafile fno=00007 name=/u01/app/oracle/oradata/grs/cmask01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/grs/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/grs/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/grs/yyhhqq.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/grs/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/grs/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/oracle/backup/back_05on6v94_1_1 tag=TAG20131024T105740 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:37
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/oracle/backup/back_06on6ve1_1_1 tag=TAG20131024T105740 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 24-OCT-13
RMAN> list backup of database;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 645.97M DISK 00:02:35 24-OCT-13
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20131024T105740
Piece Name: /u01/oracle/backup/back_05on6v94_1_1
List of Datafiles in backup set 3
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 988527 24-OCT-13 /u01/app/oracle/oradata/grs/system01.dbf
2 Full 988527 24-OCT-13 /u01/app/oracle/oradata/grs/undotbs01.dbf
3 Full 988527 24-OCT-13 /u01/app/oracle/oradata/grs/sysaux01.dbf
4 Full 988527 24-OCT-13 /u01/app/oracle/oradata/grs/users01.dbf
5 Full 988527 24-OCT-13 /u01/app/oracle/oradata/grs/example01.dbf
6 Full 988527 24-OCT-13 /u01/app/oracle/oradata/grs/yyhhqq.dbf
7 Full 988527 24-OCT-13 /u01/app/oracle/oradata/grs/cmask01.dbf
RMAN>
2 表空间的备份
只要db处于mount状态,不论是否打开,都可以进行rman 备份表空间
Rman> backup tablespace users;
-----backup tablespace users format 'f:mydbackupackup_tp_users';
List backup of tablespace users; list backup查看一下备份
删除备份:delete backupset 4(bs key)
RMAN> backup tablespace yyhhqq;-------没有指定详细路径
Starting backup at 24-OCT-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00006 name=/u01/app/oracle/oradata/grs/yyhhqq.dbf
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_nnndf_TAG20131024T110255_96k3h019_.bkp tag=TAG20131024T110255 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 24-OCT-13
RMAN> list backup of tablespace yyhhqq;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 645.97M DISK 00:02:35 24-OCT-13
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20131024T105740
Piece Name: /u01/oracle/backup/back_05on6v94_1_1
List of Datafiles in backup set 3
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 988527 24-OCT-13 /u01/app/oracle/oradata/grs/yyhhqq.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5 Full 712.00K DISK 00:00:09 24-OCT-13
BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20131024T110255
Piece Name: /u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_nnndf_TAG20131024T110255_96k3h019_.bkp
List of Datafiles in backup set 5
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 988697 24-OCT-13 /u01/app/oracle/oradata/grs/yyhhqq.dbf
RMAN> backup tablespace yyhhqq;
3数据文件的备份
有2 种方式指定数据文件(详细路径)和file_id,都可以从视图dba_data_files中得到
select file_id,file_name from dba_data_files
4 /u01/app/oracle/oradata/grs/users01.dbf
3 /u01/app/oracle/oradata/grs/sysaux01.dbf
在整库备份和list时都会出现file_id和数据文件的名称
RMAN> backup datafile '/u01/app/oracle/oradata/grs/users01.dbf' format '/u01/oracle/backup/backup_datafile_%U';
RMAN> backup datafile 6 format '/u01/oracle/backup/backup_data6_%p_%I_%t;
Piece Name: /u01/oracle/backup/backup_data6_1_325518186_830601460;
Starting backup at 24-OCT-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00004 name=/u01/app/oracle/oradata/grs/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/oracle/backup/backup_datafile_09on7bsd_1_1 tag=TAG20131024T143245 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 24-OCT-13
可以用file_id代替 backup datafile 6,7,8
RMAN> list backup of datafile 4;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 645.97M DISK 00:02:35 24-OCT-13
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20131024T105740
Piece Name: /u01/oracle/backup/back_05on6v94_1_1
List of Datafiles in backup set 3
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 988527 24-OCT-13 /u01/app/oracle/oradata/grs/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
6 Full 8.94M DISK 00:00:02 24-OCT-13
BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20131024T143245
Piece Name: /u01/oracle/backup/backup_datafile_09on7bsd_1_1
List of Datafiles in backup set 6
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 995093 24-OCT-13 /u01/app/oracle/oradata/grs/users01.dbf
4控制文件的备份
Rman>backup current controlfile;
backup current controlfile
执行backup命令时指定include current controlfile
Rman>backup database include current controlfile
通过指定configure命令将controlfile autobackup置为on
Rman>configure controlfile autobackup on/off; rman做任何备份操作都会备份控制文件
List backup of controlfile
RMAN> backup current controlfile format '/u01/oracle/backup/backup_control_file';
Starting backup at 24-OCT-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/oracle/backup/backup_control_file tag=TAG20131024T144627 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 24-OCT-13
RMAN> list backup of controlfile;
List of Backup Sets
RMAN> configure controlfile autobackup on;----任何backup都会备份控制文件
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
The RMAN BACKUP CURRENT CONTROLFILE command makes a binary backup of
the control file, as either a backup set or an image copy.
The SQL statement ALTER DATABASE BACKUP CONTROLFILE makes a binary
backup of the control file.
The SQL statement ALTER DATABASE BACKUP CONTROLFILE TO TRACE exports
the control file contents to a SQL script file. You can use the script to create a new
control file. Trace file backups have one major disadvantage: they contain no
records of archived redo logs, and RMAN backups and copies. For this reason,
binary backups are preferable.
使用alter database backup controlfile备份控制文件
SQL> alter database backup controlfile to trace;
或者
SQL> alter database backup controlfile to trace as '/data/controlfile1.cof'; (这样你可以查看controlfile的构成)
5归档文件的备份
1 RMAN> backup archivelog all;
Starting backup at 24-OCT-13
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=20 recid=1 stamp=829666475
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_annnn_TAG20131024T145435_96kk1gpx_.bkp tag=TAG20131024T145435 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 24-OCT-13
Starting Control File and SPFILE Autobackup at 24-OCT-13
piece handle=/u01/app/oracle/flash_recovery_area/GRS/autobackup/2013_10_24/o1_mf_s_829666480_96kk1jj2_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 24-OCT-13
Backup archivelog命令比较灵活,all是指备份当前所有可访问到的归档文件夹,
还可以通过until,scn,time,sequence等参数灵活指定备份的归档区间。
2 执行backup时指定plus archivelog字句
Rman>backup current controlfile plus archivelog
在备份控制文件之前先对归档文件进行备份,
Backup 。。。 plus archivelog,命令执行以下步骤
A 运行alter system archive log current语句对当前redolog进行归档
B 执行backup archivlelog all命令 备份所有归档文件
C 执行backup命令对指定项进行备份
D 再次运行alter system archive log current对redolog进行归档
E 对新生成的尚未备份的归档文件进行备份
完成了归档日志的备份后,我们需要删除过期的归档文件的备份,
Rman,提供了delete all input参数,加在backup命令后,则会完成备份后自动删除归档目录中已备份的归档日志,
RMAN> delete archivelog all like '/backup/archivelog1/%' backed up 1 times to device type disk;
Rman>list backup of archivelog all;
--delete noprompt archivelog all completed before 'sysdate'; --->该命令清除所有的归档日志
delete noprompt archivelog all; --->同上一命令
6初始化参数文件的备份
通常在备份控制文件时,rman会自动备份服务器端的初始化参数文件,并置于控制文件相同的备份片中,/u01/app/oracle/product/10.2.0/db_1/dbs/spfilegrs.ora
Rman>backup spfile;单独备份参数文件
RMAN> backup spfile format '/u01/oracle/backup/backup_spfile';
Starting backup at 24-OCT-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/oracle/backup/backup_spfile tag=TAG20131024T145840 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 24-OCT-13
Starting Control File and SPFILE Autobackup at 24-OCT-13
piece handle=/u01/app/oracle/flash_recovery_area/GRS/autobackup/2013_10_24/o1_mf_s_829666721_96kk91h7_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 24-OCT-13
RMAN> backup spfile format '/u01/oracle/backup
2> ';
Starting backup at 14-MAR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 03/14/2014 16:14:29
RMAN-06062: can not backup SPFILE because the instance was not started with SPFILE
7对备份集进行备份
备份所有备份集
Rman>backup backupset all;
指定备份备份集
Rman>backup backupset n1,n2..;也可以添加delete input参数
4 rman命令
1 显示rman默认配置—show
RMAN> show all;
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.2.0/db_1/dbs/snapcf_grs.f'; # default
配置项后面加了#default,表示该配置项没有修改过,
Rman>show configure archivlelog deletion policy to none;
2 列出备份信息—list
LIST BACKUP OF DATABASE BY BACKUP
LIST BACKUP BY FILE
LIST BACKUP SUMMARY
LIST EXPIRED COPY
LIST BACKUP RECOVERABLE
LIST FAILURE;
ADVISE FAILURE;
REPAIR FAILURE;
RMAN> list backup;
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
1 176.85M DISK 00:02:21 10-NOV-14
BP Key: 1 Status: AVAILABLE Compressed: YES Tag: TAG20141110T165750
Piece Name: /home/oracle/oracle_rman/rman_backup_01pn9a8g_1_1
List of Archived Logs in backup set 1
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 3 480534 29-OCT-14 521206 30-OCT-14
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2 Full 135.77M DISK 00:04:17 10-NOV-14
BP Key: 2 Status: AVAILABLE Compressed: YES Tag: TAG20141110T170021
Piece Name: /home/oracle/oracle_rman/rman_backup_02pn9ad5_1_1
List of Datafiles in backup set 2
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 16926112 10-NOV-14 /u01/app/oracle/grs/system01.dbf
2 Full 16926112 10-NOV-14 /u01/app/oracle/grs/undotbs01.dbf
3 Full 16926112 10-NOV-14 /u01/app/oracle/grs/sysaux01.dbf
4 Full 16926112 10-NOV-14 /u01/app/oracle/grs/users01.dbf
5 Full 16926112 10-NOV-14 /u01/app/oracle/grs/example01.dbf
6 Full 16926112 10-NOV-14 /u01/app/oracle/grs/grsv501.dbf
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
3 1.11M DISK 00:00:01 10-NOV-14
BP Key: 3 Status: AVAILABLE Compressed: YES Tag: TAG20141110T170448
Piece Name: /home/oracle/oracle_rman/rman_backup_03pn9alg_1_1
List of Archived Logs in backup set 3
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 17 16926056 10-NOV-14 16926311 10-NOV-14
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
4 Full 6.80M DISK 00:00:01 10-NOV-14
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20141110T170450
Piece Name: /home/oracle/oracle_rman/rman_backup_c-360277547-20141110-00
Control File Included: Ckp SCN: 16926317 Ckp time: 10-NOV-14
SPFILE Included: Modification time: 07-NOV-14
List命令查看rman生成的备份集,备份镜像,归档文件等
List backup ;所有备份信息
List backup of controlfile;—所有控制文件的备份信息
List backup of datafile ‘f:mydbackup......dbf’;
List backup of datafile 5;
List backup of archivelog all;---所有备份的归档文件的信息
List copy of tablespace ‘system’;----列出指定表空间的信息
List device type disk backup;列出某个设备上的所有信息
List archivelog all;列出db当前所有归档
List expired backup;列出无效备份(---无效备份怎么定义的??)
List backup summary
RMAN> list copy of database archivelog all
RMAN> list expired backup;
3 删除备份—delete
用于删除rman备份记录以及相关物理文件(有时候并不是删除,而是打上标记),当使用rman执行备份操作时,会在rman资料库中生成rman备份记录,默认情况下rman备份记录会被存放在目标数据库的控制文件中,如果配置了恢复目录(recovery catalog),那么该备份集也会存放到该恢复目录中
Delete obsolete;删除过期备份----rman会根据冗余策略确定备份是否过期
RMAN> delete obsolete;
Delete obsolete命令
Note:1 如果被判断为废弃的备份是一个单独数据文件的镜像复制,在delete时直接删除
2 如果是备份集中的一部分,则必须等整个备份集都废弃了,才能删除
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set 1 24-OCT-13
Delete expired backup;删除无效备份,用此命令删除无效的备份,
首先执行crosscheck命令核对备份集,如果发现无效(比如备份对应的数据文件损坏或丢失),rman会将该备份集标记为expired状态,
RMAN> delete expired backup;
using channel ORA_DISK_1
Delete expired copy;删除expiry副本
Delete backupset 9,1,2;删除指定备份集
RMAN> delete backupset 43,47,48,49;
using channel ORA_DISK_1
List of Backup Pieces
BP Key BS Key Pc# Cp# Status Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
43 43 1 1 UNAVAILABLE DISK /u01/oracle/backup/full_1koo4kd1_1_1
47 47 1 1 UNAVAILABLE DISK /u01/oracle/backup/rman1104_backup_c-325518186-20140312-00
48 48 1 1 UNAVAILABLE DISK /u01/oracle/backup/backup_spfile
49 49 1 1 UNAVAILABLE DISK /u01/oracle/backup/rman1104_backup_c-325518186-20140314-00
Do you really want to delete the above objects (enter YES or NO)? yes
Delete backuppiece ‘f:mydackup....bak’;删除特定备份片
Delete backup;删除所有备份集—----状态为expired的备份删不掉,
Delete datafile copy ‘f……….bak’;删除特定映像副本
Delete copy ;删除所有映像副本
Backup archivelog all delete input ;在备份后删除输入对象
RMAN> backup archivelog all delete input;
Starting backup at 24-OCT-13
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=20 recid=1 stamp=829666475
input archive log thread=1 sequence=21 recid=2 stamp=829669679
channel ORA_DISK_1: starting piece 1 at 24-OCT-13
channel ORA_DISK_1: finished piece 1 at 24-OCT-13
piece handle=/u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_annnn_TAG20131024T154800_96kn5k4j_.bkp tag=TAG20131024T154800 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/u01/app/oracle/flash_recovery_area/GRS/archivelog/2013_10_24/o1_mf_1_20_96kk1b3h_.arc recid=1 stamp=829666475
archive log filename=/u01/app/oracle/flash_recovery_area/GRS/archivelog/2013_10_24/o1_mf_1_21_96kn5hv3_.arc recid=2 stamp=829669679
Finished backup at 24-OCT-13
Delete backupset 22 format =”f:mydbackupackup_%bk” delete input;
4 报表显示命令—report
REPORT NEED BACKUP DATABASE
REPORT OBSOLETE
REPORT SCHEMA
REPORT UNRECOVERABLE
Report主要用于当前备份信息的分析,如哪些备份已过期,哪些该备份,哪些备份不可用,哪些备份可删除等,
查看7天前的数据库的模式
Rman>report schema at time ‘sysdate-7’;--此时模式信息必须连接到catalog数据库(目录)
查看所需要备份的文件
RMAN> report need backup;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of files with less than 1 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------
查看指定表空间是否需要备份
Report need backup tablespace yyhhqq;
查看过期备份
RMAN> report obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 7 days
Report of obsolete backups and copies
Type Key Completion Time Filen
RMAN> delete obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
5 执行检查—crosscheck命令
Crosscheck用来检查备份或归档物理文件的状态,如果物理文件存储并且在控制文件(或回复目录)有配匹记录,则标记该对象的状态为available(有效),如果文件不存在,则标记为expired,
检查所有归档文件
Rman>crosscheck archivelog all;
当操作系统环境变量nls_lang指定为中文,执行crosscheck检查失败,而又确定文件存在,显示失败说明成功,设置为american_america,英文环境检查正常
检查所有备份集
RMAN> crosscheck backup;
using channel ORA_DISK_1
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/oracle/backup/back_05on6v94_1_1 recid=3 stamp=829652260
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/oracle/backup/backup_datafile_09on7bsd_1_1 recid=6 stamp=829665165
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_annnn_TAG20131024T145435_96kk1gpx_.bkp recid=8 stamp=829666478
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/u01/oracle/backup/backup_spfile recid=12 stamp=829666720
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/flash_recovery_area/GRS/backupset/2013_10_24/o1_mf_annnn_TAG20131024T154800_96kn5k4j_.bkp recid=14 stamp=829669681
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/app/oracle/flash_recovery_area/GRS/autobackup/2013_10_24/o1_mf_s_829669684_96kn5nok_.bkp recid=15 stamp=829669684
Crosschecked 6 objects
RMAN> delete expired backup;
using channel ORA_DISK_1
List of Backup Pieces
BP Key BS Key Pc# Cp# Status Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
12 12 1 1 EXPIRED DISK /u01/oracle/backup/backup_spfile
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/u01/oracle/backup/backup_spfile recid=12 stamp=829666720
Deleted 1 EXPIRED objects
6 修改状态—change命令
Change命令用来修改备份文件或归档文件的状态,不是指物理文件,而是这些文件在控制文件(或恢复目录)中对应记录的状态,available,unavailable,
修改指定备份集状态为unavailable
Rman>change backupset n unavailable;n为指定备份集的备份集序号,指定的备份集必须存在,
RMAN> change backupset 47,48,46,43 unavailable;
changed backup piece unavailable
backup piece handle=/u01/oracle/backup/full_1koo4kd1_1_1 recid=43 stamp=830624161
changed backup piece unavailable
backup piece handle=/u01/oracle/backup/rman1104_backup_c-325518186-20131119-00 recid=46 stamp=831916246
changed backup piece unavailable
backup piece handle=/u01/oracle/backup/rman1104_backup_c-325518186-20140312-00 recid=47 stamp=842007923
changed backup piece unavailable
backup piece handle=/u01/oracle/backup/backup_spfile recid=48 stamp=842200054
Changed 4 objects to UNAVAILABLE status
修改指定指定的表空间的备份集为unavailable;
Rman>change backup of tablespace users unavailable;
修改指定归档文件状态为unavailable
Rman>change archivelog logseq=n unavailable;
Change 命令附带了delete字句,
删除某个归档文件
Rman>change archivelog logseq=n delete;