[oracle@bak ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Sun Oct 12 17:59:06 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ora10g (not mounted)
RMAN> restore database;
Starting restore at 12-OCT-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 10/12/2014 17:59:15
ORA-01507: database not mounted
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> restore database;
Starting restore at 12-OCT-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/ora10g/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/ora10g/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/ora10g/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/ora10g/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/ora10g/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/ora10g/zlm01.dbf
channel ORA_DISK_1: reading from backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141012_860776704_316.db
ORA-19870: error reading backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141012_860776704_316.db
ORA-19505: failed to identify file "/u01/orabackup/backupsets/ora10g-4175411955_20141012_860776704_316.db"
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
failover to previous backup
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/ora10g/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/ora10g/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/ora10g/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/ora10g/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/ora10g/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/ora10g/zlm01.dbf
channel ORA_DISK_1: reading from backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141011_860666488_312.db
ORA-19870: error reading backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141011_860666488_312.db
ORA-19505: failed to identify file "/u01/orabackup/backupsets/ora10g-4175411955_20141011_860666488_312.db"
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
failover to previous backup
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/ora10g/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/ora10g/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/ora10g/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/ora10g/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/ora10g/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/ora10g/zlm01.dbf
channel ORA_DISK_1: reading from backup piece /u01/orabackup/backupsets/ora10g-4175411955_20140928_859456907_308.db
ORA-19870: error reading backup piece /u01/orabackup/backupsets/ora10g-4175411955_20140928_859456907_308.db
ORA-19505: failed to identify file "/u01/orabackup/backupsets/ora10g-4175411955_20140928_859456907_308.db"
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
failover to previous backup
creating datafile fno=6 name=/u01/app/oracle/oradata/ora10g/zlm01.dbf
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 10/12/2014 17:59:33
ORA-01119: error in creating database file ‘/u01/app/oracle/oradata/ora10g/zlm01.dbf‘
ORA-27040: file create error, unable to create file
Linux Error: 2: No such file or directory
RMAN>
run{
set newname for datafile 3 to"/oradata/ora10g/sysaux01.dbf";
set newname for datafile 1 to"/oradata/ora10g/system01.dbf";
set newname for datafile 2 to"/oradata/ora10g/undotbs01.dbf";
set newname for datafile 3 to"/oradata/ora10g/sysaux01.dbf";
set newname for datafile 4 to"/oradata/ora10g/users01.dbf";
set newname for datafile 5 to"/oradata/ora10g/example01.dbf";
set newname for datafile 6 to"/oradata/ora10g/zlm01.dbf";
restore database;
switch datafile all;
10> }
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 12-OCT-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /oradata/ora10g/system01.dbf
restoring datafile 00002 to /oradata/ora10g/undotbs01.dbf
restoring datafile 00003 to /oradata/ora10g/sysaux01.dbf
restoring datafile 00004 to /oradata/ora10g/users01.dbf
restoring datafile 00005 to /oradata/ora10g/example01.dbf
restoring datafile 00006 to /oradata/ora10g/zlm01.dbf
channel ORA_DISK_1: reading from backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141012_860776704_316.db
channel ORA_DISK_1: restored backup piece 1
failover to piece handle=/oracle/backupsets/ora10g-4175411955_20141012_860776704_316.db tag=DB_BAK
channel ORA_DISK_1: restore complete, elapsed time: 00:02:17
Finished restore at 12-OCT-14
datafile 1 switched to datafile copy
input datafile copy recid=18 stamp=860783911 filename=/oradata/ora10g/system01.dbf
datafile 2 switched to datafile copy
input datafile copy recid=19 stamp=860783911 filename=/oradata/ora10g/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy recid=20 stamp=860783911 filename=/oradata/ora10g/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy recid=21 stamp=860783911 filename=/oradata/ora10g/users01.dbf
datafile 5 switched to datafile copy
input datafile copy recid=22 stamp=860783911 filename=/oradata/ora10g/example01.dbf
datafile 6 switched to datafile copy
input datafile copy recid=23 stamp=860783911 filename=/oradata/ora10g/zlm01.dbf
RMAN>
注意,这里会有一个failover to的操作,先是去/u01/orabackup/backupsets读取,但是发现没有,但不会像之前那么样报错,而是转到了刚才我们catalog过的目录“/oracle/backupsets”中去读取,这次很顺利就把数据文件恢复出来了
[oracle@bak ~]$ ll -lrth /oradata/ora10g/
total 1.2G
-rw-r----- 1 oracle oinstall 21M Oct 12 18:36 zlm01.dbf
-rw-r----- 1 oracle oinstall 31M Oct 12 18:36 users01.dbf
-rw-r----- 1 oracle oinstall 101M Oct 12 18:36 example01.dbf
-rw-r----- 1 oracle oinstall 166M Oct 12 18:37 undotbs01.dbf
-rw-r----- 1 oracle oinstall 271M Oct 12 18:37 sysaux01.dbf
-rw-r----- 1 oracle oinstall 561M Oct 12 18:38 system01.dbf
-rw-r----- 1 oracle oinstall 7.2M Oct 12 18:50 control03.ctl
-rw-r----- 1 oracle oinstall 7.2M Oct 12 18:50 control02.ctl
-rw-r----- 1 oracle oinstall 7.2M Oct 12 18:50 control01.ctl
8. 还原测试机数据库
RMAN> recover database;
Starting recover at 12-OCT-14
using channel ORA_DISK_1
starting media recovery
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=24
channel ORA_DISK_1: reading from backup piece /u01/orabackup/backupsets/ora10g-4175411955_20141012_860776830_317.arc
channel ORA_DISK_1: restored backup piece 1
failover to piece handle=/oracle/backupsets/ora10g-4175411955_20141012_860776830_317.arc tag=ARC_BAK
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/u01/app/oracle/product/10.2.0/db_1/dbs/arch1_24_858698568.dbf thread=1 sequence=24
unable to find archive log
archive log thread=1 sequence=25
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/12/2014 18:52:11
RMAN-06054: media recovery requesting unknown log: thread 1 seq 25 lowscn 1091432
RMAN> exit
Recovery Manager complete.
由于RMAN是不完全恢复,无法保证数据与源库是完全一致的,只能恢复到做备份集的那个时刻
[oracle@bak ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Oct 12 18:56:43 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-00344: unable to re-create online log
‘/u01/app/oracle/oradata/ora10g/redo01.log‘
ORA-27040: file create error, unable to create file
Linux Error: 2: No such file or directory
SQL> alter database add logfile ‘/oradata/ora10g/redo01.log‘ size 50m;
Database altered.
SQL> alter database add logfile ‘/oradata/ora10g/redo02.log‘ size 50m;
alter database add logfile ‘/oradata/redo02.log‘ size 50m
*
ERROR at line 1:
ORA-19502: write error on file "/oradata/ora10g/redo02.log", blockno 26625
(blocksize=512)
ORA-27072: File I/O error
Linux Error: 2: No such file or directory
Additional information: 4
Additional information: 26625
Additional information: 52736
SQL> !
[oracle@bak ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7.7G 7.3G 13M 100% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 506M 0 506M 0% /dev/shm
/dev/sdb1 5.0G 541M 4.2G 12% /data
很不幸,用作存放数据文件的磁盘是挂在/下面的,正好碰到磁盘空间不足,只剩13M了,导致无法创建之后的redo日志
把备份集删除,释放部分磁盘空间
[oracle@bak ~]$ cd /oracle/backupsets
[oracle@bak backupsets]$ rm -f *
rm: cannot remove `ora10g-4175411955_20141012_860776699_315.arc‘: Permission denied
rm: cannot remove `ora10g-4175411955_20141012_860776704_316.db‘: Permission denied
rm: cannot remove `ora10g-4175411955_20141012_860776830_317.arc‘: Permission denied
rm: cannot remove `ora10g-c-4175411955-20141012-00.ctl‘: Permission denied
[oracle@bak backupsets]$ exit
logout
[root@bak oradata]# cd /oracle/backupsets/
[root@bak backupsets]# ll
total 181172
-rw-r----- 1 oracle oinstall 4440064 Oct 12 16:46 ora10g-4175411955_20141012_860776699_315.arc
-rw-r----- 1 oracle oinstall 172843008 Oct 12 16:47 ora10g-4175411955_20141012_860776704_316.db
-rw-r----- 1 oracle oinstall 427520 Oct 12 16:47 ora10g-4175411955_20141012_860776830_317.arc
-rw-r----- 1 oracle oinstall 7602176 Oct 12 16:47 ora10g-c-4175411955-20141012-00.ctl
[root@bak backupsets]# rm -f *
[root@bak backupsets]# ll
total 0
[root@bak backupsets]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7.7G 7.1G 240M 97% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 506M 0 506M 0% /dev/shm
/dev/sdb1 5.0G 541M 4.2G 12% /data
[root@bak backupsets]# su - oracle
[oracle@bak ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Oct 12 19:21:27 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area 1073741824 bytes
Fixed Size 1223512 bytes
Variable Size 264242344 bytes
Database Buffers 805306368 bytes
Redo Buffers 2969600 bytes
Database mounted.
SQL> alter database add logfile ‘/oradata/ora10g/redo01.log‘ size 50m;
Database altered.
SQL> alter database add logfile ‘/oradata/ora10g/redo02.log‘ size 50m;
Database altered.
SQL> alter database add logfile ‘/oradata/ora10g/redo03.log‘ size 50m;
Database altered.
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-00344: unable to re-create online log
‘/u01/app/oracle/oradata/ora10g/redo01.log‘
ORA-27040: file create error, unable to create file
Linux Error: 2: No such file or directory
由于控制文件中记录的redo日志是在/u01/app/oracle/oradata/ora10g下面的,而由于测试机改到/oradata/ora10g下面,因此要修改控制文件中的内容,我们来重建一下控制文件
SQL> oradebug setmypid
Statement processed.
SQL> alter database backup controlfile to trace;
Database altered.
SQL> oradebug tracefile_name
/oracle/admin/ora10g/udump/ora10g_ora_30187.trc
SQL> !
查看ora10g_ora_30187.trc,复制其中resetlog部分的重建控制文件的SQL语句出来
CREATE CONTROLFILE REUSE DATABASE "ORA10G" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ‘/u01/app/oracle/oradata/ora10g/redo01.log‘ SIZE 50M,
GROUP 2 ‘/u01/app/oracle/oradata/ora10g/redo02.log‘ SIZE 50M,
GROUP 3 ‘/u01/app/oracle/oradata/ora10g/redo03.log‘ SIZE 50M,
GROUP 4 ‘/oradata/ora10g/redo01.log‘ SIZE 50M,
GROUP 5 ‘/oradata/ora10g/redo02.log‘ SIZE 50M,
GROUP 6 ‘/oradata/ora10g/redo03.log‘ SIZE 50M
-- STANDBY LOGFILE
DATAFILE
‘/oradata/ora10g/system01.dbf‘,
‘/oradata/ora10g/undotbs01.dbf‘,
‘/oradata/ora10g/sysaux01.dbf‘,
‘/oradata/ora10g/users01.dbf‘,
‘/oradata/ora10g/example01.dbf‘,
‘/oradata/ora10g/zlm01.dbf‘
CHARACTER SET ZHS16GBK
;
可以看到,刚才创建控制redo logfile时并没有指定group xxx,默认就会从未使用的组号开始命名,所以这里对应的就是group 4,group 5,group 6,因此只要把之前3组的语句删除,再重建一下控制文件即可
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1073741824 bytes
Fixed Size 1223512 bytes
Variable Size 264242344 bytes
Database Buffers 805306368 bytes
Redo Buffers 2969600 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE "ORA10G" RESETLOGS ARCHIVELOG
DATAFILE
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 4 ‘/oradata/ora10g/redo01.log‘ SIZE 50M,
GROUP 5 ‘/oradata/ora10g/redo02.log‘ SIZE 50M,
GROUP 6 ‘/oradata/ora10g/redo03.log‘ SIZE 50M
-- STANDBY LOGFILE
DATAFILE
‘/oradata/ora10g/system01.dbf‘,
‘/oradata/ora10g/undotbs01.dbf‘,
‘/oradata/ora10g/sysaux01.dbf‘,
‘/oradata/ora10g/users01.dbf‘,
‘/oradata/ora10g/example01.dbf‘,
‘/oradata/ora10g/zlm01.dbf‘
CHARACTER SET ZHS16GBK
;
Control file created.
SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-01100: database already mounted
SQL> alter database open resetlogs;
Database altered.
SQL> select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
READ WRITE PRIMARY
SQL> select group#,sequence#,(bytes/1024/1024) "SIZE(MB)",archived,status from v$log;
GROUP# SEQUENCE# SIZE(MB) ARC STATUS
---------- ---------- ---------- --- ----------------
4 0 50 YES UNUSED
5 0 50 YES UNUSED
6 1 50 NO CURRENT
至此,数据库已经顺利恢复完毕,当然,如果觉得redo logfile从group 4开始有点不顺眼,那么可以再做一下调整
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 1073741824 bytes
Fixed Size 1223512 bytes
Variable Size 264242344 bytes
Database Buffers 805306368 bytes
Redo Buffers 2969600 bytes
Database mounted.
SQL> alter database drop logfile ‘/oradata/ora10g/redo01.log‘;
Database altered.
SQL> alter database drop logfile ‘/oradata/ora10g/redo02.log‘;
alter database drop logfile ‘/oradata/ora10g/redo02.log‘
*
ERROR at line 1:
ORA-01567: dropping log 5 would leave less than 2 log files for instance ora10g
(thread 1)
ORA-00312: online log 5 thread 1: ‘/oradata/ora10g/redo02.log‘
oralce要求1个数据库实例至少要有2组日志,因此不允许删除剩余2组日志
SQL> alter database drop logfile ‘/oradata/ora10g/redo03.log‘;
alter database drop logfile ‘/oradata/ora10g/redo03.log‘
*
ERROR at line 1:
ORA-01623: log 6 is current log for instance ora10g (thread 1) - cannot drop
ORA-00312: online log 6 thread 1: ‘/oradata/ora10g/redo03.log‘
无法删除日志组6,是因为它是当前使用的日志文件。当然了,即使不是当前日志也无法删除,因为同样要遵循至少剩余2组日志的必要条件
SQL> alter database add logfile group 1 ‘/oradata/ora10g/redo01.log‘ size 50m;
alter database add logfile group 1 ‘/oradata/ora10g/redo01.log‘ size 50m
*
ERROR at line 1:
ORA-00301: error in adding log file ‘/oradata/ora10g/redo01.log‘ - file cannot
be created
ORA-27038: created file already exists
Additional information: 1
由于只是从控制文件中删除,而在OS物理级别该文件依然存在,所以提示无法创建
SQL> !
[oracle@bak ~]$ ll /oradata/ora10g
total 1349168
-rw-r----- 1 oracle oinstall 7389184 Oct 12 19:55 control01.ctl
-rw-r----- 1 oracle oinstall 7389184 Oct 12 19:55 control02.ctl
-rw-r----- 1 oracle oinstall 7389184 Oct 12 19:55 control03.ctl
-rw-r----- 1 oracle oinstall 104865792 Oct 12 19:49 example01.dbf
-rw-r----- 1 oracle oinstall 52429312 Oct 12 19:36 redo01.log
-rw-r----- 1 oracle oinstall 52429312 Oct 12 19:36 redo02.log
-rw-r----- 1 oracle oinstall 52429312 Oct 12 19:49 redo03.log
-rw-r----- 1 oracle oinstall 283123712 Oct 12 19:49 sysaux01.dbf
-rw-r----- 1 oracle oinstall 587210752 Oct 12 19:49 system01.dbf
-rw-r----- 1 oracle oinstall 173023232 Oct 12 19:49 undotbs01.dbf
-rw-r----- 1 oracle oinstall 31465472 Oct 12 19:49 users01.dbf
-rw-r----- 1 oracle oinstall 20979712 Oct 12 19:49 zlm01.dbf
[oracle@bak ~]$ rm -f /oradata/ora10g/redo01.log
[oracle@bak ~]$ exit
exit
SQL> alter database add logfile group 1 ‘/oradata/ora10g/redo01.log‘ size 50m;
Database altered.
先在OS上物理删除日志组1对应的文件redo01.log,再重新添加,添加时指定新的组号group 1
SQL> alter database drop logfile ‘/oradata/ora10g/redo02.log‘;
Database altered.
添加完日志组1,就可以删除日志组2,因为只要满足仍然有2组日志这个条件即可
SQL> !
[oracle@bak ~]$ rm -f /oradata/ora10g/redo02.log
[oracle@bak ~]$ exit
exit
SQL> alter database add logfile group 2 ‘/oradata/ora10g/redo02.log‘ size 50m;
Database altered.
同样地,继续完成日志组2的更新,先物理删除文件,再指定组名添加
由于日志组6是当前日志,因此不能直接删除,需要先切换日志
SQL> alter system switch logfile;
alter system switch logfile
*
ERROR at line 1:
ORA-01109: database not open
SQL> alter database open;
Database altered.
SQL> select group#,sequence#,(bytes/1024/1024) "SIZE(MB)",archived,status from v$log;
GROUP# SEQUENCE# SIZE(MB) ARC STATUS
---------- ---------- ---------- --- ----------------
1 0 50 YES UNUSED
2 0 50 YES UNUSED
6 1 50 NO CURRENT
SQL> alter system switch logfile;
System altered.
SQL> select group#,sequence#,(bytes/1024/1024) "SIZE(MB)",archived,status from v$log;
GROUP# SEQUENCE# SIZE(MB) ARC STATUS
---------- ---------- ---------- --- ----------------
1 2 50 NO CURRENT
2 0 50 YES UNUSED
6 1 50 NO ACTIVE
切换一次日志后,group 1成为当前日志组,现在可以删除日志组3了
SQL> alter database drop logfile ‘/oradata/ora10g/redo03.log‘;
Database altered.
SQL> !
[oracle@bak ~]$ rm -f /oradata/ora10g/redo03.log
[oracle@bak ~]$ exit
exit
SQL> alter database add logfile group 3 ‘/oradata/ora10g/redo03.log‘ size 50m;
Database altered.
SQL> select group#,sequence#,(bytes/1024/1024) "SIZE(MB)",archived,status from v$log;
GROUP# SEQUENCE# SIZE(MB) ARC STATUS
---------- ---------- ---------- --- ----------------
1 2 50 NO CURRENT
2 0 50 YES UNUSED
3 0 50 YES UNUSED
现在,已经把日志组编号调整到正常状态了,当然了,如果不改也不会影响数据库的正常使用