在数据库中启用块跟踪
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脚本
[oracle@db ~]$ 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
[oracle@db ~]$ 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
自动调用
[oracle@db ~]$ 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
#授予脚本执行权限
oracle@SZDB:~> chmod u+x rman_bak_sh
#执行shell脚本
oracle@SZDB:~> /rman_bak_sh
RMAN> RMAN> > > > > > > > > > > > > > > > > > > > > RMAN> oracle@SZDB:~>
crontab详解:http://718693.blog.51cto.com/708693/1683129