Monday, 28 December 2015

RMAN Preparation (IQ)

RMAN Preparation:

We can delete all expired archive log files by issuing the following command.

RMAN> delete expired archivelog all; 

RMAN> change archivelog all crosscheck;
    
[OR]  crosscheck archivelog all; -- Which is useful for whether all of the registered archive logs are still exist. if not, the RMAN changes their status in the metadata as EXPIRED.

CMDFILE : Which is useful to execute the .rcv files from rman prompt as in the following example.

$ rman target / cmdfile script.rcv

Or else we can execute the script as follow.

$rman target / @script.rcv

We can connect the all three types of databases (Such as target, catalog, auxiliary) when we are in operating system prompt. But, we can not connect when we are on RMAN prompt we have to connect individually. For example as showing the below.

When we are on operating system prompt:

$rman target / catalog sys/passwd@catdb auxiliary sys/passwd@aux

when we are on RMAN prompt:

RMAN> connect target /
RMAN> connect catalog sys/passwd@catdb
RMAN> connect auxiliary sys/passwd@aux

We can use a run block when we want to execute a set of rman commands. For example as follow.

run
{
allocate channel ch1 device type disk format '/u02/backup/%F.bak;
backup database;
backup archivelog all;
delete all archivelogs completed before 'sysdate-1';
release channel;
}

We can't issue a SELECT command from within RMAN client.

We can issue the CREATE command from within RMAN and as well we can issue the PLSQL blocks from within RMAN client.

We can issue the STARTUP and SHUTDOWN databases from within RMAN client as showing the follow.

RMAN> startup
RMAN> startup upgrade
RMAN> startup mount
RMAN> startup nomount

RMAN> Shut immediate
RMAN> Shut abort
RMAN> alter database open;
RMAN> alter database open resetlogs;

By using the following command we can check the syntax of rman commands before executing the rman command from within RMAN.

$rman checksyntax @/tmp/scripts.cmd


NOTE: We cant use the CHECKSYNTAX argument after starting the RMAN client.

Identifying RMAN Server sessions:

RMAN performs all its backup and recovery tasks by using server sessions.

Number Sessions = C+N+2

Here, C is the no.of channels allocated.
      N is the no.of CONNECT options used in the allocate channel commands (if no connect options are used, N has the value of 1)its means default connection means target database.

If we are connecting catalog database as well along with target database, there are two sessions.

We can find out exactly who is currently running the RMAN client by issuing a following command.

$ps -ef|grep rman

oracle 9255 9012 0 mar18 pts/4 00:00:01 rman target /
oracle 6068 6032 0 mar18 pts/2 00:00:01 rman target /

Having a list of RMAN client sessions like this, you can pick one in which you're interested. Say that you're intersted in the session for process ID 9255.
You can then issue the following command, which will find all the child processes associated with that instance of the client:

$ps -ef|grep 9255

To identify the Oracle Session ID of the RMAN session, Look for the following types of messages in the RMAN log:

channel ch2: sid-12 devtype=SBT_TAPE

By using RMAN sessions we can kill the unwanted RMAN sessions by using 'KILL' command or alter system kill session;

How to drop the database within RMAN Prompt?

However we can drop a database within sql*plus prompt but we cant drop database including backup within sql*plus prompt.

Steps to drop a database within RMAN prompt:

RMAN> startup mount;

RMAN> drop database;

Now drop the database including backup by issuing following command:

RMAN> drop database including backups;

NOTE: RMAN will ensures that all datafiles, redo logfiles and controlfiles belonging to the database are removed from the operating system file system.

Optionally, we can specify all the archived logs, backups and copies belong to the database to be removed as well.


CONFIGURING THE RMAN ENVIRONMENT:

Configure settings are stored in target database CONTROLFILE regardless of whether you are using RECOVERY CATALOG Database.

If you are using one recovery catalog db, contains the configurations for all databases that are registered in the recover catalog database.

If you are not using catalog database the configuration settings stored in the their target database contolfiles.

RMAN> show all;

When we issuing the SHOW command queries the target database controlfile to retrieve the RMAN Configuration settings. 

Your database must be MOUNTED or OPEN when issuing the SHOW command quires. Since the RMAN configuration settings stored in the controlfile. 

controlfile autobackup - which is useful, whether the control file backup is automated or not.

Ex: configure controlfile backup on/off #default OFF

retention policy - Shows the policy of datafiles and controlfiles backups and copies that RMAN marks as obsolete.

Note: By using the V$RMAN_CONFIGURATION view we can find out the nondefault RMAN Configure settings.

SQL> select * from V$RMAN_CONFIGURATION;

* CONFIGURE RETENTION POLICY TO REDUNDANCY 1 - Means that RMAN retains only one set of backup copies.

* CONFIGURE BACKUP OPTIMIZATION OFF - Means that by default RMAN won't skip the backing up unchanged data blocks in the datafiles.

* CONFIGURE DEFAULT DEVICE TYPE TO DISK - Means that by default RMAN sends backup output to a disk drive.

* CONFIGURE CONTROLFILE AUTOBACKUP OFF - Means that by default RMAN doesn't automatically backup the control files when it performs a backup task.

* CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET - Means that the default RMAN backup type is a backup set (and not an image copy) and the degree of parallelism is 1.

Here, Parallelism is 1 means 

* CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1 - Means that by default RMAN doesn't make multiple copies of a backup file.

