Pages

Monday, April 2, 2012

USER MANAGED BACKUP AND RECOVERY



User Managed Backup

Backup means taking copy of our database which is overcome for database failures and with that backup we can recover database whenever it crash. Here we have two types of backups are there, they are
·        Physical Backup
  1. Cold Backup (Consistent Backup)
 2.  Hot Backup (Inconsistent Backup)
·         Logical Backup
1.  Export / Import
2.  Expdp /Impdp (available on oracle10g onwards)
Here first we see about physical backup, later we discuss about logical backup
Physical Backup

Cold Backup: (Consistent Backup)

A cold (or off-line) backup is a backup performed while the database is off-line and unavailable to its users. Cold backups can be taken regardless if the database is in ARCHIVELOG or NOARCHIVELOG mode. It is easier to restore from off-line backups as no recovery (from archived logs) would be required to make the database consistent.
Why you say cold backup is consistent backup?
After shutdown the database we have taken the cold backup. During this time all datafile headers SCN are same. When we restore the cold backup, no redo is needed in case of recovery. We had taken backup datafile, logfile, controlfile, parameter file & password file.

Cold Backup Steps:

1.       Get the file path information using below query
Sql> Select name from v$datafile;
Sql> select member from v$logfile;
Sql> select name from v$controlfile;
2.      Taken the password file & parameter file backup ( Optional)
3.      Sql>Alter system switch logfile;
4.      Sql>Shutdown immediate;
5.      Copy all the data files /control files /log files using os command & placed in backup path(in any secure location)
6.      Startup the database ( sql> startup)

Hot Backup: (Inconsistent Backup)
A hot (or on-line) backup is a backup performed while the database is open and available for use (read and write activity). Except for Oracle exports, one can only do on-line backups when the database is ARCHIVELOG mode.
Why you say Hot backup is inconsistent backup?
While database running we have taken the hot backup. During this time backup tablespace datafile headers SCN are not same with another tablespace datafiles. When we restore the hot backup, redo is needed for recovery.
Hot Backup Steps:

1       First we have to check our database is in archive log mode or not
Sql > archive log list;
If database is in archive log then it shows archive log enable and location of archive log files, if not it shows archive log mode disable
If archive log mode is disable then we have to shutdown the database and enable the archive log mode using below commands
Sql>shutdown immediate;
Open parameter file of that database to edit the location of archive logs
$ Vi initTEST.ora
Log_archive_dest=’/Oracle/product/10.2.0/db_1/admin/arch’
Save and exit(:wq)
Sql>startup mount
Sql>alter database archivelog;
Sql>alter database open;
And check database is in archive log mode or not
Sql>archive log list;
2.       Now we can take the complete database backup or tablespace backup
Let us suppose we want to take online backup of USERS" tablespace. You can query the V$DATAFILE view to find out the name of datafiles associated with this tablespace. Let’s suppose the file is  ‘/u01/oradata/usr1.dbf’

Sql>alter tablespace USERS begin backup;
Sql> host cp /u01/oradata/usr1.dbf   /u02/backup
Sql>alter tablespace USERS end backup;
Sql>exit;

Similarly for complete database backup
Sql>alter database begin backup;
Copy datafiles, control files, redo logfiles, archive log files to secure location
After completion of copying
Sql>alter database end backup;
Sql>exit;

RECOVERING THE DATABASE IF IT IS RUNNING IN NOARCHIVELOG MODE

Option 1: When you don’t have a backup

If you have lost one datafile and if you don't have any backup and if the datafile does not contain important objects then, you can drop the damaged datafile and open the database. You will loose all information contained in the damaged datafile.
The following are the steps to drop a damaged datafile and open the database.

STEP 1: First take full backup of database for safety.
STEP 2: Start the sqlplus and give the following commands.

$sqlplus
Enter User: / as sysdba
SQL> STARTUP MOUNT
SQL> ALTER DATABASE DATAFILE ‘/u01/ica/usr1.dbf ‘offline drop;
SQL>alter database open;

Option 2: When you have the Backup

