【ORACLE】手工建库+RMAN Catalog创建、配置和使用

今天因为工作原因,需要部署一个RMAN Catalog库,对另一个数据库进行备份,正好复习下手工建库。
全部过程记录如下:

一、手工创建【CATADB】数据库

1.1创建密码文件orapwCATADB

[oracle@db1 dbs]$ orapwd file=orapwCATADB password=oracle entries=30
[oracle@db1 dbs]$ ll
total 40
-rw-rw----. 1 oracle oinstall 1544 Sep 18 10:44 hc_oradb3.dat
-rw-r--r--. 1 oracle oinstall 2851 May 15  2009 init.ora
-rw-r-----. 1 oracle oinstall   24 Sep 15 14:42 lkORADB3
-rw-r-----. 1 oracle oinstall 5120 Sep 20 10:32 orapwCATADB
-rw-r-----. 1 oracle oinstall 1536 Sep 15 14:45 orapworadb3
-rw-r-----. 1 oracle oinstall 2560 Sep 18 10:45 spfileoradb3.ora

1.2生成初始化参数文件并修改

[oracle@db1 dbs]$ cat init.ora |grep -v ^$ |grep -v ^# >initCATADB.ora
[oracle@db1 dbs]$ cat initCATADB.ora 
db_name='CATADB'
memory_target=1G
processes = 150
audit_file_dest='$ORACLE_BASE/admin/CATADB/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='$ORACLE_BASE/fast_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='$ORACLE_BASE'
dispatchers='(PROTOCOL=TCP) (SERVICE=CATADBXDB)'
open_cursors=300 
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS'
control_files = '/u01/app/oracle/oradata/CATADB/ora_control1.ctl', '/u01/app/oracle/oradata/CATADB/ora_control2.ctl'
compatible ='11.2.0'

1.3 创建相关目录

[oracle@db1 dbs]$ mkdir -p $ORACLE_BASE/admin/CATADB/adump
[oracle@db1 dbs]$ mkdir -p $ORACLE_BASE/fast_recovery_area
[oracle@db1 dbs]$ mkdir -p /u01/app/oracle/oradata/CATADB/

1.4 参照官方文档脚本创建建库SQL脚本

[oracle@db1 dbs]$ cat crdb.sql 
CREATE DATABASE CATADB
   USER SYS IDENTIFIED BY oracle
   USER SYSTEM IDENTIFIED BY oracle
   LOGFILE GROUP 1 ('/u01/app/oracle/oradata/CATADB/redo01a.log','/u01/app/oracle/oradata/CATADB/redo01b.log') SIZE 100M BLOCKSIZE 512,
           GROUP 2 ('/u01/app/oracle/oradata/CATADB/redo02a.log','/u01/app/oracle/oradata/CATADB/redo02b.log') SIZE 100M BLOCKSIZE 512,
           GROUP 3 ('/u01/app/oracle/oradata/CATADB/redo03a.log','/u01/app/oracle/oradata/CATADB/redo03b.log') SIZE 100M BLOCKSIZE 512
   MAXLOGFILES 5
   MAXLOGMEMBERS 5
   MAXLOGHISTORY 1
   MAXDATAFILES 100
   CHARACTER SET AL32UTF8
   NATIONAL CHARACTER SET AL16UTF16
   EXTENT MANAGEMENT LOCAL
   DATAFILE '/u01/app/oracle/oradata/CATADB/system01.dbf' SIZE 325M REUSE
   SYSAUX DATAFILE '/u01/app/oracle/oradata/CATADB/sysaux01.dbf' SIZE 325M REUSE
   DEFAULT TABLESPACE users
      DATAFILE '/u01/app/oracle/oradata/CATADB/users01.dbf'
      SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
   DEFAULT TEMPORARY TABLESPACE temp
      TEMPFILE '/u01/app/oracle/oradata/CATADB/temp01.dbf'
      SIZE 20M REUSE
   UNDO TABLESPACE undotbs
      DATAFILE '/u01/app/oracle/oradata/CATADB/undotbs01.dbf'
      SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

1.5创建spfile并启动实例,开始创建数据库

[oracle@db1 ~]$export ORACLE_SID=CATADB
[oracle@db1 ~]$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Sep 20 10:42:56 2017
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to an idle instance.
SYS@CATADB> create spfile from pfile;
File created.

SYS@CATADB> startup nomount;
ORACLE instance started.
Total System Global Area 1068937216 bytes
Fixed Size          2260088 bytes
Variable Size         671089544 bytes
Database Buffers      390070272 bytes
Redo Buffers            5517312 bytes

SYS@CATADB> @crdb.sql
Database created.

1.6执行手工建库后脚本

[oracle@db1 dbs]$ cat 1.sql

@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql
conn system/oracle
@?/rdbms/admin/utlrp.sql