* CONFIGURE MAXSETSIZE TO UNLIMITED - Means that there's no limit on the size of a backpset by default.

* CONFIGURE ENCRYPTION FOR DATABASE OFF - Means that by default RMAN backups aren't encrypted.


If we want to change the value of parameter to default value that you can change by using the following command.

RMAN> configure ....clear;

Example :

RMAN> configure backup optimization clear;

NOTE: 
Once you configure automatic control file backup, RMAN Will automatically backup your target database controlfile, as well as the current binary server parameter file (SPFILE)if you're using, when any of the following events occurs:

* Successful completion of either a BACKUP or COPY command.
* After a CREATE CATALOG command from the RMAN prompt is successfully completed.
* Any structural changes to the database modify the contents of the controlfile.

First two events - If you are using one - is successfully updated, RMAN will then backup the controlfile to its own backup piece.

In third event, Any changes to the pysical structure of your database, even if they are made through SQL*PLUS, will trigger a control file autobackup. 

For example, The following actions will trigger an autobackup of the controlfile: 

Adding a tablespace or Datafile, Dropping a datafile, Placing a tablespace offline or online, adding an online redo log, and renaming a datafile).

When automatic backup is triggered by a structural change, and oracle server process (not an RMAN Process) will automatically create the autobackup of your control file.

NOTE: Automatic control file back ups that occur after a datafile backup can be created on disk or tape.

*****************************************************************
RMAN Can recover a database if you have autobackup of controlfile, even if the current conrolfile, the recovery catalog, and the server parameter file all turn out to be inaccessible.

The following are the steps RMAN takes in recovering the database:

* RMAN Will first restore the SPFILE from the location where the file was automatically backed up to by RMAN.

*RMAN will start the instance with the help of SPFILE it restored in first step.

* RMAN Will restore the control file from the same autobackup.

* Once the control file is MOUNTED, RMAN will connect to the target database in the NOCATALOG mode and use the RMAN repository available in the control file to restore the data files and then recover the database.

* At this point, you may re-create a new recovery catalog and register your target databases in it.

* Finally, RMAN will copy all the RMAN repository records from the target database control files to the new recovery catalog.


NOTE: Diff bw CATALOG and NOCATALOG arguments.

The default for the "RMAN" command is nocatalog. If the catalog database is not available.

If catalog db is created, RMAN will store all repository into the catalog db schema.

When ever we need to restore and recover the database we want to connect the rman client along with the catalog argument. then it will connect the target database along with the catalog db as well.

********************************************************************
Snapshot control file:

We can configure the backup of snapshot controlfile by using the following command.

RMAN> configure snapshot controlfile name to '/backup/snct.ctl';

The default location of the snct file is $ORACLE_HOME/dbs.
we can find the default location of the snct file by issuing following command.

SQL>show snapshot controlfile name;

The snapshot controlfile is a temporary file copy of the controlfile.
Which is used by RMAN to synchronize the information with the current controlfile.

Snapshot controlfile is created when resynchronizing with the recover catalog and when making a backup of the current controlfile.


Basically the snapshot controlfile is created when oracle needs a "read-consistent verion" of the controlfile.

*******************************************************************

Retention period of the RMAN Backup details (RMAN Repository in controlfile):


If you are using on controlfile to store the RMAN repository and there is no recovery catalog database to store the repository of the RMAN. In this case we want to change the length of time for which the oracle server will retain history data in the controlfile before overwriting it. for this we have to follow the below.

We can set the retention period by using the below parameter.

parameter is CONTROL_FILE_RECORD_KEEP_TIME

>ALTER SYSTEM SET CONTROL_FILE_RECORD_KEEP_TIME=15;

Now the control file saved the 15 days of historical RMAN backup and recover activities.

By default, the control file saved 7 days details and range of the value is 0 to 365 days.

If you set the retention time to zero, it means the reusable sections of the control file will not expand when there aren't any more empty reusable records and the database starts over writing the existing records as and when it needs them.
The controlfile contains two types of sections: 

Reusable and nonreusable.

control_file_record_keep_time parameter applies only to the reusable section of the controlfile.

If RMAN needs to add new backup and recovery-related records to the control file, any records that expired as per the parameter are overwritten.

If there are no expired records to be overwritten, the reusable section of the controlfile (and therefore the control file itself) expands.

The V$CONTROLFILE_RECORD_SECTION view provides information about the control file record sections.

********************************************************************************

CONFIGURE BACKUP OPTIMIZATION ON;

We can skip the previously backed up files.
*************************************************************

Creating a backup retention policy:

We want to create a retention policy to optimize storage space and other expenses involved in retaining backups.

Backup retention policy based on a Recovery Window:

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

After the specified number of days, RMAN will mark the backups as obsolete, making the eligible for deletion.

Backup retention policy based on redundancy:

CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

By default, RMAN keeps a single copy of each backed-up datafile and controlfile. However, we can specify that RMAN retain more than a single copy of a backed up datafile or controlfile by using REDUNDANCY parameter of the configure retention policy command.

RMAN marks any backups that fail to meet the backup retention policy constraints as OBSOLETE BACKUPS.

We can find the obsolete files by issuing the following command.

RMAN> report obsolete;

and we can delete the files by issuing the following commond.

RMAN> delete obsolete;

We can also query the V$BACKUP_FILES views to check on obsolete backups.

************************************************************

Configure archived log deletion policy:

CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO SBT;

******************************************************************



No comments:

Post a Comment