User Managed Hot Backup and Recovery of lost of data file

Example of User Managed Hot Backup:
-----------------------------------------

1)Determine which data file you need to backup.
SQL> select file_name ,tablespace_name from dba_data_files
2 /

FILE_NAME TABLESPACE_NAME
---------------------------------------- ------------------------------
/oradata2/7.dbf USERS
/oradata2/data1/dbase/users01.dbf USERS
/oradata2/data1/dbase/sysaux01.dbf SYSAUX
/oradata2/data1/dbase/undotbs01.dbf UNDOTBS1
/oradata2/data1/dbase/system01.dbf SYSTEM
/oradata2/6.dbf USERS
6 rows selected.

2)Make the tablespace in backup mode one by one and copy the associated datafile to backup location.
SQL> ALTER TABLESPACE USERS BEGIN BACKUP;

Tablespace altered.

SQL> !cp /oradata2/data1/dbase/users01.dbf /oradata2/shaik

SQL> !cp /oradata2/7.dbf /oradata2/shaik

SQL> ALTER TABLESPACE USERS END BACKUP;

Tablespace altered.

SQL> ALTER TABLESPACE SYSAUX BEGIN BACKUP;

Tablespace altered.

SQL> !cp /oradata2/data1/dbase/sysaux01.dbf /oradata2/shaik

SQL> ALTER TABLESPACE SYSAUX END BACKUP;

Tablespace altered.

SQL> ALTER TABLESPACE UNDOTBS1 BEGIN BACKUP;

Tablespace altered.

SQL> !cp /oradata2/data1/dbase/undotbs01.dbf /oradata2/shaik

SQL> ALTER TABLESPACE UNDOTBS1 END BACKUP;

Tablespace altered.

SQL> ALTER TABLESPACE SYSTEM BEGIN BACKUP;

Tablespace altered.

SQL> !cp /oradata2/data1/dbase/system01.dbf /oradata2/shaik

SQL> ALTER TABLESPACE SYSTEM END BACKUP;

Tablespace altered.

SQL> ALTER TABLESPACE USERS BEGIN BACKUP;

Tablespace altered.

SQL> !cp /oradata2/6.dbf /oradata2/shaik

SQL> ALTER TABLESPACE USERS END BACKUP;

Tablespace altered.

3)Take a backup of your control file also.
SQL> ALTER DATABASE BACKUP CONTROLFILE TO '/oradata2/shaik/control.ctl';
Database altered.


Now, I have taken backup.With this backup I will work for next recovery purpose. In this example I will show if someone has accidentally drop one datafile what will be my procedure.

Suppose someone accidentally two files.

SQL> !rm /oradata2/data1/dbase/users01.dbf
SQL> !rm /oradata2/6.dbf

Whenever you want to do any operation it will raise error like following,

SQL> alter tablespace users offline;
alter tablespace users offline
*
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/oradata2/data1/dbase/users01.dbf'
ORA-27041: unable to open file
Solaris-AMD64 Error: 2: No such file or directory
Additional information: 3


User Managed Recovery of Datafile when your database is online (Archive Log Mode)
---------------------------------------------------------------------------
1)Make the affected tablespace offline.
SQL> ALTER TABLESPACE USERS OFFLINE IMMEDIATE;
Tablespace altered.

2)Copy the lost datafile from backup into the location of the datafile.

SQL> !cp /oradata2/shaik/users01.dbf /oradata2/data1/dbase/
SQL> !cp /oradata2/shaik/6.dbf /oradata2

3)Recover the tablespace.
SQL> RECOVER TABLESPACE USERS;
Media recovery complete.

4)Make the Tablespace online.
SQL> ALTER TABLESPACE USERS ONLINE;
Tablespace altered.

While database is offline and can't start it will show following message.

SQL> !rm /oradata2/data1/dbase/users01.dbf

SQL> startup
ORACLE instance started.

Total System Global Area 167772160 bytes
Fixed Size 2019288 bytes
Variable Size 100663336 bytes
Database Buffers 58720256 bytes
Redo Buffers 6369280 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/oradata2/data1/dbase/users01.dbf'

1)In order to see which files need media recovery issue,

SQL> SELECT r.FILE# AS df#, d.NAME AS df_name, t.NAME AS tbsp_name,
d.STATUS, r.ERROR, r.CHANGE#, r.TIME
FROM V$RECOVER_FILE r, V$DATAFILE d, V$TABLESPACE t
WHERE t.TS# = d.TS#
AND d.FILE# = r.FILE#
; 2 3 4 5 6

DF# DF_NAME TBSP_NA STATUS ERROR CHANGE#
---- ----------------------------------- ------- ------- ---------- ---------
4 /oradata2/data1/dbase/users01.dbf USERS ONLINE FILE NOT 0
FOUND

2)Copy the lost file from backup to destination.

SQL> !cp /oradata2/shaik/users01.dbf /oradata2/data1/dbase/users01.dbf

3)Recover the file and open the database.

SQL> RECOVER DATAFILE 4;
Media recovery complete.
SQL> ALTER DATABASE OPEN;

Database altered.


Note: If the location is damaged permamnent to make datafile in another location use,
SQL>ALTER DATABASE RENAME FILE '/oradata2/data1/dbase/users01.dbf' TO
'/disk2/users01.dbf';

If you do not have a backup of a specific datafile but you have archived log since the datafile creation then you can recover that datafile by creating an empty file by ALTER DATABASE CREATE DATAFILE and then simply perform recovery of the datafile.

Comments

Popular posts from this blog

ORA-00923: FROM keyword not found where expected

How to make partitioning in Oracle more Quickly

Copy files between Unix and Windows with rcp