rman
是热备份,必须是归档模式
nocatalog
catalog
rman
备份的时候是启动oracle
后台进程读用过的数据块
rman target /
RMAN> backup database; #备份数据库默认是放在了恢复闪回区里
Starting backup at 06-JAN-20
allocated channel: ORA_DISK_1 #分配通道
channel ORA_DISK_1 #通道名字: SID=38 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=/u01/app/oradata/prod/system01.dbf
input datafile file number=00002 name=/u01/app/oradata/prod/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oradata/prod/example01.dbf
input datafile file number=00003 name=/u01/app/oradata/prod/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oradata/prod/users01.dbf
channel ORA_DISK_1: starting piece 1 at 06-JAN-20 #开始时间
channel ORA_DISK_1: finished piece 1 at 06-JAN-20 #完成时间
piece handle
channel ORA_DISK_1: backup set complete #备份集完成了, elapsed time: 00:00:07 #花费时间是7秒
channel ORA_DISK_1: starting full datafile backup set #开始控制文件完全备份
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set #在这个备份集里包含了当前的控制文件和SPFILE
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 06-JAN-20
channel ORA_DISK_1: finished piece 1 at 06-JAN-20
piece handle=/u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_ncsnf_TAG20200106T160455_h15tkhsz_.bkp tag=TAG20200106T160455 comment=NONE
#这个备份片放到哪里去了=/u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_nnndf_TAG20200106T160455_h15tk7oo_.bkp tag#标记=TAG20200106T160455 comment#注释=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 06-JAN-20
tag=TAG20200106T160455
tag是标签,是一个时间2020年1月6号T是时间16:04:55
tag一样说明这两个备份集是同时生成的,是一条命令里生成的,一条命令可能会生成很多备份集,判断这些备份集是不是一批的就是通过TAG来判断的
backupset:备份集,逻辑概念相当于表空间
backup piece:备份片,物理概念相当于数据文件描述备份片的信息就是备份集
RMAN> list backup; ##查看备份情况
using target database control file instead of recovery catalog ##使用目标数据库的控制文件而不是恢复目录
List of Backup Sets ##备份集列表
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1 Full 1.08G DISK 00:00:06 2020-01-06 16:05:01
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20200106T160455
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_nnndf_TAG20200106T160455_h15tk7oo_.bkp
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
1 Full 1003865 2020-01-06 16:04:55 /u01/app/oradata/prod/system01.dbf
2 Full 1003865 2020-01-06 16:04:55 /u01/app/oradata/prod/sysaux01.dbf
3 Full 1003865 2020-01-06 16:04:55 /u01/app/oradata/prod/undotbs01.dbf
4 Full 1003865 2020-01-06 16:04:55 /u01/app/oradata/prod/users01.dbf
5 Full 1003865 2020-01-06 16:04:55 /u01/app/oradata/prod/example01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
2 Full 9.36M DISK 00:00:01 2020-01-06 16:05:03
BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20200106T160455
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_ncsnf_TAG20200106T160455_h15tkhsz_.bkp
SPFILE Included: Modification time: 2020-01-06 15:48:17
SPFILE db_unique_name: PROD
Control File Included: Ckp SCN: 1003867 Ckp time: 2020-01-06 16:05:00
BS Key:备份集的关键字
Type:这里是完全备份,相对于增量备份
LV:增量备份的级别
Device:备份到的设备这里是磁盘,还有就是磁带
Elapsed Time:用时
BP Key:备份片
Status:状态
Compressed:是否压缩
Tag:标签
Piece Name:备份片的名字及位置
Ckp SCN:这个SCN就是v$datafile_header这个视图里的SCN也就是恢复的起点
压缩备份集
RMAN> backup as compressed backupset full database;
[oracle@oracle01 /u01/app/fast_recovery_area/PROD/backupset/2020_01_06]$ ll -h
total 1.4G
-rw-r----- 1 oracle oinstall 9.4M Jan 6 16:05 o1_mf_ncsnf_TAG20200106T160455_h15tkhsz_.bkp
-rw-r----- 1 oracle oinstall 1.1M Jan 6 17:14 o1_mf_ncsnf_TAG20200106T171344_h15ymdvr_.bkp
-rw-r----- 1 oracle oinstall 1.1G Jan 6 16:05 o1_mf_nnndf_TAG20200106T160455_h15tk7oo_.bkp
-rw-r----- 1 oracle oinstall 289M Jan 6 17:14 o1_mf_nnndf_TAG20200106T171344_h15yl8r8_.bkp
大约差了10倍
支持备份database(datafile,ctrl,spfile)
能单独备表空间,多个表空间就用,隔开
RMAN> backup tablespace sysaux,undotbs1;
还可以单独备份数据文件
RMAN> backup datafile 2;
还能备份控制文件,一定要加上current,因为控制文件是有类型的
RMAN> backup current controlfile;
SYS@orcl>select controlfile_type from v$database;
CONTROL
-------
CURRENT
还可以备份SPFILE
RMAN> backup spfile;
还有就是备份归档日志
RMAN> backup archivelog all;
恢复
RMAN> shutdown immediate;
[oracle@oracle01 /u01/app/oradata/prod]$ mkdir temp
[oracle@oracle01 /u01/app/oradata/prod]$ mv example01.dbf sysaux01.dbf system01.dbf undotbs01.dbf users01.dbf temp
[oracle@oracle01 /u01/app/oradata/prod]$ ll
total 181628
drwxr-xr-x 2 oracle oinstall 4096 Jan 6 15:08 backup
-rw-r----- 1 oracle oinstall 9748480 Jan 6 17:38 control01.ctl
drwxr-xr-x 2 oracle oinstall 4096 Jan 6 15:19 online
-rw-r----- 1 oracle oinstall 52429312 Jan 6 17:32 redo01.log
-rw-r----- 1 oracle oinstall 52429312 Jan 6 17:38 redo02.log
-rw-r----- 1 oracle oinstall 52429312 Jan 6 15:47 redo03.log
drwxr-xr-x 2 oracle oinstall 4096 Jan 6 17:40 temp
-rw-r----- 1 oracle oinstall 30416896 Jan 6 14:49 temp01.dbf
在rman
里恢复分两个阶段
restore
(还原):就是把数据文件还原回来,就是相当于把文件拷贝回来
recover
(恢复):追归档
RMAN> restore database;
上面做了很多的备份,oracle
怎么知道用哪个备份恢复。这个就是列出了关于数据文件的备份,不包含控制文件、日志文件、SPFILE
RMAN> list backup of database;
数据文件也是有很多的备份,如果还原的时候不指定使用哪个备份集,oracle
默认使用最新的备份来进行还原
RMAN> list backup of database;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1 Full 1.08G DISK 00:00:06 2020-01-06 16:05:01
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20200106T160455
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_nnndf_TAG20200106T160455_h15tk7oo_.bkp
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
1 Full 1003865 2020-01-06 16:04:55 /u01/app/oradata/prod/system01.dbf
2 Full 1003865 2020-01-06 16:04:55 /u01/app/oradata/prod/sysaux01.dbf
3 Full 1003865 2020-01-06 16:04:55 /u01/app/oradata/prod/undotbs01.dbf
4 Full 1003865 2020-01-06 16:04:55 /u01/app/oradata/prod/users01.dbf
5 Full 1003865 2020-01-06 16:04:55 /u01/app/oradata/prod/example01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
3 Full 288.41M DISK 00:00:28 2020-01-06 17:14:12
BP Key: 3 Status: AVAILABLE Compressed: YES Tag: TAG20200106T171344
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_nnndf_TAG20200106T171344_h15yl8r8_.bkp
List of Datafiles in backup set 3
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
1 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/system01.dbf
2 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/sysaux01.dbf
3 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/undotbs01.dbf
4 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/users01.dbf
5 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/example01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
5 Full 381.23M DISK 00:00:02 2020-01-06 17:21:29
BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20200106T172127
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_nnndf_TAG20200106T172127_h15z0qr0_.bkp
List of Datafiles in backup set 5
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
2 Full 1006800 2020-01-06 17:21:27 /u01/app/oradata/prod/sysaux01.dbf
3 Full 1006800 2020-01-06 17:21:27 /u01/app/oradata/prod/undotbs01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6 Full 378.91M DISK 00:00:02 2020-01-06 17:25:59
BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20200106T172557
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_nnndf_TAG20200106T172557_h15z95jn_.bkp
List of Datafiles in backup set 6
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
2 Full 1006957 2020-01-06 17:25:57 /u01/app/oradata/prod/sysaux01.dbf
上面也就是说2
号文件会使用6
号备份集3
号文件会使用5号备份集,1,4,5
号文件会用到3
号备份集,1
号备份集不会用到
下面验证,oracle
在恢复之前可以预览会使用哪些文件
RMAN> restore preview database;
Starting restore at 2020-01-06 17:53:19
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
3 Full 288.41M DISK 00:00:28 2020-01-06 17:14:12
BP Key: 3 Status: AVAILABLE Compressed: YES Tag: TAG20200106T171344
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_nnndf_TAG20200106T171344_h15yl8r8_.bkp
List of Datafiles in backup set 3
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
1 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/system01.dbf
4 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/users01.dbf
5 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/example01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6 Full 378.91M DISK 00:00:02 2020-01-06 17:25:59
BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20200106T172557
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_nnndf_TAG20200106T172557_h15z95jn_.bkp
List of Datafiles in backup set 6
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
2 Full 1006957 2020-01-06 17:25:57 /u01/app/oradata/prod/sysaux01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
5 Full 381.23M DISK 00:00:02 2020-01-06 17:21:27
BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20200106T172127
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_nnndf_TAG20200106T172127_h15z0qr0_.bkp
List of Datafiles in backup set 5
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
3 Full 1006800 2020-01-06 17:21:27 /u01/app/oradata/prod/undotbs01.dbf
using channel ORA_DISK_1
#下面说恢复的时候还会用到序列号为1的归档日志
List of Archived Log Copies for database with db_unique_name PROD
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - -------------------
24 1 1 A 2020-01-06 15:47:42
Name: /u01/app/fast_recovery_area/PROD/archivelog/2020_01_06/o1_mf_1_1_h15zo1kp_.arc
Media recovery start SCN is 1006605
Recovery must be done beyond SCN 1006957 to clear datafile fuzziness
Finished restore at 2020-01-06 17:53:20
RMAN> restore database;
[oracle@oracle01 /u01/app/oradata/prod]$ ll
total 1900080
drwxr-xr-x 2 oracle oinstall 4096 Jan 6 15:08 backup
-rw-r----- 1 oracle oinstall 9748480 Jan 6 17:58 control01.ctl
-rw-r----- 1 oracle oinstall 328343552 Jan 6 17:57 example01.dbf
drwxr-xr-x 2 oracle oinstall 4096 Jan 6 15:19 online
-rw-r----- 1 oracle oinstall 52429312 Jan 6 17:32 redo01.log
-rw-r----- 1 oracle oinstall 52429312 Jan 6 17:38 redo02.log
-rw-r----- 1 oracle oinstall 52429312 Jan 6 15:47 redo03.log
-rw-r----- 1 oracle oinstall 545267712 Jan 6 17:58 sysaux01.dbf
-rw-r----- 1 oracle oinstall 786440192 Jan 6 17:58 system01.dbf
drwxr-xr-x 2 oracle oinstall 4096 Jan 6 17:40 temp
-rw-r----- 1 oracle oinstall 30416896 Jan 6 14:49 temp01.dbf
-rw-r----- 1 oracle oinstall 94380032 Jan 6 17:58 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 Jan 6 17:57 users01.dbf
restore
(还原)就是相当于把数据文件解压出来,restore
之后就可以脱离rman
了
SYS@orcl>select file#,checkpoint_change# from v$datafile;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 1007348
2 1007348
3 1007348
4 1007348
5 1007348
SYS@orcl>select file#,checkpoint_change# from v$datafile_header;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 1006605
2 1006957
3 1006800
4 1006605
5 1006605
#这里恢复的起点v$datafile_header里的SCN就是备份的时候Ckp SCN
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
3 Full 288.41M DISK 00:00:28 2020-01-06 17:14:12
BP Key: 3 Status: AVAILABLE Compressed: YES Tag: TAG20200106T171344
Piece Name: /u01/app/fast_recovery_area/PROD/backupset/2020_01_06/o1_mf_nnndf_TAG20200106T171344_h15yl8r8_.bkp
List of Datafiles in backup set 3
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
1 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/system01.dbf
4 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/users01.dbf
5 Full 1006605 2020-01-06 17:13:44 /u01/app/oradata/prod/example01.dbf
RMAN> recover database;
Starting recover at 2020-01-06 18:09:15
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2020-01-06 18:09:16
这里就不会提示一个一个输回车或者auto
,自动找
SYS@orcl>select file#,checkpoint_change# from v$datafile_header;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 1007346
2 1007346
3 1007346
4 1007346
5 1007346
SYS@orcl>select file#,checkpoint_change# from v$datafile;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 1007348
2 1007348
3 1007348
4 1007348
5 1007348
这样就可以打开了