SYS@CATADB> @1.sql
DOC>######################################################################
DOC>######################################################################
DOC>    The following statement will cause an "ORA-01722: invalid number"
DOC>    error and terminate the SQLPLUS session if the user is not SYS.
DOC>    Disconnect and reconnect with AS SYSDBA.
DOC>######################################################################
DOC>######################################################################
DOC>#
no rows selected
Session altered.
TIMESTAMP
------------------------------------------------------------
COMP_TIMESTAMP CATALG_BGN 2017-09-20 10:50:16 2458017 39016
Package created.
Package body created.
Grant succeeded.
Synonym created.
Grant succeeded.
Table created.
......
......
PL/SQL procedure successfully completed.

1.7 确认建库成功

SYSTEM@CATADB> Rem =========================================================================
SYSTEM@CATADB> Rem END utlrp.sql
SYSTEM@CATADB> Rem ===========================================================================

SYSTEM@CATADB> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0  Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

5 rows selected.

SYSTEM@CATADB> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

1 row selected.

二、创建Catalog恢复目录

2.1 修改tnsnames.ora,添加CATADB

[oracle@db1 admin]$ pwd
/u01/app/oracle/product/11.2.0/db_1/network/admin

[oracle@db1 admin]$ cat tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

ORADB3 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = db1.us.oracle.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = oradb3)
    )
  )

CATADB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = db1.us.oracle.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = CATADB)
    )
  )

2.2 创建Catalog表空间

SYS@CATADB> create tablespace cat_tbs datafile '/u01/app/oracle/oradata/CATADB/cat_tbs01.dbf' size 100m;

Tablespace created.

2.3 创建Catalog管理账户并授权

SYS@CATADB> create user catrman identified by oracle
  2  temporary tablespace temp
  3  default tablespace cat_tbs
  4  quota unlimited on cat_tbs;

User created.

SYS@CATADB> grant recovery_catalog_owner,connect,resource to catrman;

Grant succeeded.

2.4 进入Rman创建Catalog,然后升级

[oracle@db1 admin]$ rman 
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Sep 20 11:11:41 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

RMAN> connect catalog catrman/oracle
connected to recovery catalog database

RMAN> create catalog;
recovery catalog created

RMAN> upgrade catalog;
recovery catalog owner is CATRMAN
enter UPGRADE CATALOG command again to confirm catalog upgrade

RMAN> upgrade catalog;
recovery catalog upgraded to version 11.02.00.04
DBMS_RCVMAN package upgraded to version 11.02.00.04
DBMS_RCVCAT package upgraded to version 11.02.00.04

RMAN>

三、Rman Catalog 使用

3.1 注册目标数据库到Catalog

[oracle@db1 ~]$ rman target / catalog catrman/oracle@CATADB

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Sep 20 11:14:03 2017

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

connected to target database: ORADB3 (DBID=2731358481)
connected to recovery catalog database

RMAN> REGISTER DATABASE;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN> 

3.2 查看当前Rman备份策略

RMAN> SHOW ALL;

RMAN configuration parameters for database with db_unique_name ORADB3 are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
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 COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_oradb3.f'; # default

3.3 开启控制文件自动备份

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN> 

3.4 开启Rman备份优化

RMAN> CONFIGURE BACKUP OPTIMIZATION ON;

new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN> 

3.5 指定备份与恢复操作中的并行(PARALLELISM)度为2,即同时开,2个通道进行备份和恢复,可以加快备份速度

RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;

new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN> 

3.6 查看修改后配置策略

RMAN> SHOW ALL;

RMAN configuration parameters for database with db_unique_name ORADB3 are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION ON;
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 2 BACKUP TYPE TO BACKUPSET;
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 COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_oradb3.f'; # default

RMAN> 

3.7 备份测试

[oracle@db1 ~]$ rman target / catalog catrman/oracle@CATADB

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Sep 20 13:29:46 2017

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

connected to target database: ORADB3 (DBID=2731358481)
connected to recovery catalog database

RMAN> BACKUP DATABASE PLUS ARCHIVELOG;


Starting backup at 20-SEP-17
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=11 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=12 RECID=1 STAMP=955200594
channel ORA_DISK_1: starting piece 1 at 20-SEP-17
channel ORA_DISK_1: finished piece 1 at 20-SEP-17
piece handle=/u01/app/oracle/fast_recovery_area/ORADB3/backupset/2017_09_20/o1_mf_annnn_TAG20170920T132956_dw3z6o5j_.bkp tag=TAG20170920T132956 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 20-SEP-17

Starting backup at 20-SEP-17
using channel ORA_DISK_1
using channel ORA_DISK_2
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/oracle/oradata/oradb3/system01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/oradb3/test01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/oradb3/example01.dbf
......

你可能感兴趣的:(ORACLE,oracle,数据库,rman,备份)