准备工作,使用如下脚本进行数据库的全备份
[oracle@localhost ~]$ more rman_backup.sh
#!/bin/sh
RMAN_OUTPUT_LOG=/home/oracle/rman_output.log
RMAN_ERROR_LOG=/home/oracle/rman_error.log
rman target / log=/home/oracle/rman_output.log<<EOF
run
{
allocate channel ch1 device type disk;
backup full database format '/home/oracle/rman_bakckup/db_fullbackup_%d_%s_%p_%T';
backup current controlfile format '/home/oracle/rman_bakckup/ctl_%d_%s_%p_%T';
backup archivelog all format '/home/oracle/rman_bakckup/arch_%d_%s_%p_%T';
backup spfile format '/home/oracle/rman_bakckup/spfile_%d_%s_%p_%T';
release channel ch1;
}
EOF
1.退出日志应用模式
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Mon Jan 14 14:31:26 2019
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> connect / as sysdba
Connected.
SQL> alter database recover managed standby database cancel;
Database altered.
2.停掉数据库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
3.模拟删除掉users01.dbf数据文件
[oracle@localhost slnngkdg]$cd /u01/app/oracle/oradata/slnngkdg
[oracle@localhost slnngkdg]$ mv users01.dbf bak_users01.dbf
4.启动数据库
SQL> startup
ORACLE instance started.
Total System Global Area 3724607488 bytes
Fixed Size 2258760 bytes
Variable Size 788531384 bytes
Database Buffers 2919235584 bytes
Redo Buffers 14581760 bytes
Database mounted.
ORA-10458: standby database requires recovery
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/slnngkdg/users01.dbf'
提示数据文件找不到
5.完成恢复数据库
步骤4的已经启动数据库到mount状态,可以直接做恢复
run{
restore database;
recover database;
}
RMAN> run{
2> restore database;
3> recover database;
4> }
Starting restore at 14-JAN-19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=15 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/slnngkdg/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/slnngkdg/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/slnngkdg/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/slnngkdg/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/slnngkdg/tps_data01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/slnngkdg/mrkt.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rman_bakckup/db_fullbackup_SLNNGK_26_1_20190114
channel ORA_DISK_1: piece handle=/home/oracle/rman_bakckup/db_fullbackup_SLNNGK_26_1_20190114 tag=TAG20190114T140841
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:04:55
Finished restore at 14-JAN-19
Starting recover at 14-JAN-19
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 281 is already on disk as file /u01/app/oracle/archlog/1_281_994182077.dbf
archived log for thread 1 with sequence 282 is already on disk as file /u01/app/oracle/archlog/1_282_994182077.dbf
archived log file name=/u01/app/oracle/archlog/1_281_994182077.dbf thread=1 sequence=281
archived log file name=/u01/app/oracle/archlog/1_282_994182077.dbf thread=1 sequence=282
unable to find archived log
archived log thread=1 sequence=283
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/14/2019 15:12:39
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 283 and starting SCN of 5975154
原以为在主库做alter system switch logfile把283的归档日志同步到从库即可解决问题,但是还是不行,283的同步过去了,又要找284的
archived log thread=1 sequence=284
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 01/14/2019 15:25:39
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 284 and starting SCN of 5976687
6.只能做不完全恢复(注意::until不包括这个点,如until sequence 284,则不包括sequence 284)
run{
set until sequence 284;
restore database;
recover database;
}
RMAN> run{
2> set until sequence 284;
restore database;
recover database;
3> 4> 5> }
executing command: SET until clause
Starting restore at 14-JAN-19
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/slnngkdg/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/slnngkdg/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/slnngkdg/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/slnngkdg/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/slnngkdg/tps_data01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/slnngkdg/mrkt.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rman_bakckup/db_fullbackup_SLNNGK_26_1_20190114
channel ORA_DISK_1: piece handle=/home/oracle/rman_bakckup/db_fullbackup_SLNNGK_26_1_20190114 tag=TAG20190114T140841
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:15
Finished restore at 14-JAN-19
Starting recover at 14-JAN-19
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 281 is already on disk as file /u01/app/oracle/archlog/1_281_994182077.dbf
archived log for thread 1 with sequence 282 is already on disk as file /u01/app/oracle/archlog/1_282_994182077.dbf
archived log for thread 1 with sequence 283 is already on disk as file /u01/app/oracle/archlog/1_283_994182077.dbf
archived log file name=/u01/app/oracle/archlog/1_281_994182077.dbf thread=1 sequence=281
archived log file name=/u01/app/oracle/archlog/1_282_994182077.dbf thread=1 sequence=282
archived log file name=/u01/app/oracle/archlog/1_283_994182077.dbf thread=1 sequence=283
media recovery complete, elapsed time: 00:00:18
Finished recover at 14-JAN-19
7.打开数据库
SQL> alter database open;
Database altered.
从库必须是以open的方式打开,不能使用resetlogs选项
RMAN> alter database open resetlogs;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 01/14/2019 16:56:15
ORA-01666: control file is for a standby database
8.应用主库日志
alter database recover managed standby database using current logfile disconnect from session;