rman备份脚本

在数据库中启用块跟踪

alter database enable block change tracking;

alter database enable block change tracking using file ‘/u01/app/oracle/track/blockchange.trc‘;

取消块跟踪

alter database disable block change tracking

查看是否启动块跟踪

SQL> select * from v$block_change_tracking;

在RMAN 下执行:

备份文件:

CONFIGURE BACKUP OPTIMIZATION ON

CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   ‘/orahome/oracle/zjgd_back/%T/%U‘;

CONFIGURE CHANNEL DEVICE TYPE DISK clear;

控制文件:

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/orahome/oracle/zjgd_back/%T/%F‘;

snap:

CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/orahome/oracle/zjgd_back/snapcf_zjgd.f‘;

%c 备份片的拷贝数(从1开始编号);

%d 数据库名称;

%D 位于该月中的天数 (DD);

%M 位于该年中的月份 (MM);

%F 一个基于DBID唯一的名称,这个格式的形式为c-xxx-YYYYMMDD-QQ,其中xxx为该数据库的DBID,YYYYMMDD为日期,QQ是一个1-256的序列;

%n 数据库名称,并且会在右侧用x字符进行填充,使其保持长度为8;

%u 是一个由备份集编号和建立时间压缩后组成的8字符名称。利用%u可以为每个备份集生成一个唯一的名称;

%p 表示备份集中备份片段的编号,从1开始编号;

%U 是%u_%p_%c的简写形式,利用它可以为每一个备份片段(即磁盘文件)生成一个唯一名称,这是最常用的命名方式;

%s 备份集的号;

%t 备份集时间戳;

%T 年月日格式(YYYYMMDD);

你可以在备份的时候指定~比如

RMAN> backup current controlfile format‘/home/oracle/%d_%M_%D‘

RMAN> configure controlfile autobackup on;

new RMAN configuration parameters:

CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters are successfully stored

RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   ‘/u01/app/oracle/backup/%T%U‘

2> ;

new RMAN configuration parameters:

CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   ‘/u01/app/oracle/backup/%T%U‘;

new RMAN configuration parameters are successfully stored

零级备份脚本

run {

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

allocate channel ch3 device type disk;

backup as compressed backupset incremental level 0 tag ‘db0‘ database plus archivelog all delete all input;

release channel ch1;

release channel ch2;

release channel ch3;

}

ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;

CROSSCHECK BACKUPSET;

DELETE NOPROMPT OBSOLETE;

rman target / cmdfile=/home/oracle/rmanlevel0.rman log=/home/oracle/rmanlog

run {

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

allocate channel ch3 device type disk;

backup as compressed backupset incremental level 1 tag ‘db1‘ database plus archivelog all delete all input;

release channel ch1;

release channel ch2;

release channel ch3;

}

ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;

CROSSCHECK BACKUPSET;

DELETE NOPROMPT OBSOLETE;

零级备份脚本

run{

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

backup as compressed backupset incremental level 0 tag ‘satdb0‘ format ‘/u01/app/oracle/backup/satdb0%T_%U‘

database skip readonly;

sql ‘alter system archive log current‘;

backup as compressed backupset filesperset 20 format ‘/u01/app/oracle/backup/arch%T_%U‘

archivelog all delete all input;

release channel ch1;

release channel ch2;

}

差异增量备份

run{

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

backup as compressed backupset incremental level 1 tag ‘db_level1‘ format ‘/u01/app/oracle/backup/db1%T_%U‘

database skip readonly;

sql ‘alter system archive log current‘;

backup as compressed backupset filesperset 20 format ‘/u01/app/oracle/backup/arch%T_%U‘

archivelog all delete all input;

release channel ch1;

release channel ch2;

}

累计增量备份

run{

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

backup as compressed backupset incremental level 1 tag ‘db_level1‘ format ‘/u01/app/oracle/backup/db1%T_%U‘

cumulative database skip readonly;

sql ‘alter system archive log current‘;

backup as compressed backupset filesperset 20 format ‘/u01/app/oracle/backup/arch%T_%U‘

archivelog all delete all input;

delete noprompt obsolete;

release channel ch1;

release channel ch2;

}

shell脚本

[[email protected] ~]$ cat rmanbak.sh

#!/bin/bash

#by lineqi

#create time:20150731

source /home/oracle/.bash_profile

v_date=`date +%Y%m%d`

$ORACLE_HOME/bin/rman target /  cmdfile=/home/oracle/rman_level0.rman log=/home/oracle/rmanlog$v_date append

exit

[[email protected] ~]$ cat rmanbak_inr.sh

#!/bin/bash

#by lineqi

#create time:20150731

source /home/oracle/.bash_profile

v_date=`date +%Y%m%d`

$ORACLE_HOME/bin/rman target /  cmdfile=/home/oracle/rman_level1.rman log=/home/oracle/rmanloglevel1$v_date append

exit

自动调用

[[email protected] ~]$ crontab -l

0 11 * * 6 /home/oracle/rmanbak.sh

0 12 * * * /home/oracle/rmanbak_inr.sh

参考资料

rman 备份脚本

export ORACLE_SID=CNMMBO

$ORACLE_HOME/bin/rman log=/users/oracle/bak/rmanlog <<EOF

