备份数据库时会自动备份参数文件和控制文件。实际上,只要备份system表空间就会自动备份参数文件和控制文件。
命令以下:
RMAN> backup as compressed backupset database format '/home/oracle/rmanbak/database_%d_%I_%s_%p_%T';
Starting backup at 2020-04-10 08:06:27
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/usr/local/oradata/orcl/system01.dbf
input datafile file number=00005 name=/usr/local/oradata/orcl/data01.dbf
channel ORA_DISK_1: starting piece 1 at 2020-04-10 08:06:27
channel ORA_DISK_2: starting compressed full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00002 name=/usr/local/oradata/orcl/sysaux01.dbf
input datafile file number=00003 name=/usr/local/oradata/orcl/undotbs01.dbf
input datafile file number=00004 name=/usr/local/oradata/orcl/users01.dbf
channel ORA_DISK_2: starting piece 1 at 2020-04-10 08:06:27
channel ORA_DISK_2: finished piece 1 at 2020-04-10 08:07:02
piece handle=/home/oracle/rmanbak/database_ORCL_1559168802_91_1_20200410 tag=TAG20200410T080627 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_2: starting compressed full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_2: starting piece 1 at 2020-04-10 08:07:03
channel ORA_DISK_2: finished piece 1 at 2020-04-10 08:07:04
piece handle=/home/oracle/rmanbak/database_ORCL_1559168802_92_1_20200410 tag=TAG20200410T080627 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_2: starting compressed full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_2: starting piece 1 at 2020-04-10 08:07:05
channel ORA_DISK_2: finished piece 1 at 2020-04-10 08:07:06
piece handle=/home/oracle/rmanbak/database_ORCL_1559168802_93_1_20200410 tag=TAG20200410T080627 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: finished piece 1 at 2020-04-10 08:07:20
piece handle=/home/oracle/rmanbak/database_ORCL_1559168802_90_1_20200410 tag=TAG20200410T080627 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:53
Finished backup at 2020-04-10 08:07:20
可以看到,在备份数据库的时候自动备份了参数文件和控制文件。结果如下:
RMAN> list backup of spfile;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
73 Full 80.00K DISK 00:00:00 2020-04-10 08:07:05
BP Key: 105 Status: AVAILABLE Compressed: YES Tag: TAG20200410T080627
Piece Name: /home/oracle/rmanbak/database_ORCL_1559168802_93_1_20200410
SPFILE Included: Modification time: 2020-04-10 07:43:08
SPFILE db_unique_name: ORCL
RMAN> list backup of controlfile;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
72 Full 1.09M DISK 00:00:02 2020-04-10 08:07:04
BP Key: 104 Status: AVAILABLE Compressed: YES Tag: TAG20200410T080627
Piece Name: /home/oracle/rmanbak/database_ORCL_1559168802_92_1_20200410
Control File Included: Ckp SCN: 1810457 Ckp time: 2020-04-10 08:07:02
RMAN> list backup of database;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
71 Full 76.34M DISK 00:00:29 2020-04-10 08:06:56
BP Key: 103 Status: AVAILABLE Compressed: YES Tag: TAG20200410T080627
Piece Name: /home/oracle/rmanbak/database_ORCL_1559168802_91_1_20200410
List of Datafiles in backup set 71
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
2 Full 1810439 2020-04-10 08:06:27 /usr/local/oradata/orcl/sysaux01.dbf
3 Full 1810439 2020-04-10 08:06:27 /usr/local/oradata/orcl/undotbs01.dbf
4 Full 1810439 2020-04-10 08:06:27 /usr/local/oradata/orcl/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
74 Full 180.47M DISK 00:00:46 2020-04-10 08:07:13
BP Key: 106 Status: AVAILABLE Compressed: YES Tag: TAG20200410T080627
Piece Name: /home/oracle/rmanbak/database_ORCL_1559168802_90_1_20200410
List of Datafiles in backup set 74
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
1 Full 1810438 2020-04-10 08:06:27 /usr/local/oradata/orcl/system01.dbf
5 Full 1810438 2020-04-10 08:06:27 /usr/local/oradata/orcl/data01.dbf
RMAN> backup archivelog all delete input format '/home/oracle/rmanbak/archivelog_%d_%I_%s_%p_%T';
Starting backup at 2020-04-10 08:12:44
current log archived
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=225 STAMP=1037306364
input archived log thread=1 sequence=14 RECID=224 STAMP=1037306364
channel ORA_DISK_1: starting piece 1 at 2020-04-10 08:12:44
channel ORA_DISK_2: starting archived log backup set
channel ORA_DISK_2: specifying archived log(s) in backup set
input archived log thread=1 sequence=15 RECID=223 STAMP=1037306361
input archived log thread=1 sequence=16 RECID=226 STAMP=1037306366
input archived log thread=1 sequence=17 RECID=227 STAMP=1037345883
input archived log thread=1 sequence=18 RECID=228 STAMP=1037345913
input archived log thread=1 sequence=19 RECID=229 STAMP=1037345941
input archived log thread=1 sequence=20 RECID=230 STAMP=1037346135
channel ORA_DISK_2: starting piece 1 at 2020-04-10 08:12:44
channel ORA_DISK_1: finished piece 1 at 2020-04-10 08:12:47
piece handle=/home/oracle/rmanbak/archivelog_ORCL_1559168802_97_1_20200410 tag=TAG20200410T081244 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/home/oracle/archive_logs/1_13_1037292356.dbf RECID=225 STAMP=1037306364
archived log file name=/home/oracle/archive_logs/1_14_1037292356.dbf RECID=224 STAMP=1037306364
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=21 RECID=231 STAMP=1037346231
input archived log thread=1 sequence=22 RECID=232 STAMP=1037347902
input archived log thread=1 sequence=23 RECID=233 STAMP=1037347964
channel ORA_DISK_1: starting piece 1 at 2020-04-10 08:12:48
channel ORA_DISK_2: finished piece 1 at 2020-04-10 08:12:48
piece handle=/home/oracle/rmanbak/archivelog_ORCL_1559168802_98_1_20200410 tag=TAG20200410T081244 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:04
channel ORA_DISK_2: deleting archived log(s)
archived log file name=/home/oracle/archive_logs/1_15_1037292356.dbf RECID=223 STAMP=1037306361
archived log file name=/home/oracle/archive_logs/1_16_1037292356.dbf RECID=226 STAMP=1037306366
archived log file name=/home/oracle/archive_logs/1_17_1037292356.dbf RECID=227 STAMP=1037345883
archived log file name=/home/oracle/archive_logs/1_18_1037292356.dbf RECID=228 STAMP=1037345913
archived log file name=/home/oracle/archive_logs/1_19_1037292356.dbf RECID=229 STAMP=1037345941
archived log file name=/home/oracle/archive_logs/1_20_1037292356.dbf RECID=230 STAMP=1037346135
channel ORA_DISK_1: finished piece 1 at 2020-04-10 08:12:48
piece handle=/home/oracle/rmanbak/archivelog_ORCL_1559168802_99_1_20200410 tag=TAG20200410T081244 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:00
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/home/oracle/archive_logs/1_21_1037292356.dbf RECID=231 STAMP=1037346231
archived log file name=/home/oracle/archive_logs/1_22_1037292356.dbf RECID=232 STAMP=1037347902
archived log file name=/home/oracle/archive_logs/1_23_1037292356.dbf RECID=233 STAMP=1037347964
Finished backup at 2020-04-10 08:12:48
连接scott用户,在t2表中添加数据:
SQL> select * from t2;
ID
----------
1
2
Elapsed: 00:00:00.10
SQL> insert into t2 values(11);
1 row created.
Elapsed: 00:00:00.03
SQL> commit;
Commit complete.
Elapsed: 00:00:00.00
SQL> select * from t2;
ID
----------
1
2
11
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /usr/local/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora
SQL> host rm /usr/local/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora
SQL> select name from v$datafile;
NAME
---------------------------------------------------------------------------------------
/usr/local/oradata/orcl/system01.dbf
/usr/local/oradata/orcl/sysaux01.dbf
/usr/local/oradata/orcl/undotbs01.dbf
/usr/local/oradata/orcl/users01.dbf
/usr/local/oradata/orcl/data01.dbf
Elapsed: 00:00:00.08
SQL>
SQL> host rm /usr/local/oradata/orcl/*.dbf
SQL> select name from v$controlfile;
NAME
----------------------------------------------------------------------------------
/usr/local/oradata/orcl/control01.ctl
/usr/local/oracle/flash_recovery_area/orcl/control02.ctl
Elapsed: 00:00:00.01
SQL> host rm /usr/local/oradata/orcl/control01.ctl
SQL> host rm /usr/local/oracle/flash_recovery_area/orcl/control02.ctl
此时可以发现,已经无法启动实例,应为参数文件丢失导致数据库实例无法启动。
SQL> startup force;
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/usr/local/oracle/product/11.2.0/db_1/dbs/initorcl.ora'
RMAN> startup nomount;
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/usr/local/oracle/product/11.2.0/db_1/dbs/initorcl.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area 158662656 bytes
Fixed Size 2211448 bytes
Variable Size 92275080 bytes
Database Buffers 58720256 bytes
Redo Buffers 5455872 bytes
RMAN> restore spfile from '/home/oracle/rmanbak/database_ORCL_1559168802_93_1_20200410';
Starting restore at 2020-04-10 08:25:04
using channel ORA_DISK_1
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /home/oracle/rmanbak/database_ORCL_1559168802_93_1_20200410
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2020-04-10 08:25:05
RMAN> shutdown immediate
Oracle instance shut down
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1068937216 bytes
Fixed Size 2220200 bytes
Variable Size 482348888 bytes
Database Buffers 578813952 bytes
Redo Buffers 5554176 bytes
RMAN> restore controlfile from '/home/oracle/rmanbak/database_ORCL_1559168802_92_1_20200410';
Starting restore at 2020-04-10 08:29:14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/usr/local/oradata/orcl/control01.ctl
output file name=/usr/local/oracle/flash_recovery_area/orcl/control02.ctl
Finished restore at 2020-04-10 08:29:15
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
在还原数据库时出现以下错误,提示找不到系统表空间和data01表空间对应的文件:
RMAN> restore database;
Starting restore at 2020-04-10 08:30:31
Starting implicit crosscheck backup at 2020-04-10 08:30:31
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=135 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 2020-04-10 08:30:32
Starting implicit crosscheck copy at 2020-04-10 08:30:32
using channel ORA_DISK_1
using channel ORA_DISK_2
Finished implicit crosscheck copy at 2020-04-10 08:30:32
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
using channel ORA_DISK_2
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/10/2020 08:30:32
RMAN-06026: some targets not found - aborting restore
RMAN-06023: no backup or copy of datafile 5 found to restore
RMAN-06023: no backup or copy of datafile 1 found to restore
发现可能是恢复参数文件和控制文件之后,RMAN目录中的信息丢失造成的。通过list backup命令检查发现,参数文件、控制文件、归档日志文件的备份信息也丢失了。
重新在RMAN目录中注册备份信息:
RMAN> catalog start with '/home/oracle/rmanbak/database_ORCL_1559168802_90_1_20200410';
searching for all files that match the pattern /home/oracle/rmanbak/database_ORCL_1559168802_90_1_20200410
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/rmanbak/database_ORCL_1559168802_90_1_20200410
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /home/oracle/rmanbak/database_ORCL_1559168802_90_1_20200410
RMAN> list backup of database;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
71 Full 76.34M DISK 00:00:29 2020-04-10 08:06:56
BP Key: 103 Status: AVAILABLE Compressed: YES Tag: TAG20200410T080627
Piece Name: /home/oracle/rmanbak/database_ORCL_1559168802_91_1_20200410
List of Datafiles in backup set 71
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
2 Full 1810439 2020-04-10 08:06:27 /usr/local/oradata/orcl/sysaux01.dbf
3 Full 1810439 2020-04-10 08:06:27 /usr/local/oradata/orcl/undotbs01.dbf
4 Full 1810439 2020-04-10 08:06:27 /usr/local/oradata/orcl/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
72 Full 180.47M DISK 00:00:00 2020-04-10 08:06:27
BP Key: 104 Status: AVAILABLE Compressed: YES Tag: TAG20200410T080627
Piece Name: /home/oracle/rmanbak/database_ORCL_1559168802_90_1_20200410
List of Datafiles in backup set 72
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- ------------------- ----
1 Full 1810438 2020-04-10 08:06:27 /usr/local/oradata/orcl/system01.dbf
5 Full 1810438 2020-04-10 08:06:27 /usr/local/oradata/orcl/data01.dbf
RMAN> catalog start with '/home/oracle/rmanbak/archivelog_ORCL_1559168802_97_1_20200410';
searching for all files that match the pattern /home/oracle/rmanbak/archivelog_ORCL_1559168802_97_1_20200410
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_97_1_20200410
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_97_1_20200410
RMAN> catalog start with '/home/oracle/rmanbak/archivelog_ORCL_1559168802_98_1_20200410';
searching for all files that match the pattern /home/oracle/rmanbak/archivelog_ORCL_1559168802_98_1_20200410
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_98_1_20200410
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_98_1_20200410
RMAN> catalog start with '/home/oracle/rmanbak/archivelog_ORCL_1559168802_99_1_20200410';
searching for all files that match the pattern /home/oracle/rmanbak/archivelog_ORCL_1559168802_99_1_20200410
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_99_1_20200410
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_99_1_20200410
RMAN>
RMAN>
RMAN>
RMAN> list backup of archivelog all;
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
73 49.98M DISK 00:00:00 2020-04-10 08:12:44
BP Key: 105 Status: AVAILABLE Compressed: NO Tag: TAG20200410T081244
Piece Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_97_1_20200410
List of Archived Logs in backup set 73
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- ------------------- ---------- ---------
1 13 1741661 2020-04-09 20:23:41 1742829 2020-04-09 20:30:10
1 14 1742829 2020-04-09 20:30:10 1743756 2020-04-09 20:30:52
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
74 10.50M DISK 00:00:00 2020-04-10 08:12:44
BP Key: 106 Status: AVAILABLE Compressed: NO Tag: TAG20200410T081244
Piece Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_98_1_20200410
List of Archived Logs in backup set 74
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- ------------------- ---------- ---------
1 15 1743756 2020-04-09 20:30:52 1743788 2020-04-09 20:32:04
1 16 1743788 2020-04-09 20:32:04 1763927 2020-04-09 20:39:26
1 17 1763927 2020-04-09 20:39:26 1768785 2020-04-10 07:38:03
1 18 1768785 2020-04-10 07:38:03 1768900 2020-04-10 07:38:32
1 19 1768900 2020-04-10 07:38:32 1769007 2020-04-10 07:39:01
1 20 1769007 2020-04-10 07:39:01 1789067 2020-04-10 07:42:15
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
75 1.08M DISK 00:00:00 2020-04-10 08:12:48
BP Key: 107 Status: AVAILABLE Compressed: NO Tag: TAG20200410T081244
Piece Name: /home/oracle/rmanbak/archivelog_ORCL_1559168802_99_1_20200410
List of Archived Logs in backup set 75
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- ------------------- ---------- ---------
1 21 1789067 2020-04-10 07:42:15 1809216 2020-04-10 07:43:51
1 22 1809216 2020-04-10 07:43:51 1810595 2020-04-10 08:11:42
1 23 1810595 2020-04-10 08:11:42 1810648 2020-04-10 08:12:44
RMAN> restore database;
Starting restore at 2020-04-10 08:46:00
using channel ORA_DISK_1
using channel ORA_DISK_2
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 00002 to /usr/local/oradata/orcl/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /usr/local/oradata/orcl/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /usr/local/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/database_ORCL_1559168802_91_1_20200410
channel ORA_DISK_2: starting datafile backup set restore
channel ORA_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_DISK_2: restoring datafile 00001 to /usr/local/oradata/orcl/system01.dbf
channel ORA_DISK_2: restoring datafile 00005 to /usr/local/oradata/orcl/data01.dbf
channel ORA_DISK_2: reading from backup piece /home/oracle/rmanbak/database_ORCL_1559168802_90_1_20200410
channel ORA_DISK_1: piece handle=/home/oracle/rmanbak/database_ORCL_1559168802_91_1_20200410 tag=TAG20200410T080627
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_DISK_2: piece handle=/home/oracle/rmanbak/database_ORCL_1559168802_90_1_20200410 tag=TAG20200410T080627
channel ORA_DISK_2: restored backup piece 1
channel ORA_DISK_2: restore complete, elapsed time: 00:01:05
Finished restore at 2020-04-10 08:47:06
RMAN> recover database;
Starting recover at 2020-04-10 08:47:31
using channel ORA_DISK_1
using channel ORA_DISK_2
starting media recovery
archived log for thread 1 with sequence 22 is already on disk as file /usr/local/oradata/orcl/redo01.log
archived log for thread 1 with sequence 23 is already on disk as file /usr/local/oradata/orcl/redo02.log
archived log for thread 1 with sequence 24 is already on disk as file /usr/local/oradata/orcl/redo03.log
archived log file name=/usr/local/oradata/orcl/redo01.log thread=1 sequence=22
archived log file name=/usr/local/oradata/orcl/redo02.log thread=1 sequence=23
archived log file name=/usr/local/oradata/orcl/redo03.log thread=1 sequence=24
media recovery complete, elapsed time: 00:00:01
Finished recover at 2020-04-10 08:47:33
RMAN> alter database open resetlogs;
database opened
SQL> conn scott/tiger
Connected.
SQL> select * from t2;
ID
----------
1
2
11