--==============================
-- 基于catalog 创建RMAN存储脚本
--==============================
简言之,将rman的备份恢复命令写成脚本并保存在恢复目录内,恢复目录内的脚本可用性及通用性高于基于文件系统的脚本。
客户端只要能够登录到RMAN恢复目录,则这些脚本可用,尤其对于global脚本,可以被任意注册的数据库调度。哈哈哈哈哈哈
关于如何创建恢复目录数据库及恢复目录脚本,此处省略,请参考:
RMAN catalog 的创建和使用
基于catalog 创建RMAN存储脚本
基于catalog 的RMAN 备份与恢复
一、脚本的分类
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 ''--将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