COLD BACKUP AND RECOVERY SCENARIOS:
Cold backup of Database in Noarchivelog Mode.
1) analyze the space requirements.
SQL> select sum(sum_bytes)/1024/11024 m_bytes
from (
select sum(bytes) sum_bytes from v$datafile
union
select sum(bytes) sum_bytes from v$tempfile
union
select (sum(bytes) * members) sum_bytes from v$log
group by members);
2) Determine location and names of files to be backed up.
SQL> select name from v$datafile
union
select name from v$controlfile
union
select name from v$tempfile
union
select member from v$logfile;
3) shutdown database
SQL> shutdown immediate;
4) Do OS level backup
Note: I have also backed up the Online redo Log files.
cp -ivr /u01/app/oracle/oradata/orcl/* /u02/app/oracle/backup/
SQL> startup mount
Do binary backup of controlfile.
SQL> alter database backup controlfile to '/u02/app/oracle
/controlbackup/control.bkp';
Database altered.
Or trace file backup
SQL> alter database backup controlfile to trace as '/u02/app
/oracle/controlback/controltrace';
SQL> alter database open;
Restoring from cold backup in Noarchivelog.
1) When online redo logs backup is there :
Shutdown your database if its open.
Remove the old files
restore files from backup
$ cp -r /u02/app/oracle/backup/* /u01/app/oracle/oradata/orcl/
startup up your database
SQL> startup
2) When online redo logs backup is not there :
Shutdown your database if its open.
restore files from backup
$ cp -r /u02/app/oracle/backup/* /u01/app/oracle/oradata/orcl/
startup up your database
SQL> startup mount
SQL> recover database using backup controlfile until cancel;
when prompted
cancel
SQL> alter database open resetlogs;
This command will clear and recreate the online redo log files
and also will be a new incarnation of the database.
That means old archive logs if any cannot
be used for the purpose of recovery.
So its importatnt that you make a FRESH BACKUP of your database.
HOT BACKUP AND RECOVERY SCENARIOS:
BACKUP
1) Make sure that your database is in archivelog mode.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
2) analyze space requirements.
SQL> select sum(sum_bytes)/1024/11024 m_bytes
from (
select sum(bytes) sum_bytes from v$datafile
union
select sum(bytes) sum_bytes from v$tempfile
union
select (sum(bytes) * members) sum_bytes from v$log
group by members);
3) Determine the files that need backup;
SQL> select name from v$datafile
union
select name from v$controlfile
union
select name from v$tempfile;
4) check max sequence from online redo logfiles.
SQL> select max(sequence#)
from v$log;
MAX(SEQUENCE#)
--------------
7
5) Put the database or tablespace in begin backup mode.
For database
SQL> alter database begin backup;
For Tablespace
SQL> alter tablespace users begin backup;
SQL> select file#,status from v$backup;
FILE# STATUS
---------- ------------------
1 ACTIVE
2 ACTIVE
3 ACTIVE
4 ACTIVE
5 ACTIVE
6) Copy all the datafiles with OS utility.
7) Take the database or tablespace out of backup mode.
For database
SQL> alter database end backup;
For tablespace
SQL> alter tablespace users end backup;
SQL> select file#,status from v$backup;
FILE# STATUS
---------- ------------------
1 NOT ACTIVE
2 NOT ACTIVE
3 NOT ACTIVE
4 NOT ACTIVE
5 NOT ACTIVE
8) archive current logfile and check latest max sequence
number.
SQL> alter system archive log current;
System altered.
SQL> select max(sequence#) from v$log;
MAX(SEQUENCE#)
--------------
19
9) backup the controlfile
Binary backup
SQL> alter database backup controlfile to '/u01/app/oracle
/backup/control.bk';
Database altered.
Trace backup
SQL> alter database backup controlfile to trace as '/u01/app
/oracle/backup/trace';
Database altered.
10) backup all the archived logs generated during backup7
identifying them by log sequence number.
Recovery Scenarios when database is in archivelog with hot backup.
Case 1: Loss of all Controlfiles.
shutdown the database if its open.
SQL> shutdown abort
Copy the controlfiles from backup.
SQL>startup mount
SQL> recover database using backup controlfile until cancel;
SQL> alter database open resetlogs;
Database altered.
CASE 2: Loss of system datafile
SQL> shutdown abort;
SQL> startup mount
SQL> recover tablespace system;
SQL> alter tablespace users offline;
SQL> alter tablespace users offline immediate;
SQL> select file_name from dba_data_files where
tablespace_name='USERS';
FILE_NAME
---------------------------------------------------
/u01/app/oracle/oradata/orcl/users01.dbf
SQL> recover tablespace users;
SQL> alter tablespace users online;
SQL> select file_name,status from dba_data_files
where tablespace_name='USERS';
CASE 3: Added datafile was lost when hotbackup was taken.
Example: Lost test tablespace
SQL> alter tablespace test offline;
SQL> alter database create datafile '/u01/app/oracle
/oradata/orcl/test01.dbf';
SQL> alter database create datafile '/u01/app/oracle
/oradata/orcl/test02.dbf';
SQL> recover tablespace test;
SQL> alter tablespace test online;
SQL> select file_name,status from dba_data_files where
tablespace_name='TEST';
CASE 4: Data file loss and needs to be restored to different location.
Example: lost my users tablespace.
SQL> alter tablespace users offline;
Tablespace altered.
SQL> select file_name from dba_data_files where
tablespace_name='USERS';
Copy appropriate data files from backup to new location.
Rename datafiles.
1 alter database rename file '/u01/app/oracle/oradata
/orcl/users01.dbf'
2 to
3* '/u01/app/oracle/oradata/users01.dbf'
SQL> recover tablespace users;
SQL> alter tablespace users online;
Tablespace altered.
SQL> select file_name,status from dba_data_files where
tablespace_name = 'USERS';
CASE 5: Loss of CRD files.
Restore all the files from backup .
SQL> startup mount
SQL> recover database using backup controlfile until cancel;
SQL> alter database open resetlogs;
CASE 6: Loss of readonly tablespace which backup was taken.
Suppose I lost my read only users tablespace.
SQL> alter tablespace users offline;
Tablespace altered.
Restore from Backup.
SQL> alter tablespace users online;
Tablespace altered.
CASE 8: Loss of controlfile which didn't have the backup
SQL> shutdown abort
SQL> startup
SQL> @crctl.sql
SQL> recover database using backup controlfile until cancel;
SQL> alter system archive log all;
SQL> alter database open;
Cold backup of Database in Noarchivelog Mode.
1) analyze the space requirements.
from (
select sum(bytes) sum_bytes from v$datafile
union
select sum(bytes) sum_bytes from v$tempfile
union
select (sum(bytes) * members) sum_bytes from v$log
group by members);
union
select name from v$controlfile
union
select name from v$tempfile
union
select member from v$logfile;
3) shutdown database
SQL> shutdown immediate;
4) Do OS level backup
Note: I have also backed up the Online redo Log files.
SQL> startup mount
/controlbackup/control.bkp';
Database altered.
Or trace file backup
/oracle/controlback/controltrace';
SQL> alter database open;
Restoring from cold backup in Noarchivelog.
1) When online redo logs backup is there :
Shutdown your database if its open.
Remove the old files
restore files from backup
2) When online redo logs backup is not there :
Shutdown your database if its open.
restore files from backup
$ cp -r /u02/app/oracle/backup/* /u01/app/oracle/oradata/orcl/
startup up your database
SQL> startup mount
SQL> recover database using backup controlfile until cancel;
when prompted
cancel
SQL> alter database open resetlogs;
This command will clear and recreate the online redo log files
and also will be a new incarnation of the database.
That means old archive logs if any cannot
be used for the purpose of recovery.
So its importatnt that you make a FRESH BACKUP of your database.
HOT BACKUP AND RECOVERY SCENARIOS:
BACKUP
1) Make sure that your database is in archivelog mode.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
2) analyze space requirements.
SQL> select sum(sum_bytes)/1024/11024 m_bytes
from (
select sum(bytes) sum_bytes from v$datafile
union
select sum(bytes) sum_bytes from v$tempfile
union
select (sum(bytes) * members) sum_bytes from v$log
group by members);
3) Determine the files that need backup;
SQL> select name from v$datafile
union
select name from v$controlfile
union
select name from v$tempfile;
4) check max sequence from online redo logfiles.
SQL> select max(sequence#)
from v$log;
--------------
7
5) Put the database or tablespace in begin backup mode.
For database
SQL> alter database begin backup;
For Tablespace
SQL> alter tablespace users begin backup;
SQL> select file#,status from v$backup;
FILE# STATUS
---------- ------------------
1 ACTIVE
2 ACTIVE
3 ACTIVE
4 ACTIVE
5 ACTIVE
6) Copy all the datafiles with OS utility.
7) Take the database or tablespace out of backup mode.
For database
SQL> alter database end backup;
For tablespace
SQL> alter tablespace users end backup;
SQL> select file#,status from v$backup;
FILE# STATUS
---------- ------------------
1 NOT ACTIVE
2 NOT ACTIVE
3 NOT ACTIVE
4 NOT ACTIVE
5 NOT ACTIVE
8) archive current logfile and check latest max sequence
number.
SQL> alter system archive log current;
System altered.
SQL> select max(sequence#) from v$log;
MAX(SEQUENCE#)
--------------
19
9) backup the controlfile
Binary backup
SQL> alter database backup controlfile to '/u01/app/oracle
/backup/control.bk';
Database altered.
Trace backup
SQL> alter database backup controlfile to trace as '/u01/app
/oracle/backup/trace';
Database altered.
10) backup all the archived logs generated during backup7
identifying them by log sequence number.
Recovery Scenarios when database is in archivelog with hot backup.
Case 1: Loss of all Controlfiles.
shutdown the database if its open.
SQL> shutdown abort
SQL>startup mount
SQL> recover database using backup controlfile until cancel;
SQL> alter database open resetlogs;
Database altered.
SQL> shutdown abort;
SQL> startup mount
SQL> recover tablespace system;
SQL> alter tablespace users offline;
SQL> alter tablespace users offline immediate;
SQL> select file_name from dba_data_files where
tablespace_name='USERS';
FILE_NAME
---------------------------------------------------
/u01/app/oracle/oradata/orcl/users01.dbf
SQL> recover tablespace users;
SQL> alter tablespace users online;
SQL> select file_name,status from dba_data_files
where tablespace_name='USERS';
CASE 3: Added datafile was lost when hotbackup was taken.
Example: Lost test tablespace
SQL> alter tablespace test offline;
SQL> alter database create datafile '/u01/app/oracle
/oradata/orcl/test01.dbf';
SQL> alter database create datafile '/u01/app/oracle
/oradata/orcl/test02.dbf';
SQL> recover tablespace test;
SQL> alter tablespace test online;
SQL> select file_name,status from dba_data_files where
tablespace_name='TEST';
CASE 4: Data file loss and needs to be restored to different location.
Example: lost my users tablespace.
SQL> alter tablespace users offline;
Tablespace altered.
SQL> select file_name from dba_data_files where
tablespace_name='USERS';
Copy appropriate data files from backup to new location.
Rename datafiles.
1 alter database rename file '/u01/app/oracle/oradata
/orcl/users01.dbf'
2 to
3* '/u01/app/oracle/oradata/users01.dbf'
SQL> recover tablespace users;
SQL> alter tablespace users online;
Tablespace altered.
SQL> select file_name,status from dba_data_files where
tablespace_name = 'USERS';
CASE 5: Loss of CRD files.
Restore all the files from backup .
SQL> startup mount
SQL> recover database using backup controlfile until cancel;
SQL> alter database open resetlogs;
CASE 6: Loss of readonly tablespace which backup was taken.
Suppose I lost my read only users tablespace.
SQL> alter tablespace users offline;
Tablespace altered.
Restore from Backup.
SQL> alter tablespace users online;
Tablespace altered.
CASE 8: Loss of controlfile which didn't have the backup
SQL> shutdown abort
SQL> startup
SQL> @crctl.sql
SQL> alter system archive log all;
SQL> alter database open;
No comments:
Post a Comment