connect target /

RUN {

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF  DAYS;

CONFIGURE BACKUP OPTIMIZATION ON;

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/users/oracle/bak/%d_%F‘;

ALLOCATE CHANNEL CH TYPE DISK MAXPIECESIZE=G;

ALLOCATE CHANNEL CH TYPE DISK MAXPIECESIZE=G;

SET LIMIT CHANNEL CH READRATE=;

SET LIMIT CHANNEL CH KBYTES=;

SET LIMIT CHANNEL CH READRATE=;

SET LIMIT CHANNEL CH KBYTES=;

CROSSCHECK ARCHIVELOG ALL;

DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;

BACKUP

DATABASE FORMAT ‘/users/oracle/bak/%d_FULL__%U‘;

SQL ‘ALTER SYSTEM ARCHIVE LOG CURRENT‘;

BACKUP ARCHIVELOG ALL FORMAT ‘/users/oracle/bak/%d_LF_%U‘ DELETE  INPUT;

DELETE NOPROMPT OBSOLETE;

RELEASE CHANNEL CH;

RELEASE CHANNEL CH;

}

EXIT;

EOF

exit

#授予脚本执行权限

[email protected]:~> chmod u+x rman_bak_sh

#执行shell脚本

[email protected]:~> /rman_bak_sh

RMAN> RMAN> > > > > > > > > > > > > > > > > > > > > RMAN> [email protected]:~>

crontab详解:http://718693.blog.51cto.com/708693/1683129

时间: 2024-10-28 16:31:59

rman备份脚本的相关文章

Oracle 11g R2 RAC RMAN备份脚本示例

一.将RAC切换成归档模式 1. 修改数据库的归档模式,通常在安装RAC的时候都会配置归档并且使用闪回区,已经配置过归档下面的方式可以略过. SQL> alter system set cluster_database=false scope=spfile sid='*'; 2. 关闭所有实例(两边都要shutdown) SQL> shutdown immediate 或直接关闭所有实例   $ srvctl stop database -d orcl 3. 在任意一个实例上将数据库启动到mo

RMAN备份脚本执行遇到RMAN-03002,06091问题处理

一 问题描述 客户说RMAN备份脚本执行有的时候报错,有的时候正常!!! 远程登陆客户环境,查询最后一次备份的日志报错信息,得到 RMAN-03002: failure of delete command at xxx   RMAN-06091: no channel allocated for maintenance (of an appropriate type) 二 参考链接 https://www.linuxidc.com/Linux/2013-01/78144.htm Encounte

ORCLE RMAN备份脚本

1.Linux下oracle备份脚本 export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 export PATH=$PATH:$ORACLE_HOME/bin: export NLS_LANG=AMERICAN_AMERICA.zhs16gbk export ORACLE_SID=orcl rman target / nocatalog log=/tmp/rman_fu

rman备份脚本shell版

1.数据库全备到硬盘 [[email protected] scripts]$ cat rman_backup.sh   source /home/oracle/.bash_profile   rman target / log=/home/oracle/backup/backupall_rman.log<<EOF   run   {   allocate channel ch1 device type disk;  #分配通道   allocate channel ch2 device ty

oracle数据库中rman备份脚本非常实用

查询字符集 SQL> select * from nls_database_parameters; NLS_CHARACTERSETAL32UTF8 备份时字符集很重要,不然会出乱码 一.0级备份(全备)红色是要修改的,根据个人的存放位置. [[email protected] script]$ cat db_bak0.rman run{    configure retention policy to recovery window of 8 days;    configure contro

Oracle Rman备份脚本与自动删除重复备份文件

#!/bin/sh source /home/oracle/.bash_profile if [ -z $1 ] then echo "Please Input a number,Usage: 0|1|2" exit else RMAN_LEVEL=$1 fi export ORACLE_SID=xxxx export TODAY=`date '+%Y%m%d'` export RMAN_DIR=/backup/archivelog/rman/$ORACLE_SID/$TODAY-$R

rman 备份脚本

[[email protected] ~]$ ls Desktop oracle_backup.rman oracle_backup.sh [[email protected] ~]$ cat oracle_backup.rman run{ CONFIGURE BACKUP OPTIMIZATION ON; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS; C

一周RMAN备份脚本

#! /bin/bash#crontab---->00 20 * * 0 su - oracle -c '/scripts/oracle_full_backup.sh'#crontab---->00 20 * * 1-6 su - oracle -c '/scripts/oracle_inc_backup.sh'export BACKUP_DIR=/backupexport ORACLE_HOME=/oracle/oracle/product/11.2.0/db_1#exec >>

linux 下RMAN备份shell脚本

RMAN备份对于Oracle数据库的备份与恢复简单易用,成本低廉.对于使用非catalog方式而言,将RMAN脚本嵌入到shell脚本,然后再通过crontab来实现中小型数据库数据库备份无疑是首选.本文提供了一个简单易用的基于linux shell下的RMAN备份脚本供参考.大家可根据自己的需要进行适当调整. RMAN备份相关方面的知识较多,可以参考:    RMAN 概述及其体系结构    RMAN 配置.监控与管理    RMAN 备份详解    RMAN 还原与恢复    RMAN ca