手动不完全恢复测试使用备份控制文件 备份数据库 SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/prod/system01.dbf /u01/app/oracle/oradata/prod/sysaux01.dbf /u01/app/oracle/oradata/prod/undotbs01.dbf /u01/app/oracle/oradata/prod/users01.dbf /u01/app/oracle/oradata/prod/test01.dbf SQL> alter database begin backup; Database altered. SQL> ! [[email protected] ~]$ cd $ORACLE_BASE/oradata [[email protected] oradata]$ ls prod prod_bk [[email protected] oradata]$ cp ./prod/*.dbf ./prod_bk/ [[email protected] oradata]$ exit exit SQL> alter database end backup; Database altered. SQL> alter database backup controlfile to ‘/u01/app/oracle/oradata/prod_bk/controlbk20150618.ctl‘; Database altered. 实验开始 SQL> conn scott/oracle Connected. SQL> create table test(id number); Table created. SQL> begin 2 for i in 1..100 loop 3 insert into test values( i); 4 end loop; 5 end; 6 / PL/SQL procedure successfully completed. SQL> commit; Commit complete. SQL> 查表在表空间 SQL> select table_name, tablespace_name from user_tables; TABLE_NAME TABLESPACE_NAME ------------------------------ ------------------------------ TEST TEST EMPLOYEE USERS REOVERTEST USERS SALGRADE USERS BONUS USERS EMP USERS DEPT USERS 7 rows selected. SQL> conn / as sysdba Connected. SQL> drop tablespace test including contents and datafiles; Tablespace dropped. SQL> /* 删除表空间操作会记录在日志文件中,查看日记文件记录如下: Sun Jun 14 06:28:55 2015 drop tablespace test including contents and datafiles Sun Jun 14 06:29:11 2015 Deleted file /u01/app/oracle/oradata/prod/test01.dbf Completed: drop tablespace test including contents and datafiles */ SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/prod/system01.dbf /u01/app/oracle/oradata/prod/sysaux01.dbf /u01/app/oracle/oradata/prod/undotbs01.dbf /u01/app/oracle/oradata/prod/users01.dbf SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 7839 KING PRESIDENT 17-NOV-81 5000 10 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7900 JAMES CLERK 7698 03-DEC-81 950 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10 14 rows selected. SQL> truncate table emp; Table truncated. SQL> select * from emp; no rows selected SQL> SQL> SQL> select * from test; select * from test * ERROR at line 1: ORA-00942: table or view does not exist SQL> 先在需要恢复查看test表,但是其所在表空间已经被删除,需要恢复,步骤如下: SQL> conn / as sysdba Connected. SQL> shutdown abort; ORACLE instance shut down. restore所有手工备份 SQL> ! [[email protected] ~]$ cd /u01/app/oracle/oradata/prod [[email protected] prod]$ ls control01.ctl redo01.log redo03.log system01.dbf temp101.dbf users01.dbf control02.ctl redo02.log sysaux01.dbf temp01.dbf undotbs01.dbf [[email protected] prod]$ rm -rf *.dbf [[email protected] prod]$ rm -rf *.ctl [[email protected] prod]$ cp ../prod_bk/*.dbf ./ [[email protected] prod]$ ls redo01.log redo02.log redo03.log sysaux01.dbf system01.dbf temp01.dbf temp101.dbf test01.dbf undotbs01.dbf users01.dbf [[email protected] prod]$ cp ../prod_bk/controlbk20150618.ctl ./control01.ctl [[email protected] prod]$ cp ../prod_bk/controlbk20150618.ctl ./control02.ctl [[email protected] prod]$ exit exit SQL> 到mount状态进行不完全恢复 SQL> startup mount; ORACLE instance started. Total System Global Area 534462464 bytes Fixed Size 2254952 bytes Variable Size 209717144 bytes Database Buffers 314572800 bytes Redo Buffers 7917568 bytes Database mounted. SQL> sho parameters nls_ NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ nls_calendar string nls_comp string BINARY nls_currency string nls_date_format string nls_date_language string nls_dual_currency string nls_iso_currency string nls_language string AMERICAN nls_length_semantics string BYTE nls_nchar_conv_excp string FALSE nls_numeric_characters string NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ nls_sort string nls_territory string AMERICA nls_time_format string nls_time_tz_format string nls_timestamp_format string nls_timestamp_tz_format string SQL> alter session set nls_date_format=‘yyyy-mm-dd hh24:mi:ss‘; Session altered. recover 数据库到删除表空间的时间点(根据告警日志文件) SQL> recover database until time ‘2015-06-14 06:28:55‘ using backup controlfile; ORA-00279: change 1213896 generated at 06/14/2015 06:18:49 needed for thread 1 ORA-00289: suggestion : /oracle/arch1/1_2_882339416.dbf ORA-00280: change 1213896 for thread 1 is in sequence #2 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} auto ORA-00308: cannot open archived log ‘/oracle/arch1/1_2_882339416.dbf‘ ORA-27037: unable to obtain file status Linux-x86_64 Error: 2: No such file or directory Additional information: 3 ORA-00308: cannot open archived log ‘/oracle/arch1/1_2_882339416.dbf‘ ORA-27037: unable to obtain file status Linux-x86_64 Error: 2: No such file or directory Additional information: 3 ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below ORA-01195: online backup of file 1 needs more recovery to be consistent ORA-01110: data file 1: ‘/u01/app/oracle/oradata/prod/system01.dbf‘ 找不到日志文件,实验中最后关库用的是shutdown abort,archived_log 为 SQL> select name from v$archived_log; NAME ------------------------------------------ /oracle/arch1/1_1_882332679.dbf /oracle/arch1/1_1_882332679.dbf /oracle/arch1/1_2_882332679.dbf /oracle/arch1/1_1_882339416.dbf 所以需要当前日志做恢复用,查看当前日志 SQL> select * from v$log; GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME ---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------- ------------ ------------------- 1 1 1 52428800 512 1 YES INACTIVE 1203589 2015-06-14 06:16:56 1213831 2015-06-14 06:18:43 3 1 0 52428800 512 1 YES UNUSED 0 0 2 1 2 52428800 512 1 NO CURRENT 1213831 2015-06-14 06:18:43 2.8147E+14 SQL> select group#, member from v$logfile; GROUP# MEMBER ---------- -------------------------------------------------- 3 /u01/app/oracle/oradata/prod/redo03.log 2 /u01/app/oracle/oradata/prod/redo02.log 1 /u01/app/oracle/oradata/prod/redo01.log 当前日志为2组 SQL> recover database until time ‘2015-06-14 06:28:55‘ using backup controlfile; ORA-00279: change 1213896 generated at 06/14/2015 06:18:49 needed for thread 1 ORA-00289: suggestion : /oracle/arch1/1_2_882339416.dbf ORA-00280: change 1213896 for thread 1 is in sequence #2 Specify log: {<RET>=suggested | filename | AUTO | CANCEL} /u01/app/oracle/oradata/prod/redo02.log Log applied. Media recovery complete. SQL> alter database open resetlogs; Database altered. SQL> select name from v$datafile; NAME --------------------------------------------------- /u01/app/oracle/oradata/prod/system01.dbf /u01/app/oracle/oradata/prod/sysaux01.dbf /u01/app/oracle/oradata/prod/undotbs01.dbf /u01/app/oracle/oradata/prod/users01.dbf /u01/app/oracle/oradata/prod/test01.dbf SQL> select count(*) from scott.test; COUNT(*) ---------- 100 SQL> select * from scott.emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- ------------------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20 7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30 7521 WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30 7566 JONES MANAGER 7839 1981-04-02 00:00:00 2975 20 7654 MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30 7698 BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30 7782 CLARK MANAGER 7839 1981-06-09 00:00:00 2450 10 7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20 7839 KING PRESIDENT 1981-11-17 00:00:00 5000 10 7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30 7876 ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- ------------------- ---------- ---------- ---------- 7900 JAMES CLERK 7698 1981-12-03 00:00:00 950 30 7902 FORD ANALYST 7566 1981-12-03 00:00:00 3000 20 7934 MILLER CLERK 7782 1982-01-23 00:00:00 1300 10 14 rows selected. 恢复成功,truncate表也恢复过来
时间: 2024-10-09 16:55:43