SYS@EMREP> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
1、检查需要备份的数据文件与控制文件
col name for a60
select name form v$datafile;
select name from v$controlfile;
select member from v$logfile;
tips:如果正常关闭数据库(如shutdown immediate),可以不备份online redo log,可以在需要的时候重新创建。但是在备份前由于某种错误导致实例异常终止,如果备份中没有包括联机重做日志文件,会再restore 还原数据库后无法打开数据库,因为不能执行必须的recover恢复。
tips:临时文件不需要做备份(即使临时文件受损,也总能够重新创建而不丢失数据)
select name from v$tempfile;
2```
、执行dbv检查坏块
在手工备份前,可以使用dbv命令检查datafile 是否有坏块,备份完后对备份也要做检查,对某个datafile做坏块检查。
dbv --在os目录下
dbv file=/u01/app/oracle/oradata/PROD/users01.dbf
3、查看数据库的归档模式,如果归档该为未归档
archive log list;
4`
、关闭数据库,备份数据文件,控制文件,重做日志文件。
在os目录下新建存储数据文件,控制文件,日志文件备份的文件夹。后关闭数据库执行备份。
tips:注意检查是否复制成功。
mkdir /u01/app/oracle/oradata/data_backup
mkdir /u01/app/oracle/oradata/control_backup
mkdir /u01/app/oracle/oradata/log_backup
shutdown immediate
cp /u01/app/oracle/oradata/EMREP/*.dbf /u01/app/oracle/oradata/backup_datafile
cp /u01/app/oracle/oradata/EMREP/*.ctl /u01/app/oracle/oradata/backup_controlfile
cp /u01/app/oracle/oradata/EMREP/*.log /u01/app/oracle/oradata/backup_logfile
5、打开数据库,创建测试表backup_test
startup;
create table backup_test as select * from dba_objects;
6、关闭数据库,转到文件目录下删除数据文件,控制文件
shutdown immediate;
rm *.dbf
rm *.ctl
7、将数据库启动到nomount模式下启动成功,启动到mount状态下失败(找不到控制文件)
SYS@EMREP> startup nomount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 536874064 bytes
Database Buffers 289406976 bytes
Redo Buffers 6565888 bytes
SYS@EMREP> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying control file, check alert log for more info
8、将备份的控制文件复制到原路径下,再启动数据库到open状态下后失败(缺少数据文件)
cp /u01/app/oracle/oradata/backup_controlfile/*.ctl /u01/app/oracle/oradata/EMREP
SYS@EMREP> alter database mount;
Database altered.
SYS@EMREP> select status from v$instance;
STATUS
------------
MOUNTED
SYS@EMREP> alter database open;
alter database open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/EMREP/system01.dbf'
9、将备份的数据文件复制到原路径下,再启动数据库到open状态。(失败,因为创建了测试表,导致文件变大以及日志文件的scn控制文件不同)
SYS@EMREP> alter database open;
alter database open
*
ERROR at line 1:
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/u01/app/oracle/oradata/EMREP/system01.dbf'
ORA-01200: actual file size of 82007 is smaller than correct size of 96000 blocks
10、进行介质恢复,原先创建表backup_test数据丢失。
SYS@EMREP> recover database until cancel;
Media recovery complete.
SYS@EMREP> alter database open resetlogs;
Database altered.
SYS@EMREP>
SYS@EMREP> select status from v$instance;
STATUS
------------
OPEN
SYS@EMREP> select count(1) from backup_test;
select count(1) from backup_test
*
ERROR at line 1:
ORA-00942: table or view does not exist