源库备份(A库)联机全备: 全库备份加控制文件及归档备份;(热备) run { backup database format '/home/oracle/BKdbfile_%d_%U_%T'; sql 'alter system archive log current'; #backup all archive logs BACKUP FORMAT '/home/oracle/BKarch_%d_%U_%T' ARCHIVELOG ALL DELETE INPUT; BACKUP CURRENT CONTROLFILE FORMAT '/home/oracle/conbak.%u'; } -本次只是全被数据库,没开自动控制文件备份,但是当数据库结构变化是,控制文件及spfile会自动备份 RMAN> backup database;
Starting backup at 11-DEC-17 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00004 name=/u01/app/oracle/oradata/DBdb/users01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/DBdb/undotbs01.dbf input datafile file number=00001 name=/u01/app/oracle/oradata/DBdb/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/DBdb/sysaux01.dbf input datafile file number=00005 name=/u01/app/oracle/oradata/DBdb/example01.dbf channel ORA_DISK_1: starting piece 1 at 11-DEC-17 channel ORA_DISK_1: finished piece 1 at 11-DEC-17 piece handle=/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_nnndf_TAG20171211T070728_f2vhkjlf_.bkp tag=TAG20171211T070728 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 11-DEC-17 channel ORA_DISK_1: finished piece 1 at 11-DEC-17 piece handle=/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp tag=TAG20171211T070728 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 11-DEC-17
startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initkill.ora'
starting Oracle instance without parameter file for retrieval of spfile Oracle instance started
4.恢复参数文件: RMAN> restore spfile to pfile '?/dbs/initkill.ora' from '/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp';
Starting restore at 2017-12-25 18:13:44 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 2017-12-25 18:13:46
--查看恢复的pfile文件; [oracle@testdb ~]$ cd $ORACLE_HOME/dbs [oracle@testdb dbs]$ ls hc_kill.dat initkill.ora init.ora [oracle@testdb dbs]$
SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 25 18:18:57 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> show parameter spfile;
NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string SQL> SQL> create spfile from pfile;
File created.
SQL> shutdown immediate; ORA-01507: database not mounted
Total System Global Area 835104768 bytes Fixed Size 2257840 bytes Variable Size 549456976 bytes Database Buffers 281018368 bytes Redo Buffers 2371584 bytes SQL> SQL> show parameter spfile;
NAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ spfile string /u01/app/oracle/product/11.2.0 /dbhome_1/dbs/spfilekill.ora
6..还原控制文件: 还原控制文件并启动到mount模式
[oracle@testdb ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Dec 25 18:21:51 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: DBDB (not mounted)
RMAN> restore controlfile from '/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp';
Starting restore at 2017-12-25 18:22:13 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=20 device type=DISK
7.还原数据文件(即set newname): RMAN> run{ set newname for datafile 1 to '/u01/app/oracle/oradata/kill/system01.dbf'; set newname for datafile 2 to '/u01/app/oracle/oradata/kill/sysaux01.dbf'; set newname for datafile 3 to '/u01/app/oracle/oradata/kill/undotbs01.dbf'; set newname for datafile 4 to '/u01/app/oracle/oradata/kill/users01.dbf'; set newname for datafile 5 to '/u01/app/oracle/oradata/kill/example01.dbf'; restore database; switch datafile all; recover database; } executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 2017-12-25 17:12:18 Starting implicit crosscheck backup at 2017-12-25 17:12:18 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=1 device type=DISK Crosschecked 1 objects Finished implicit crosscheck backup at 2017-12-25 17:12:19
Starting implicit crosscheck copy at 2017-12-25 17:12:19 using channel ORA_DISK_1 Finished implicit crosscheck copy at 2017-12-25 17:12:19
searching for all files in the recovery area cataloging files... cataloging done
List of Cataloged Files ======================= File Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_12_25/o1_mf_ncsnf_TAG20171225T125632_f411cfmz_.bkp
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/kill/system01.dbf channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/kill/undotbs01.dbf channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/kill/sysaux01.dbf channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/kill/users01.dbf channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/kill/example01.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_12_25/o1_mf_nnndf_TAG20171225T125632_f4118147_.bkp channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_12_25/o1_mf_nnndf_TAG20171225T125632_f4118147_.bkp tag=TAG20171225T125632 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:01:45 Finished restore at 2017-12-25 17:14:05
RMAN> run{ set until scn 5456222; restore database; switch datafile all; recover database; } executing command: SET until clause
Starting restore at 2017-12-25 18:29:57 using channel ORA_DISK_1
skipping datafile 1; already restored to file /u01/app/oracle/oradata/kill/system01.dbf skipping datafile 2; already restored to file /u01/app/oracle/oradata/kill/sysaux01.dbf skipping datafile 3; already restored to file /u01/app/oracle/oradata/kill/undotbs01.dbf skipping datafile 4; already restored to file /u01/app/oracle/oradata/kill/users01.dbf skipping datafile 5; already restored to file /u01/app/oracle/oradata/kill/example01.dbf restore not done; all files read only, offline, or already restored Finished restore at 2017-12-25 18:29:58
Starting recover at 2017-12-25 18:29:58 using channel ORA_DISK_1
starting media recovery media recovery complete, elapsed time: 00:00:00
Finished recover at 2017-12-25 18:29:58
RMAN> 8.Resetlogs方式打开数据库: RMAN> alter database open resetlogs;
RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of alter db command at 12/25/2017 18:31:24 ORA-00344: unable to re-create online log '/u01/app/oracle/oradata/DBdb/redo01.log' ORA-27040: file create error, unable to create file Linux-x86_64 Error: 2: No such file or directory Additional information: 1
报错因为此时数据库SID为kill,不一致导致。
--查看源库有三个日志组,需转换路径: SQL> select member from v$logfile;
MEMBER -------------------------------------------------------------------------------- /u01/app/oracle/oradata/DBdb/redo03.log /u01/app/oracle/oradata/DBdb/redo02.log /u01/app/oracle/oradata/DBdb/redo01.log
--开始转换: run{ sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo01.log'' to ''/u01/app/oracle/oradata/kill/redo01.log'' "; sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo02.log'' to ''/u01/app/oracle/oradata/kill/redo02.log'' "; sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo03.log'' to ''/u01/app/oracle/oradata/kill/redo03.log'' "; }
sql statement: alter database rename file ''/u01/app/oracle/oradata/DBdb/redo01.log'' to ''/u01/app/oracle/oradata/kill/redo01.log'' sql statement: alter database rename file ''/u01/app/oracle/oradata/DBdb/redo02.log'' to ''/u01/app/oracle/oradata/kill/redo02.log'' sql statement: alter database rename file ''/u01/app/oracle/oradata/DBdb/redo03.log'' to ''/u01/app/oracle/oradata/kill/redo03.log''
RMAN>
--再次resetlogs方式启动数据库: RMAN> alter database open resetlogs;
RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of alter db command at 12/25/2017 18:38:39 ORA-00392: log 1 of thread 1 is being cleared, operation not allowed ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/kill/redo01.log'
RMAN>
--解决:手工clear然后再Open resetlogs RMAN> sql 'alter database clear logfile group 1';
sql statement: alter database clear logfile group 1
SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 25 18:42:09 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select status from v$instance;
STATUS ------------ OPEN
SQL> SQL> select file_name from dba_temp_files; select file_name from dba_temp_files * ERROR at line 1: ORA-01157: cannot identify/lock data file 201 - see DBWR trace file ORA-01110: data file 201: '/u01/app/oracle/oradata/DBdb/temp01.dbf'