--=================================
-- 基于catalog 的RMAN 备份与恢复
--=================================
RMAN的备份与恢复存储仓库的数据通常存放于控制文件或恢复目录中,本文主要讲述基于catalog的备份与恢复。
关于catalog的创建请参考:RMAN catalog的创建和使用
catalog方式的RMAN备份与恢复只不过是将备份恢复信息数据放在catalog目录内,普通的rman方式则是存放在控制文件中
catalog方式可以存储常用或特定的备份与恢复的脚本
有关catalog方式RMAN存储脚本请参考:基于 catalog 创建RMAN存储脚本
一、基于catalog来备份数据库(目标数据库orcl,恢复目录数据库asmdb)
首先基于catalog创建备份脚本
--连接到RMAN
[Oracle@oradb ~]$ rman target sys/RedHat@orcl catalog rman/rman@asmdb
connected to target database: ORCL (DBID=1263182651)
connected to recovery catalog database
--创建全局删除废弃备份的脚本
RMAN> create global script global_del_obsocomment 'A script for obsolete backup and delete it' {
2> allocate channel ch1 device type disk;
3> delete obsolete recovery window of 7 days;
4> release channel ch1;
5> }
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
created global script global_del_obso
--创建全局归档日志的备份脚本
RMAN> create global script global_arch
2> comment ' A script for archivelog and delete it '
3> {
4>allocate channel ch1 device type disk;
5>sql " alter system archive log current";
6>set limit channel ch1 readrate=10240;
7>set limit channel ch1 kbytes=2048000;
8>backup as compressed backupset archivelog all delete input
9>format='/u01/bk/rmbk/arch_%d_%U'
10>tag='Archbk';
11>release channel ch1;
12> }
created global script global_arch
--创建全局0级增量备份脚本
RMAN> create global script global_inc0
2> comment ' A script for backup database using incremental level 0'
3> {
4>execute global script global_del_obso;
5>allocate channel ch1 device type disk;
6>set limit channel ch1 readrate=10240;
7>set limit channel ch1 kbytes=2048000;
8>backup as compressed backupset incremental level 0 database
9>format='/u01/bk/rmbk/inc0_%d_%U'
10>tag='Inc0';
11>release channel ch1;
12>execute global script global_arch;
13> }
created global script global_inc0
--列出已经创建的全局脚本
RMAN> list global script names;
List of Stored Scripts in Recovery Catalog
Global Scripts
Script Name
Description
-----------------------------------------------------------------------
global_arch
A script for archivelog and delete it
global_del_obso
A script for obsolete backup and delete it
global_inc0
A script for backup database using incremental level 0
--启用控制文件的自动备份功能
RMAN> configure controlfile autobackup on;
RMAN> configure controlfile autobackup format for device type disk to '/u01/bk/rmbk/auto_ctl_%d_%f';
--删除以前的备份
RMAN> delete noprompt backupset;
--备份前验证归档日志是否存在
RMAN> crosscheck archivelog all;
--删除无效的归档日志信息
RMAN> delete noprompt expired archivelog all;
--使用0级增量备份数据库
RMAN> run { execute global script global_inc0;}
--查看刚刚完成的备份情况
RMAN> list backupset summary;
RMAN> list backupset ;
RMAN> list backup of controlfile ;
RMAN> list backup of archivelog all;
RMAN> list backup of database;
RMAN> list backup of datafile n ;