RMAN可以用来备份和还原数据库文件、归档日志和控制文件。它也可以用来执行完全或不完全的数据库恢复。与传统工具相比,RMAN具有独特的优势:跳过未使用的数据块。当备份一个RMAN备份集时,RMAN不会备份从未被写入的数据块,而传统的方式无法获知那些是未被使用的数据块。
-
- rman的备份;包括整个数据库或者表空间、数据文件、控制文件、参数文件、归档文件的示例
- rman的增量备份
- rman的备份脚本
- rman的还原和恢复
[oracle@oracle235 ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Wed Aug 8 18:07:35 2018 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORA235 (DBID=2047494122) RMAN>
eg:
RMAN> backup database format '/data/backup/db_full_%U'; Starting backup at 08-AUG-18 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00005 name=/data/oracle/data/lottu01.dbf input datafile file number=00001 name=/u01/app/oradata/ora235/system01.dbf input datafile file number=00002 name=/u01/app/oradata/ora235/sysaux01.dbf input datafile file number=00003 name=/u01/app/oradata/ora235/undotbs01.dbf input datafile file number=00004 name=/u01/app/oradata/ora235/users01.dbf channel ORA_DISK_1: starting piece 1 at 08-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/data/backup/db_full_03ta2cqc_1_1 tag=TAG20180808T180916 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45 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-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/data/backup/db_full_04ta2crp_1_1 tag=TAG20180808T180916 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-AUG-18
2.2 备份表空间
eg: backup tablespace lottu format '/data/backup/tsp_lottu_%U';
RMAN> backup tablespace lottu format '/data/backup/tsp_lottu_%U'; Starting backup at 08-AUG-18 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00005 name=/data/oracle/data/lottu01.dbf channel ORA_DISK_1: starting piece 1 at 08-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/data/backup/tsp_lottu_05ta2e01_1_1 tag=TAG20180808T182921 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-AUG-18
eg:
RMAN> backup datafile 5 format '/data/backup/df_5_%U'; Starting backup at 08-AUG-18 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00005 name=/data/oracle/data/lottu01.dbf channel ORA_DISK_1: starting piece 1 at 08-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/data/backup/df_5_06ta2e6k_1_1 tag=TAG20180808T183252 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-AUG-18
SQL> select file_id,file_name from dba_data_files; FILE_ID FILE_NAME ---------- ---------------------------------------- 1 /u01/app/oradata/ora235/system01.dbf 2 /u01/app/oradata/ora235/sysaux01.dbf 3 /u01/app/oradata/ora235/undotbs01.dbf 4 /u01/app/oradata/ora235/users01.dbf 5 /data/oracle/data/lottu01.dbf
RMAN> backup datafile '/data/oracle/data/lottu01.dbf' format '/data/backup/dfname_5_%U'; Starting backup at 08-AUG-18 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00005 name=/data/oracle/data/lottu01.dbf channel ORA_DISK_1: starting piece 1 at 08-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/data/backup/dfname_5_07ta2ei5_1_1 tag=TAG20180808T183901 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-AUG-18
including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 08-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/data/backup/db_full_04ta2crp_1_1 tag=TAG20180808T180916 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-AUG-18
在查看控制文件的备份集;我们可以看到:说明对控制文件已经有备份了。
RMAN> list backup of controlfile; List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 2 Full 9.36M DISK 00:00:01 08-AUG-18 BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20180808T180916 Piece Name: /data/backup/db_full_04ta2crp_1_1 Control File Included: Ckp SCN: 915985 Ckp time: 08-AUG-18
eg:
RMAN> backup current controlfile format '/data/backup/ct_%U'; Starting backup at 08-AUG-18 using channel ORA_DISK_1 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 channel ORA_DISK_1: starting piece 1 at 08-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/data/backup/ct_08ta2f97_1_1 tag=TAG20180808T185119 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-AUG-18
- eg:
- eg:
RMAN> backup current controlfile format '/data/backup/ct_%U' plus archivelog; Starting backup at 08-AUG-18 current log archived using channel ORA_DISK_1 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=56 RECID=1 STAMP=983577870 input archived log thread=1 sequence=57 RECID=2 STAMP=983579059 channel ORA_DISK_1: starting piece 1 at 08-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/u01/app/oracle/dbs/09ta2grj_1_1 tag=TAG20180808T191811 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 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=1 RECID=3 STAMP=983641357 input archived log thread=1 sequence=2 RECID=4 STAMP=983647091 channel ORA_DISK_1: starting piece 1 at 08-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/u01/app/oracle/dbs/0ata2grk_1_1 tag=TAG20180808T191811 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-AUG-18 Starting backup at 08-AUG-18 using channel ORA_DISK_1 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 channel ORA_DISK_1: starting piece 1 at 08-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/data/backup/ct_0bta2grl_1_1 tag=TAG20180808T191813 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-AUG-18 Starting backup at 08-AUG-18 current log archived using channel ORA_DISK_1 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=3 RECID=5 STAMP=983647095 channel ORA_DISK_1: starting piece 1 at 08-AUG-18 channel ORA_DISK_1: finished piece 1 at 08-AUG-18 piece handle=/u01/app/oracle/dbs/0cta2grn_1_1 tag=TAG20180808T191815 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 08-AUG-18