这里面的target数据库进行备份和修复的,执行的时候要有SYSDBA的权限,这样才能连接到目标数据库,如果没有连接会失败。
在做RMAN备份的时候,catalog数据库是可选的,即可以使用也可以不使用。什么是catalog数据库?Catalog数据库的作用是存储备份信息的,比如说备份了什么东西,做了什么备份,然后备份的目录是什么,备份的文件名是什么,等等。也就是说在使用RMAN备份的时候,产生的一些信息保存在Recovery catalog database里面。如果缺省的方式即非catalog模式,RMAN信息存放在控制文件里面。(在非catalog模式下面,RMAN产生的备份的信息存放在控制文件里面)。
Auxiliary是辅助数据库,也就是说在使用RMAN在连接生产数据库的时候做RMAN备份,同时又可以连接一个辅助数据库。也就是说可以连接两个数据库。可以将生产数据库拷贝到辅助数据库。
RMAN可以连接上面三种类型的数据库。上面三种数据库可以在一台服务器上面,也可以在多台服务器上面。Oracle是建议catalog不要和生产数据库放在一个server上面。如果server出问题了,catalog数据库有可能出问题,那么做恢复的时候就比较麻烦。
[root@localhost oracle]# find / -name rman
/u01/oracle/product/11.2.0/db_1/sysman/admin/scripts/db/rman
/u01/oracle/product/11.2.0/db_1/bin/rman
/u01/oracle/product/11.2.0/db_1/oc4j/j2ee/oc4j_applications/applications/em/em/WEB-INF/perl/db/rman
修改环境变量
[oracle@localhost ~]$ vi .bash_profile
PATH=$ORACLE_HOME/bin:$PATH(调整它们之间的顺序)。
[oracle@localhost ~]$ echo $PATH
/u01/oracle/product/11.2.0/db_1/bin:/u01/oracle/product/11.2.0/db_1/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/u01/oracle/product/11.2.0/db_1/bin:/u01/oracle/product/11.2.0/db_1/bin
在oracle以后下面敲RMAN会先去$PATH变量里面找,找到/u01/oracle/product/11.2.0/db_1/bin就是我们需要的。
在使用RMAN备份的时候先要去确定数据库是否处于归档模式下面。
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Next log sequence to archive 3
Current log sequence 3
如果没有开启就在数据库mount状态下SQL> alter database archivelog;。
在非nocatalog模式下面直接使用rman命令就可以使用该工具。
[oracle@localhost ~]$ rman
Recovery Manager: Release 11.2.0.4.0 - Production on Fri Dec 8 03:03:34 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
RMAN>
要是不放心,可以使用nocatalog来指定
[oracle@localhost ~]$ rman nocatalog
Recovery Manager: Release 11.2.0.4.0 - Production on Fri Dec 8 03:04:19 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
看看里面也没有备份信息
RMAN> list backupset;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of list command at 12/08/2017 03:05:36
RMAN-06171: not connected to target database
可以看到出错了,因为没有连接到目标数据库。使用nocatalog模式必须先要连接到目标数据库。
RMAN> connect target /
connected to target database: ORADB (DBID=2715094423)
using target database control file instead of recovery catalog
这里有两点,连接到的数据库名字叫oradb,另外一点使用控制文件存储RMAN要备份的信息。
RMAN> list backupset;
specification does not match any backup in the repository
可以看到里面没有任何信息。
全备份
全备份就是对整个数据库进行备份
RMAN> backup database;
Starting backup at 08-DEC-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=40 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/oracle/oradata/system01.dbf
input datafile file number=00002 name=/u01/oracle/oradata/sysaux01.dbf
input datafile file number=00003 name=/u01/oracle/oradata/undotbs01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/users01.dbf
channel ORA_DISK_1: starting piece 1 at 08-DEC-17
channel ORA_DISK_1: finished piece 1 at 08-DEC-17
piece handle=/u01/oracle/fast_recovery_area/ORADB/backupset/2017_12_08/o1_mf_nnndf_TAG20171208T032031_f2nxd0wz_.bkp tag=TAG20171208T032031 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:46
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
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 08-DEC-17
channel ORA_DISK_1: finished piece 1 at 08-DEC-17
piece handle=/u01/oracle/fast_recovery_area/ORADB/backupset/2017_12_08/o1_mf_ncsnf_TAG20171208T032031_f2nxhdkj_.bkp tag=TAG20171208T032031 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 08-DEC-17
............................................................................................
经过一段时间就可以将数据库完全备份下来。
现在再去查看备份信息
RMAN> list backupset;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1 Full 1.02G DISK 00:01:46 08-DEC-17 (1号备份是全备份,备份的尺寸大小是1.02G,备份到硬盘上面,后面是什么时间备份的。)
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20171208T032031
Piece Name: /u01/oracle/fast_recovery_area/ORADB/backupset/2017_12_08/o1_mf_nnndf_TAG20171208T032031_f2nxd0wz_.bkp
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1038388 08-DEC-17 /u01/oracle/oradata/system01.dbf
2 Full 1038388 08-DEC-17 /u01/oracle/oradata/sysaux01.dbf
3 Full 1038388 08-DEC-17 /u01/oracle/oradata/undotbs01.dbf
4 Full 1038388 08-DEC-17 /u01/oracle/oradata/users01.dbf
(1.02个G的大小是上面4个文件加起来的大小)
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2 Full 9.36M DISK 00:00:01 08-DEC-17
BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20171208T032031
Piece Name: /u01/oracle/fast_recovery_area/ORADB/backupset/2017_12_08/o1_mf_ncsnf_TAG20171208T032031_f2nxhdkj_.bkp
SPFILE Included: Modification time: 08-DEC-17
SPFILE db_unique_name: ORADB
Control File Included: Ckp SCN: 1038423 Ckp time: 08-DEC-17
[oracle@localhost oradata]$ ls -la /u01/oracle/fast_recovery_area/ORADB/backupset/2017_12_08
total 1075948
drwxr-x--- 2 oracle oinstall 4096 Dec 8 03:22 .
drwxr-x--- 3 oracle oinstall 4096 Dec 8 03:20 ..
-rw-r----- 1 oracle oinstall 9830400 Dec 8 03:22 o1_mf_ncsnf_TAG20171208T032031_f2nxhdkj_.bkp
-rw-r----- 1 oracle oinstall 1091928064 Dec 8 03:22 o1_mf_nnndf_TAG20171208T032031_f2nxd0wz_.bkp
可以看到在/u01/oracle/fast_recovery_area/ORADB/backupset/2017_12_08下面产生了两个文件。