rman
备份默认是放在恢复闪回区里
[oracle@oracle01 /u01/app/oradata/prod]$ ll
total 1900080
drwxr-xr-x 2 oracle oinstall 4096 Jan 7 09:47 backup
把备份放到backup
里,%d
取数据库的名字,%T
取当前日期,%U
序列号防止同一目录下文件名重复
RMAN> backup as compressed backupset full database format '/u01/app/oradata/prod/backup/%d_%T_%U.BAK';
[oracle@oracle01 /u01/app/oradata/prod]$ ls backup/
PROD_20200107_0culccsb_1_1.BAK PROD_20200107_0dulccte_1_1.BAK
oracle
在恢复的时候总是选择最新的备份,因为最新的备份应用归档日志最少
在恢复的时候让oracle
不自动选择备份集,自己指定恢复的时候用哪个备份集
RMAN> shutdown immediate;
RMAN> startup mount;
RMAN> restore database from tag TAG20200106T160455;
SYS@orcl>select file#,checkpoint_change# from v$datafile;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 1009471
2 1009471
3 1009471
4 1009471
5 1009471
SYS@orcl>select file#,checkpoint_change# from v$datafile_header;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 1003865
2 1003865
3 1003865
4 1003865
5 1003865
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 06-JAN-20
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 06-JAN-20 /u01/app/oradata/prod/system01.dbf
2 Full 1003865 06-JAN-20 /u01/app/oradata/prod/sysaux01.dbf
3 Full 1003865 06-JAN-20 /u01/app/oradata/prod/undotbs01.dbf
4 Full 1003865 06-JAN-20 /u01/app/oradata/prod/users01.dbf
5 Full 1003865 06-JAN-20 /u01/app/oradata/prod/example01.dbf
数据文件头的SCN
和备份集1
的SCN
相等,说明恢复的时候用的是1
号备份集
SYS@orcl>recover database;
Media recovery complete.
RMAN> alter database open;
有catalog
的情况============
target DB:10.16.35.141
catalog DB:10.16.35.142
catalog
上操作(连接catalog
数据库不能以sysdba
或者sysoper
用户登陆)
SYS@orcl>create user rman identified by rman;
SYS@orcl>grant connect,resource,recovery_catalog_owner to rman;
看一下recovery_catalog_owner
这个角色有哪些权限
SYS@orcl>select * from dba_sys_privs where grantee=upper('recovery_catalog_owner');
GRANTEE PRIVILEGE ADM
------------------------------ ---------------------------------------- ---
RECOVERY_CATALOG_OWNER CREATE SYNONYM NO
RECOVERY_CATALOG_OWNER CREATE CLUSTER NO
RECOVERY_CATALOG_OWNER ALTER SESSION NO
RECOVERY_CATALOG_OWNER CREATE DATABASE LINK NO
RECOVERY_CATALOG_OWNER CREATE PROCEDURE NO
RECOVERY_CATALOG_OWNER CREATE SEQUENCE NO
RECOVERY_CATALOG_OWNER CREATE TABLE NO
RECOVERY_CATALOG_OWNER CREATE SESSION NO
RECOVERY_CATALOG_OWNER CREATE TYPE NO
RECOVERY_CATALOG_OWNER CREATE VIEW NO
RECOVERY_CATALOG_OWNER CREATE TRIGGER NO
target DB
[oracle@oracle01 ~]$ vim /u01/app/oracle/network/admin/tnsnames.ora
catalog =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.16.35.142)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = prod)
)
)
[oracle@oracle01 ~]$ rman
RMAN> connect target
RMAN> connect catalog rman/rman@catalog;
或者
[oracle@oracle01 ~]$ rman target / catalog rman/rman@catalog
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Jan 7 11:48:45 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=439100281)
connected to recovery catalog database
创建一些对象用来保存备份的信息,这里指定了表空间,要是不指定就是rman
用户的缺省表空间
RMAN> create catalog tablespace users;
现在target DB
和catalog DB
还没有关联上,catalog
用户rman
下面有一张表db
catalog
上查询
RMAN@orcl>select * from db;
no rows selected #现在还没有target DB的信息
下面的命令就是把target DB
的控制文件当中的信息读到catalog
中
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
catalog DB
上执行
RMAN@orcl>select * from db;
DB_KEY DB_ID CURR_DBINC_KEY
---------- ---------- --------------
1 439100281 2
target DB
上执行
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
111 Full 1.08G DISK 00:00:06 06-JAN-20
BP Key: 124 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 111
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1003865 06-JAN-20 /u01/app/oradata/prod/system01.dbf
2 Full 1003865 06-JAN-20 /u01/app/oradata/prod/sysaux01.dbf
3 Full 1003865 06-JAN-20 /u01/app/oradata/prod/undotbs01.dbf
4 Full 1003865 06-JAN-20 /u01/app/oradata/prod/users01.dbf
5 Full 1003865 06-JAN-20 /u01/app/oradata/prod/example01.dbf
上面这些信息都是catalog
中的信息,验证一下
启动到nomount
状态,控制文件还没用到,能看到备份的信息这些信息就是从catalog
中看到的
RMAN> shutdown immediate;
RMAN> startup nomount;
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
111 Full 1.08G DISK 00:00:06 06-JAN-20
BP Key: 124 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 111
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1003865 06-JAN-20 /u01/app/oradata/prod/system01.dbf
2 Full 1003865 06-JAN-20 /u01/app/oradata/prod/sysaux01.dbf
3 Full 1003865 06-JAN-20 /u01/app/oradata/prod/undotbs01.dbf
4 Full 1003865 06-JAN-20 /u01/app/oradata/prod/users01.dbf
5 Full 1003865 06-JAN-20 /u01/app/oradata/prod/example01.dbf
.......省略
rman
常用的命令=================
list backup
列出备份的信息,of database/controlfile/archivelog all/spfile/tablespace/
还能加上summary
RMAN> list backup of database summary;
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
111 B F A DISK 06-JAN-20 1 1 NO TAG20200106T160455
113 B F A DISK 06-JAN-20 1 1 YES TAG20200106T171344
115 B F A DISK 06-JAN-20 1 1 NO TAG20200106T172127
116 B F A DISK 06-JAN-20 1 1 NO TAG20200106T172557
122 B F A DISK 07-JAN-20 1 1 YES TAG20200107T095107
但是这样显示有一个小问题,比如116
号备份集只备份了一个数据文件,那么也会出现在这里,也就说不是数据文件完整的备份也是会出现在这里