RMAN的一些脚本

时间:2021-05-24 00:47:03
confifure controlfile autobackup format device type disk to '/uo1/backup/%F';


configure controlfile autobackup on;
drop tablespace test including contents and datafiles;


alter system set log_archive_start=true scope=spfile;




shutdown immedidate 
startup mount;
archive log lisg 


使用rman备份整个数据库
backup as compressed backupset database plus archivelog delete all input


run{
allocate channel ch1 device type disk format '/uo1/backup/ch1_u%';
allocate channel ch2 device type disk format '/uo1/backup/ch2_u%';
backup as backupset
(datafile 1,4 channel ch1)
(datafile 2,3,4 channel ch2);
sql 'alter system archive log current';}




run{


allocate channel ch1 device type disk;
allocate channel ch2 device type disk;
backup as backupset format 'u01/backup/%u'
(datafile 1,4 channel ch1)
(datafile 2,3,5  channel ch2);
sql 'alter system archive log current';}






backup tablespace users;
backup as compressed backupset tablespace users;
backup as backupset datafile 1 format '/uo1/backup/datafile_01_%U';


%c:备份的副本数
%d:数据库名称
%D:位于该月的第几天
%M:位于该年的第几个月
%n:数据库名称,向右填补道最大的19个字符
%u:一个字符的名称,代表备份集和创建时间
%p:该备份集的备份号,从1开始创建的文件数
%u:一个唯一的名字%u_%p_%c;
%s:备份集的编号
%t:备份集的时间戳
%t:年月日的格式




backup current controlfile
backup nochecksum tablespace users tag='weekly_backup'
backup check logical tablespace users


backup incremental level 0 database


backup incremental level 1 database


alter database enable block change tracking
 using file 'e:/oracle/product/oradata/chtrack.log';




select filename,status,bytes form v$block_change_tracking


 alter database rename file 'e:/oracle/product/oradata/chtrack.log'
to 'e:/oracle/product/oradata/dsf/chtrack.log'


禁用块跟踪特性
alter database disable block change tracking;




在影像副本上应用增量备份


对镜像副本应用增量备份的例子
run{


backup incremental level 1 for recover of copy with tag  'incr_copy_backup' database;
recover copy of database with tag 'incr_copy_backup';}


list copy 查询当前的影像副本


创建一个表空间
create user rca identified by oracle
default tablespace tcat_tbs
temporary tablespace temp;




create tablespace jerry 
logging 
datafile 'F:\app\Administrator\oradatarorasxszstat01.dbf' 
size 32m 
autoextend on 
next 32m maxsize 512m 
extent management local;






 create user jerry_owner identified by oracle default tablespace jerry temporary
 tablespace temp;




grant recovery_catalog_owner to jerry_owner 




RMAN脚本管理


create script rman_backup{
sql'alter system checkpoint';
backup database format
'/u01/backup/offline_back/back_%u.dbf';
backup current controlfile format
'u01/backup/offline_backup/back_ctl_%u.dbf';}


执行脚本
run{
execute script rman_backup;}


使用rman费归档模式下的完全恢复




restore controlfile from 'u01/backup/....';