首页 > 代码库 > 基于catalog 创建RMAN存储脚本
基于catalog 创建RMAN存储脚本
--==============================
-- 基于catalog 创建RMAN存储脚本
--==============================
简言之,将rman的备份恢复命令写成脚本并保存在恢复目录内,恢复目录内的脚本可用性及通用性高于基于文件系统的脚本。
客户端只要能够登录到RMAN恢复目录,则这些脚本可用,尤其对于global脚本,可以被任意注册的数据库调度。
一、脚本的分类
local : 在rman连接的目标数据库下创建的脚本,此类脚本仅仅适用于当前目标数据库。即是针对特定的数据库创建的rman脚本
global : 能够在恢复目录注册的任意目标数据库中执行
二、创建脚本
--创建全局备份脚本
RMAN> create global script global_full_backup
2> comment ‘A script for full backup to be used with any database‘
3> {
4> backup database
5> plus archivelog
6> tag=‘Whole_db_bk‘;
7> delete obsolete;
8> }
created global script global_full_backup
--创建本地备份脚本
RMAN> create script full_backup
2> comment ‘A script for full backup to be used with current target database‘
3> {
4> backup as compressed backupset
5> database plus archivelog delete input
6> tag=‘Whole_db_bk‘;
7> delete obsolete;
8> }
created script full_backup
--从文本文件创建脚本
[oracle@oradb bk]$ cat backup_ctl_spfile --注意文本文件必须以"{" 开头,以"}" 结尾
{
allocate channel ch1 device type disk;
backup current controlfile
tag=‘ctl_spfile‘
format ‘/u01/oracle/bk/rmbk/ctl_spfile_%d_%U‘;
release channel ch1;
}
RMAN> create script ctl_spfile_bk from file ‘/u01/oracle/bk/rmbk/backup_ctl_spfile‘;
script commands will be loaded from file /u01/oracle/bk/rmbk/backup_ctl_spfile
created script ctl_spfile_bk
三、查看脚本的内容
print [global] script script_name
print [global] script script_name to file ‘<dir>‘ --将RMAN存储脚本转换到文件系统可读文件
RMAN> print script ctl_spfile_bk;
printing stored script: ctl_spfile_bk
{
allocate channel ch1 device type disk;
backup current controlfile
tag=‘ctl_spfile‘
format ‘/u01/oracle/bk/rmbk/ctl_spfile_%d_%U‘;
release channel ch1;
}
RMAN> print script ctl_spfile_bk to file ‘/u01/oracle/bk/rmbk/backup_ctl_spfile2‘;
script ctl_spfile_bk written to file /u01/oracle/bk/rmbk/backup_ctl_spfile2
查看当前恢复目录内的脚本
list [global | all] script names
RMAN> list script names;
List of Stored Scripts in Recovery Catalog
Scripts of Target Database ORCL
Script Name
Description
-----------------------------------------------------------------------
ctl_spfile_bk
full_backup
A script for full backup to be used with current target database
Global Scripts
Script Name
Description
-----------------------------------------------------------------------
global_full_backup
A script for full backup to be used with any database
四、更新脚本
replace [global] script scrip_name {....}
replace [global] script script_name from file ‘<dir>‘ --从文件更新脚本
RMAN> replace global script global_full_backup
2> {
3> backup as compressed backupset database plus archivelog
4> tag=‘whole_db_bk‘;
5> delete obsolete;
6> }
replaced global script global_full_backup
五、执行脚本
方法:RUN { EXECUTE [global] SCRIPT script_name; }
从rman客户端直接执行恢复目录内的脚本
rman target sys/redhat@orcl catalog rman/rman@asmdb script ‘script_name‘;
RMAN> run { execute global script global_full_backup;}
executing global script: global_full_backup
六、删除脚本
delete [global] script script_name
RMAN> delete script ctl_spfile_bk;
deleted script: ctl_spfile_bk
七、其它
注意:使用EXECUTE SCRIPT, DELETE SCRIPT ,PRINT SCRIPT等命令时,如果一个本地的脚本未找到,则寻找全局的脚本来代替。
因此应当注意命名规范,尽可能的不使用重名的脚本名,当DELETE SCRIPT 找不到本地脚本,而找到同样名字的全局脚本,则全局
脚本被删除
转:http://blog.csdn.net/leshami/article/details/6073020
基于catalog 创建RMAN存储脚本