全量备份 首先修改一些基本配置 configure controlfile autobackup on; configure controlfile autobackup format for device type disk to ‘/u01/backup/%d-ctrl-%F’; control_file_record_keep_time=30
// 创建RMAN脚本 /u01/exec/fulldb.rmn[oracle@orcl ~]$ vi /u01/exec/fulldb.rmn
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;delete noprompt backupset completed before 'sysdate-7';
sql 'alter system archive log current';
backup format '/u01/backup/%d_full_%U' database;
backup archivelog all format '/u01/archbak/%d_arch_%U'delete all input;
release channel c1;
release channel c2;
release channel c3;}// 测试执行[oracle@orcl ~]$ rman target / cmdfile /u01/exec/fulldb.rmn
Recovery Manager: Release 12.1.0.2.0- Production on Fri Dec 708:37:322018Copyright(c)1982,2014, Oracle and/or its affiliates. All rights reserved.
connected to target database:ORCL(DBID=1519857657)RMAN> run{2> allocate channel c1 type disk;3> allocate channel c2 type disk;4> allocate channel c3 type disk;5>delete noprompt backupset completed before 'sysdate-7';6> sql 'alter system archive log current';7> backup format '/u01/backup/%d_full_%U' database;8> backup archivelog all format '/u01/archbak/%d_arch_%U'delete all input;9> release channel c1;10> release channel c2;11> release channel c3;12>}13>
using target database control file instead of recovery catalog
allocated channel: c1
channel c1:SID=261 device type=DISK
allocated channel: c2
channel c2:SID=39 device type=DISK
allocated channel: c3
channel c3:SID=278 device type=DISK
specification does not match any backup in the repository
sql statement: alter system archive log current
Starting backup at 2018-12-0708:37:35
channel c1: starting full datafile backup set
channel c1: specifying datafile(s)in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/tbs01.dbf
channel c1: starting piece 1 at 2018-12-0708:37:35
channel c2: starting full datafile backup set
channel c2: specifying datafile(s)in backup set
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel c2: starting piece 1 at 2018-12-0708:37:35
channel c3: starting full datafile backup set
channel c3: specifying datafile(s)in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
channel c3: starting piece 1 at 2018-12-0708:37:35
channel c3: finished piece 1 at 2018-12-0708:41:31
piece handle=/u01/backup/ORCL_full_78tk5lef_1_1 tag=TAG20181207T083735 comment=NONE
channel c3: backup set complete, elapsed time:00:03:56
channel c2: finished piece 1 at 2018-12-0708:41:51
piece handle=/u01/backup/ORCL_full_77tk5lef_1_1 tag=TAG20181207T083735 comment=NONE
channel c2: backup set complete, elapsed time:00:04:16
channel c1: finished piece 1 at 2018-12-0708:42:01
piece handle=/u01/backup/ORCL_full_76tk5lef_1_1 tag=TAG20181207T083735 comment=NONE
channel c1: backup set complete, elapsed time:00:04:26
Finished backup at 2018-12-0708:42:01
Starting backup at 2018-12-0708:42:01
current log archived
channel c1: starting archived log backup set
channel c1: specifying archived log(s)in backup set
input archived log thread=1 sequence=165RECID=159STAMP=994235855
channel c1: starting piece 1 at 2018-12-0708:42:02
channel c2: starting archived log backup set
channel c2: specifying archived log(s)in backup set
input archived log thread=1 sequence=166RECID=160STAMP=994236121
channel c2: starting piece 1 at 2018-12-0708:42:02
channel c1: finished piece 1 at 2018-12-0708:42:03
piece handle=/u01/archbak/ORCL_arch_79tk5lmq_1_1 tag=TAG20181207T084202 comment=NONE
channel c1: backup set complete, elapsed time:00:00:01
channel c1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2018_12_07/o1_mf_1_165_g0mj6grb_.arc RECID=159STAMP=994235855
channel c2: finished piece 1 at 2018-12-0708:42:03
piece handle=/u01/archbak/ORCL_arch_7atk5lmq_1_1 tag=TAG20181207T084202 comment=NONE
channel c2: backup set complete, elapsed time:00:00:01
channel c2: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2018_12_07/o1_mf_1_166_g0mjgsyd_.arc RECID=160STAMP=994236121
Finished backup at 2018-12-0708:42:03
Starting Control File and SPFILE Autobackup at 2018-12-0708:42:03
piece handle=/u01/backup/ORCL-ctrl-c-1519857657-20181207-02 comment=NONE
Finished Control File and SPFILE Autobackup at 2018-12-0708:42:04
released channel: c1
released channel: c2
released channel: c3
Recovery Manager complete.// 创建shell脚本 /u01/exec/fulldb.sh// select userenv('language') from dual; 查看oracle服务端字符集// log 记录日志到 /u01/backup/fulldb.log// append 追加日志内容 不覆盖[oracle@orcl ~]$ vi /u01/exec/fulldb.sh
echo "======Full Backup Begin "`(date +"%Y-%m-%d %H:%M:%S")`"======">>/u01/backup/fulldb.log
exportORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
exportORACLE_SID=orcl
exportNLS_LANG=AMERICAN_AMERICA.AL32UTF8exportNLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'/u01/app/oracle/product/12.1.0/dbhome_1/bin/rman target / cmdfile /u01/exec/fulldb.rmn log /u01/backup/fulldb.log append
echo "======Full Backup End "`(date +"%Y-%m-%d %H:%M:%S")`"======">>/u01/backup/fulldb.log
// 给予shell脚本执行权限[oracle@orcl ~]$ ll -h /u01/exec/
total 8.0K
-rw-r--r--1 oracle oinstall 225 Dec 316:29 fulldb.rmn
-rw-r--r--1 oracle oinstall 525 Dec 317:25 fulldb.sh
[oracle@orcl ~]$ chmod 777/u01/exec/fulldb.sh
[oracle@orcl ~]$ ll -h /u01/exec/
total 8.0K
-rw-r--r--1 oracle oinstall 225 Dec 316:29 fulldb.rmn
-rwxrwxrwx 1 oracle oinstall 525 Dec 317:25 fulldb.sh
// crontab定时任务// 2代表标准错误;1代表标准输出[oracle@orcl ~]$ crontab -e
01***/u01/exec/fulldb.sh >/dev/null2&>1// 查看日志输出[oracle@orcl ~]$ tail -f /u01/backup/fulldb.log
增量备份 检查Block ChangeTracking是否启用 当Block Change Tracking这个特性启用时,RMAN可以通过块跟踪文件,判断出哪些块是属于增量备份所使用的,进而避免扫描数据文件中的每一个块。 select * from v$block_change_tracking; alter database enable block change tracking using file ‘/u01/block_change/tracking.file’;
// 创建0级备份RMAN脚本 /u01/exec/level0.rmn[oracle@orcl ~]$ vi /u01/exec/level0.rmn
run{delete noprompt backupset completed before 'sysdate-14';
sql 'alter system archive log current';
backup incremental level 0 format '/u01/backup/%d_inc0_%U' database;
backup archivelog all format '/u01/archbak/%d_arch_%U'delete all input;}// 创建1级备份RMAN脚本 /u01/exec/level1.rmn[oracle@orcl ~]$ vi /u01/exec/level1.rmn
run{delete noprompt backupset completed before 'sysdate-14';
sql 'alter system archive log current';
backup incremental level 1 format '/u01/backup/%d_inc1_%U' database;
backup archivelog all format '/u01/archbak/%d_arch_%U'delete all input;}// 创建0级备份shell脚本[oracle@orcl ~]$ vi /u01/exec/level0.sh
echo "======Level0 Backup Begin "`(date +"%Y-%m-%d %H:%M:%S")`"======">>/u01/backup/incdb.log
exportORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
exportORACLE_SID=orcl
exportNLS_LANG=AMERICAN_AMERICA.AL32UTF8exportNLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'/u01/app/oracle/product/12.1.0/dbhome_1/bin/rman target / cmdfile /u01/exec/level0.rmn log /u01/backup/incdb.log append
echo "======Level0 Backup End "`(date +"%Y-%m-%d %H:%M:%S")`"======">>/u01/backup/incdb.log
// 创建1级备份shell脚本[oracle@orcl ~]$ vi /u01/exec/level1.sh
echo "======Level1 Backup Begin "`(date +"%Y-%m-%d %H:%M:%S")`"======">>/u01/backup/incdb.log
exportORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
exportORACLE_SID=orcl
exportNLS_LANG=AMERICAN_AMERICA.AL32UTF8exportNLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'/u01/app/oracle/product/12.1.0/dbhome_1/bin/rman target / cmdfile /u01/exec/level1.rmn log /u01/backup/incdb.log append
echo "======Level1 Backup End "`(date +"%Y-%m-%d %H:%M:%S")`"======">>/u01/backup/incdb.log
// crontab定时任务// 2代表标准错误;1代表标准输出[oracle@orcl ~]$ crontab -e
// 星期天凌晨3点执行0级备份03**0/u01/exec/level0.sh >/dev/null2&>1// 星期1-6凌晨3点执行1级备份03**1-6/u01/exec/level1.sh >/dev/null2&>1// 查看日志输出[oracle@orcl ~]$ tail -f /u01/backup/incdb.log
全量备份// 创建RMAN脚本 /u01/exec/fulldb.rmn[oracle@orcl ~]$ vi /u01/exec/fulldb.rmn run{delete noprompt backupset completed before 'sysdate-7';sql 'alter system archive log current';backup format '/u...