oracle RMAN备份步骤

1、 要使用RMAN备份前提是必须启动ORACLE归档日志功能;
2、 首先检查数据库归档日志模式,以DBA用户模式登陆系统,执行
SELECT log_mode from v$database;--查看数据库归档方式

3、 如果结果为NOARCHIVELOG则需要将数据库模式设置为归档模式,否则跳过此步
A、 关闭数据库
SQL> shutdown immediate;

B、 挂起模式启动数据库
SQL> startup mount;

C、 将数据库设置成归档模式
SQL> alter database archivelog;

D、 启动数据库
SQL> alter database open;

E、 重新做第二步的检查,如果为ARCHIVELOG表明数据库归档模式启动成功;
4、 利用RMAN做批处理备份脚本,为了简单这里只做两层的备份,0级备份和1级备份,0级备份代表全库备份,1级为增量备份:
A、 批处理脚本,可以根据实际情况做稍许调整,这边不做详细介绍了,经我测试在win7下执行是无问题的

set oracle_sid=orcl
set y=%date:~0,4%
set m=%date:~5,2%
set d=%date:~8,2%
set h=%time:~0,2%
set mi=%time:~3,2%
set s=%time:~6,2%
rman target / log f:\backup\logs\%y%%m%%d%_%h%%mi%%s%.log cmdfile=F:\backup\backupscript\database_backup_orcl_level0.rman

pause


B、 RMAN脚本
================FILENAME: database_backup_orcl_level0.rman==============
================我是分割线====0级备份===============================

RUN{
 configure retention policy to redundancy 2;
 #CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF  1  DAYS;

 CONFIGURE CONTROLFILE AUTOBACKUP ON;

 
 CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "f:/backup/%F%T.control_bak";

 ALLOCATE CHANNEL CH1 DEVICE TYPE DISK FORMAT "f:/backup/%U%T%t.bak";

 BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL=0 DATABASE SKIP INACCESSIBLE FILESPERSET 10 

     PLUS ARCHIVELOG FILESPERSET 20

     DELETE ALL INPUT;

 RELEASE CHANNEL CH1;
}

 ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;

 CROSSCHECK BACKUPSET;

 DELETE NOPROMPT OBSOLETE;
===============分割线==============================================
================FILENAME: database_backup_orcl_level1.rman==============
================我是分割线====1级备份===============================
RUN{
 configure retention policy to redundancy 2;
 #CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF  1  DAYS;

 CONFIGURE CONTROLFILE AUTOBACKUP ON;

 
 CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "f:/backup/%F%T.control_bak";

 ALLOCATE CHANNEL CH1 DEVICE TYPE DISK FORMAT "f:/backup/%U%T%t.bak";

 BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL=1 DATABASE SKIP INACCESSIBLE FILESPERSET 10 

     PLUS ARCHIVELOG FILESPERSET 20

     DELETE ALL INPUT;

 RELEASE CHANNEL CH1;
}

 ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;

 CROSSCHECK BACKUPSET;

 DELETE NOPROMPT OBSOLETE;
===============分割线==============================================

小常识:这里我用的增量备份模式为默认模式,RMAN默认是DIFFERENTIAL (差异),模式,另外还有一种 CUMULATIVE (累积)方式,需要显示指定,如下:
RMAN> BACKUP INCREMENTAL LEVEL=1 CUMULATIVE DATABASE;

两者的区别这里就不做详细介绍了
5、 接下来只要设定好执行两个级别批处理备份的计划任务执行时间就行了,需要注意的是任务执行时间上要有时间差,不要两级备份的时间同时发生,这点要特别注意。

你可能感兴趣的:(oracle,sql,F#,脚本)