ORACLE-RMAN自动备份和恢复

来源:这里教程网 时间:2026-03-03 16:02:07 作者:

以下介绍的是每周1-6增量备份,每周日全量备份。 通过系统启动自动化任务 [oracle@orcl ~]$ crontab -l 10 00 * * 0  /home/scripts/rmanlevel0.sh  10 00 * * 1,2,3,4,5,6  /home/scripts/rmanlevel1.sh  30 00 * * * /home/oracle/report/awr.sh [oracle@orcl ~]$ cat /home/scripts/rmanlevel1.sh---增量备份 #!/bin/sh a=`date "+%y_%m%d"` NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS' export ORACLE_BASE=/home/app/oracle export ORACLE_HOME=/home/app/oracle/product/11.2.0 export ORACLE_SID=orcl export PATH=$PATH:$ORACLE_HOME/bin export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib export NLS_LANG=AMERICAN_AMERICA.UTF8 export ORACLE_UNQNAME=orcl rman target / log /home/oracle/rman_log/rmanlv1$a.log <<EOF RUN {         CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/data_backup/ctlbackup/%F';         CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/data_backup/%U';         BACKUP INCREMENTAL LEVEL 1 CUMULATIVE  DATABASE PLUS ARCHIVELOG DELETE ALL INPUT;         DELETE FORCE NOPROMPT OBSOLETE REDUNDANCY 1; } QUIT; EOF source /home/oracle/.bash_profile b=`date -d last-day +%Y%m%d` a=`date "+%y_%m%d"` echo $a echo $b echo "RAC-RMANBACKUP LOG $a" |mail -a /home/oracle/rman_log/"rmanlv0$a.log" -s "RAC-RMAN_BACKUP_LOG-$a" test@test.com [oracle@orcl ~]$ cat /home/scripts/rmanlevel0.sh ---全量备份 #!/bin/sh a=`date "+%y_%m%d"` NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS' export ORACLE_BASE=/home/app/oracle export ORACLE_HOME=/home/app/oracle/product/11.2.0 export ORACLE_SID=orcl export PATH=$PATH:$ORACLE_HOME/bin export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib export NLS_LANG=AMERICAN_AMERICA.UTF8 export ORACLE_UNQNAME=orcl rman target / log /home/oracle/rman_log/rman$a.log <<EOF RUN {        CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/data_backup/ctlbackup/%F';         CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/data_backup/%U';         BACKUP INCREMENTAL LEVEL 0 SECTION SIZE 200G DATABASE  PLUS ARCHIVELOG DELETE ALL INPUT;         DELETE FORCE NOPROMPT OBSOLETE REDUNDANCY 1; } QUIT; EOF source /home/oracle/.bash_profile b=`date -d last-day +%Y%m%d` a=`date "+%y_%m%d"` echo $a echo $b echo "orcl-RMANBACKUP LOG $a" |mail -a /home/oracle/rman_log/"rmanlv0$a.log" -s "orcl-RMAN_BACKUP_LOG-$a" test@test.com --------- 基于RMAN备份的恢复 1. 先把数据库软件创建好, 2. 然后创建一个和需要恢复的数据库同名的实例 3. 把实例名下面的所有数据文件删除。 4. 恢复控制文件  在umount状态下:  RMAN>startup nomount  RMAN>restore controlfile to '/home/oracle/app/oracle/oradata/orcl/control01.ctl' from '/data/oracle/ctlbackup/c-3667560725-20170516-00' ;  或者:restore controlfile from autobackup; [root@orcl ctlbackup]# chown -R oracle:oinstall /data/oracle/ctlbackup/ [root@orcl ctlbackup]# cp /home/oracle/app/oracle/oradata/orcl/control01.ctl /home/oracle/app/oracle/fast_recovery_area/orcl/control02.ctl    RMAN>alter database mount; RMAN> list incarnation; List of Database Incarnations DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time ------- ------- -------- ---------------- --- ---------- ---------- 1       1       orcl    3667560725       PARENT  1          24-AUG-13 2       2       orcl    3667560725       CURRENT 925702     22-DEC-16 run { set newname for datafile 1 to '/home/oracle/app/oracle/oradata/orcl/system01.dbf'; set newname for datafile 2 to '/home/oracle/app/oracle/oradata/orcl/sysaux01.dbf'; set newname for datafile 3 to '/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf'; set newname for datafile 4 to '/home/oracle/app/oracle/oradata/orcl/users01.dbf'; set newname for datafile 5 to '/home/oracle/app/oracle/oradata/orcl/ts_test01.dbf'; set newname for datafile 6 to '/home/oracle/app/oracle/oradata/orcl/ts_test02.dbf'; set newname for datafile 7 to '/home/oracle/app/oracle/oradata/orcl/ts_test03.dbf'; set newname for datafile 8 to '/home/oracle/app/oracle/oradata/orcl/ts_test04.dbf'; set newname for datafile 9 to '/home/oracle/app/oracle/oradata/orcl/ts_test05.dbf'; set newname for datafile 10 to '/home/oracle/app/oracle/oradata/orcl/ts_orcl_01.dbf'; set newname for datafile 11 to '/home/oracle/app/oracle/oradata/orcl/ts_orcl_02.dbf'; restore database; switch datafile all; } RMAN> recover database; Starting recover at 17-MAY-17 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=176 device type=DISK starting media recovery channel ORA_DISK_1: starting archived log restore to default destination channel ORA_DISK_1: restoring archived log archived log thread=1 sequence=2850 channel ORA_DISK_1: restoring archived log archived log thread=1 sequence=2851 channel ORA_DISK_1: reading from backup piece /data/oracle/rmanbackset/rps4bve7_1_1 channel ORA_DISK_1: piece handle=/data/oracle/rmanbackset/rps4bve7_1_1 tag=TAG20170516T050407 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:15 archived log file name=/home/oracle/app/oracle/fast_recovery_area/orcl/archivelog/2017_05_17/o1_mf_1_2850_dkq7ht3d_.arc thread=1 sequence=2850 channel default: deleting archived log(s) archived log file name=/home/oracle/app/oracle/fast_recovery_area/orcl/archivelog/2017_05_17/o1_mf_1_2850_dkq7ht3d_.arc RECID=2853 STAMP=944210947 archived log file name=/home/oracle/app/oracle/fast_recovery_area/orcl/archivelog/2017_05_17/o1_mf_1_2851_dkq7ht3l_.arc thread=1 sequence=2851 channel default: deleting archived log(s) archived log file name=/home/oracle/app/oracle/fast_recovery_area/orcl/archivelog/2017_05_17/o1_mf_1_2851_dkq7ht3l_.arc RECID=2852 STAMP=944210940 unable to find archived log archived log thread=1 sequence=2852 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 05/17/2017 08:49:25 RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 2852 and starting SCN of 1169238920 RMAN> recover database until sequence 2852; Starting recover at 17-MAY-17 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:01 Finished recover at 17-MAY-17 RMAN> alter database open; RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of alter db command at 05/17/2017 09:20:34 ORA-01589: must use RESETLOGS or NORESETLOGS option for database open RMAN> alter database open resetlogs; RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of alter db command at 05/17/2017 09:21:27 ORA-00349: failure obtaining block size for '/datafile/redo/redo01.log' ORA-27041: unable to open file Linux-x86_64 Error: 2: No such file or directory Additional information: 9    SQL> select * from v$logfile;  alter database rename file '/datafile/redo/redo01.log' to '/home/oracle/app/oracle/oradata/orcl/redo01.log';  alter database rename file '/datafile/redo/redo02.log' to '/home/oracle/app/oracle/oradata/orcl/redo02.log';  alter database rename file '/datafile/redo/redo03.log' to '/home/oracle/app/oracle/oradata/orcl/redo03.log';  alter database rename file '/datafile/redo/redo04.log' to '/home/oracle/app/oracle/oradata/orcl/redo04.log';  alter database rename file '/datafile/redo/redo05.log' to '/home/oracle/app/oracle/oradata/orcl/redo05.log';  alter database rename file '/datafile/redo/redo06.log' to '/home/oracle/app/oracle/oradata/orcl/redo06.log'; RMAN> alter database open resetlogs; RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of alter db command at 05/17/2017 09:30:51 ORA-00392: log 2 of thread 1 is being cleared, operation not allowed ORA-00312: online log 2 thread 1: '/home/oracle/app/oracle/oradata/orcl/redo02.log' SQL> alter database clear logfile group 2; RMAN>  alter database open resetlogs;       database opened

相关推荐