一. Oracle用户管理备份介绍
Oracle物理恢复就是在Oracle服务器由不定的因素造成崩溃;这时需要根据备份文件进行Oracle恢复。根据恢复状态而分:恢复可分为完全恢复和不完全恢复。区别在于是否恢复到最新的时间点。
三. Oracle冷备份
数据库在关闭状态下完成所有物理系统文件拷贝的过程,也称脱机备份。场景适合于非归档模式下,数据库处于一致性状态。
3.1 备份操作原理
set feedback off set heading off set verify off set trimspool off set pagesize 0 set linesize 200 define dir = '/home/oracle/cool' define script = '/home/oracle/cool/sql/coolbak.sql' spool &script select 'ho cp ' || name || ' &dir' from v$controlfile union all select 'ho cp ' || name || ' &dir' from v$datafile union all select 'ho cp ' || member || ' &dir' from v$logfile union all select 'ho cp ' || name || ' &dir' from v$tempfile / create pfile = '&dir/initorcl.ora' from spfile; ho cp /u01/app/oracle/dbs/orapwora235 &dir spool off shutdown immediate start &script ho rm &script startup
四. Oracle热备份
Oracle 热备份是指数据库处于open状态下,对数据库的数据文件、控制文件、参数文件、密码文件等进行一系列备份操作;设置归档模式
archive log list alter system set log_archive_dest_1 = 'LOCATION=/data/arch' scope = spfile; shutdown immediate; startup mount alter database archivelog; alter database open;
- 热备的过程
- 基于数据库的热备
- 基于表空间的热备
set feedback off set heading off set verify off set trimspool off set pagesize 0 set linesize 200 define dir = '/home/oracle/hotbak' define script = '/tmp/hotbak.sql' spool &script select 'ho cp ' ||name|| ' &dir' from v$datafile; spool off alter database begin backup; start &script alter database end backup; alter database backup controlfile to '&dir/controlbak.ctl'; create pfile = '&dir/initorcl.ora' from spfile;
五.Oracle用户管理恢复
Oracle数据库恢复;分为 数据还原 和 数据恢复 两步。
首先使用备份还原数据,然后再应用归档日志、重做日志的恢复方式称为介质恢复。介质恢复能将一个经过还原的数据更新到当前的时间点或之前的某个时间点。通常介质恢复这个术语专指对数据文件进行恢复的过程。数据块的介质恢复指数据文件中的个别数据块出现错误时进行的特殊恢复操作。
介质恢复通常又可以分为 完全恢复 和 不完全恢复
对整个数据库实现完全恢复的步骤
对表空间及数据文件实现完全恢复的步骤
场景
SQL> create table t_lottu as select level as id from dual connect by level <= 5; Table created.
- 模拟故障;删除数据文件lottu01.dbf,system01.dbf。
[oracle@oracle235 ~]$ rm /u01/app/oradata/ora235/system01.dbf [oracle@oracle235 ~]$ rm /data/oracle/data/lottu01.dbf
- 这时数据库虽然可以连;但是执行命令会报某个数据文件不存在。
SQL> conn lottu/li0924 Connected. SQL> insert into t_lottu values (6); insert into t_lottu values (6) * ERROR at line 1: ORA-01116: error in opening database file 5 ORA-01110: data file 5: '/data/oracle/data/lottu01.dbf' ORA-27041: unable to open file Linux-x86_64 Error: 2: No such file or directory Additional information: 3
- 重启数据库;会报1号数据文件不存在?因为我们前面删除了system01.dbf
SQL> shutdown abort; ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 780824576 bytes Fixed Size 2257312 bytes Variable Size 511708768 bytes Database Buffers 264241152 bytes Redo Buffers 2617344 bytes Database mounted. ORA-01157: cannot identify/lock data file 1 - see DBWR trace file ORA-01110: data file 1: '/u01/app/oradata/ora235/system01.dbf'
- 查看哪些数据文件需要恢复?
SQL> select FILE#,ONLINE_STATUS from v$recover_file; FILE# ONLINE_ ---------- ------- 1 ONLINE 5 ONLINE
- 数据还原;将备份好的文件拷贝到对应的目录
[oracle@oracle235 hotbak]$ cp system01.dbf /u01/app/oradata/ora235 [oracle@oracle235 hotbak]$ cp lottu01.dbf /data/oracle/data
- 数据恢复;并打开数据库。验证数据恢复情况。
SQL> recover datafile 1,5; Media recovery complete. SQL> alter database open; Database altered. SQL> conn lottu/li0924 Connected. SQL> select * from t_lottu; ID ---------- 1 2 3 4 5
5.2 模拟不完全恢复-PITR
场景
SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual; TO_CHAR(SYSDATE,'YY ------------------- 2018-08-08 00:11:46 SQL> drop table t_lottu; Table dropped.
- 关闭数据库
SQL> shutdown abort; ORACLE instance shut down.
- 用备份中的数据文件替换数据库中数据文件
[oracle@oracle235 ora235]$ rm *.dbf [oracle@oracle235 ora235]$ rm /data/oracle/data/lottu01.dbf [oracle@oracle235 ora235]$ cd /home/oracle/hotbak/ [oracle@oracle235 hotbak]$ cp *.dbf /u01/app/oradata/ora235 [oracle@oracle235 hotbak]$ mv /u01/app/oradata/ora235/lottu01.dbf /data/oracle/data/lottu01.dbf
- 数据恢复
SQL> startup mount ORACLE instance started. Total System Global Area 780824576 bytes Fixed Size 2257312 bytes Variable Size 511708768 bytes Database Buffers 264241152 bytes Redo Buffers 2617344 bytes Database mounted. SQL> recover database until time '2018-08-08 00:11:46'; Media recovery complete. 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; Database altered. SQL> conn lottu/li0924 Connected. SQL> select * from t_lottu; ID ---------- 1 2 3 4 5
若是模拟的场景;还可以采用TSPITR恢复也可以;但需要涉及rman。
- Oracle 冷备份
- Oracle 热备份