If the database is running in Noarchivelog mode and if you have a full backup. Then there are two options for you.
i . Either you can drop the damaged datafile, if it does not contain important information which you can afford to loose.
ii . Or you can restore from full backup. You will loose all the changes made to the database since last full backup.
To drop the damaged datafile follow the steps shown previously.
To restore from full database backup. Do the following.
STEP 1: Take a full backup of current database.
STEP 2: Restore from full database backup i.e. copy all the files from backup to their original locations.
Suppose the backup is in “/u2/oracle/backup" directory. Then do the following
$cp /u02/backup/* /u01/ica
This will copy all the files from backup directory to original destination. Also remember to copy the control files to all the mirrored locations.

RECOVERING FROM LOST OF CONTROL FILE


If you have lost the control file and if it is mirrored. Then simply copy the control file from mirrored location to the damaged location and open the database. If you have lost all the mirrored control files and all the datafiles and logfiles are intact. Then you can recreate a control file.
If you have already taken the backup of control file creation statement by giving this command. " ALTER DATABASE BACKUP CONTROLFILE TO TRACE; " and if you have not added any tablespace since then, just create the controlfile by executing the statement
Buf If you have added any new tablespace after generating create controlfile statement. Then you have to alter the script and include the filename and size of the file in script file.
If your script file containing the control file creation statement is "CR.SQL"
Then just do the following.
STEP 1: Start sqlplus
STEP 2: connect / as sysdba
STEP 3: Start and do not mount a database like this.
SQL> STARTUP NOMOUNT
STEP 4: Run the "CR.SQL" script file.
STEP 5: Mount and Open the database.
SQL>alter database mount;
SQL>alter database open;
If you do not have a backup of Control file creation statement. Then you have to manually give the CREATE CONTROL FILE statement. You have to write the file names and sizes of all the datafiles. You will lose any datafiles which you do not include.

Recovering Database when the database is running in ARCHIVELOG Mode

Recovering from the lost of Damaged Datafile

If you have lost one datafile. Then follow the steps shown below


STEP 1: Shutdown the Database if it is running.
STEP 2: Restore the datafile from most recent backup.
STEP 3: Then Start sqlplus and connect as SYSDBA.
$sqlplus
Enter User:/ as sysdba
SQL>Startup mount;
SQL>Set autorecovery on;
SQL>alter database recover;

 If all archive log files are available then recovery should go on smoothly. After you get the "Media Recovery completely" statement. Go on to next step.


STEP 4: Now open the database
SQL>alter database open;
Recovering from the Lost Archived Files:
If you have lost the archived files. Then Immediately shutdown the database and take a full offline backup.

Time Based Recovery (INCOMPLETE RECOVERY)


Suppose a user has a dropped a crucial table accidentally and you have to recover the dropped table.
You have taken a full backup of the database on Monday 13-Aug-2007 and the table was created on Tuesday 14-Aug-2007 and thousands of rows were inserted into it. Some user accidently drop the table on Thursday 16-Aug-2007 and nobody notice this until Saturday.
Now to recover the table follows these steps.
STEP 1: Shutdown the database and take a full offline backup.
STEP 2: Restore all the datafiles, logfiles and control file from the full offline backup which was taken on Monday.
STEP 3: Start SQLPLUS and start and mount the database.
STEP 4: Then give the following command to recover database until specified time.
SQL> recover database until time '2007:08:16:13:55:00'
         using backup controlfile;
STEP 5: Open the database and reset the logs. Because you have performed a Incomplete Recovery, like this
SQL> alter database open resetlogs;
STEP 6: After database is open. Export the table to a dump file using Export Utility.
STEP 7: Restore from the full database backup which you have taken on Saturday.
STEP 8: Open the database and Import the table.

Note: In Oracle 10g you can easily recover drop tables by using Flashback feature.

4 comments:

  1. I was looking for the Oracle Online Training courses and your website really help me in finding my needs. This site contains all the stuff which i was looking . Thanks for this great work and i hope this will help a lots of users to achieve their goals

    ReplyDelete
  2. This information which you provided is very much useful for us.It was very interesting and useful for software Courses online training.We also providing oracle online training institute in USA.

    ReplyDelete
  3. The blog was absolutely fantastic! Lot of great information. It is amazing and wonderful to visit your site. It is amazing and wonderful to visit your site.You can also visit here Oracle training institute in delhi. Thanks for sharing this nice article..

    ReplyDelete
  4. Iam so thrilled because of finding your alluring website here.Actually i was searching for Oracle PPM Cloud.Your blog is so astounding and informative too..Iam very happy to find such a creative blog. Iam also find another one by mistake while am searching the same topicOracle Fusion HCM.Thank you soo much.

    ReplyDelete