2014-12-24 Created By BaoXinjian
一、摘要
简言之,将rman的备份恢复命令写成脚本并保存在恢复目录内,恢复目录内的脚本可用性及通用性高于基于文件系统的脚本。
客户端只要能够登录到RMAN恢复目录,则这些脚本可用,尤其对于global脚本,可以被任意注册的数据库调度。
二、脚本的分类
1. local
在rman连接的目标数据库下创建的脚本,此类脚本仅仅适用于当前目标数据库。即是针对特定的数据库创建的rman脚本。
2. global
能够在恢复目录注册的任意目标数据库中执行。
三、创建脚本
1. 创建全局备份脚本
RMAN>create global script global_full_backup
comment 'A script for full backup to be used with any database'
{
backup database
plus archivelog
tag='whole_db_bk';
delete obsolete;
}
created global script global_full_backup
2. 创建本地备份脚本
RMAN> create script full_backup
comment 'A script for full backup to be used with current target database'
{
backup as compressed backupset
database plus archivelog delete input
tag='whole_db_bk';
delete obsolete;
}
created script full_backup
3. 从文本文件创建脚本
[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
四、查看脚本的内容
1. 语法
print [global] script script_name
print [global] script script_name to file '<dir>' --将RMAN存储脚本转换到文件系统可读文件
2. 例子
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';
3. 查看当前恢复目录内的脚本
list [global | all] script names
RMAN> list script names;
五、更新脚本
1. 语法
replace [global] script scrip_name {....}
replace [global] script script_name from file '<dir>' --从文件更新脚本
2. RMAN例子
RMAN> replace global script global_full_backup
{
backup as compressed backupset database plus archivelog
tag='whole_db_bk';
delete obsolete;
}
replaced global script global_full_backup
六、执行脚本
1. 语法:
RUN { EXECUTE [global] SCRIPT script_name; }
2. 从RMAN客户端直接执行恢复目录内的脚本
rman target sys/oracle@odellprod catalog rman/rman@catadb script 'script_name';
RMAN> run { execute global script global_full_backup;}
executing global script: global_full_backup
七、删除脚本
1. 方法:
delete [global] script script_name
2. 如何删除
RMAN> delete script ctl_spfile_bk;
八、其它
注意:使用EXECUTE SCRIPT,DELETE SCRIPT,PRINT SCRIPT等命令时,如果一个本地的脚本未找到,则寻找全局的脚本来代替。
因此应当注意命名规范,尽可能的不使用重名的脚本名,当DELETE SCRIPT 找不到本地脚本,而找到同样名字的全局脚本,则全局脚本被删除
Thanks and Regards