Oracle Technology Blog

OraTech Blog provides tips,tricks,scripts and how-to type answers for Oracle related technologies. I use these commands very often, so I thought it would be useful to share with everybody. Please feel free to include your comments/corrections/questions.

Saturday, November 20, 2010

RMAN Backup Scripts to device backup strategy

Backup database and archivelogs:

allocate channel for maintenance device type disk;
delete force backup completed before 'sysdate - 1 + 1';
crosscheck archivelog all;
run {
allocate channel c1 type DISK ;
allocate channel c2 type DISK ;
backup
database
plus archivelog;
 }


Backup Archive logs:

RMAN> connect catalog *
run {
 allocate channel c1 type SBT PARMS="ENV=(NB_ORA_CLIENT=client_backup_interface,NB_ORA_POLICY=policy_name)";
allocate channel c2 type SBT PARMS="ENV=(NB_ORA_CLIENT=client_backup_interface,NB_ORA_POLICY=policy_name)";
backup
archivelog all ;
}


Delete Archivelog backed up 1 times to device type SBT and completed couple of days ago:

RMAN> connect catalog *
allocate channel for maintenance device type disk;
delete force archivelog all backed up 1 times to device type SBT completed before 'sysdate - 2';


Backup backupset to Tape:

RMAN> connect catalog *
 run {
allocate channel c1 type 'SBT' ;
 allocate channel c2 type 'SBT' ;
 backup backupset completed after "to_date('MM/DD/YYYY HH24:MI:SS','MM/DD/YYYY HH24:MI:SS')"
 ;
 }

Delete Obsolete Backups:

RMAN> connect catalog *
 allocate channel for maintenance device type DISK PARMS="ENV=(NB_ORA_CLIENT=client_backup_interface,NB_ORA_POLICY=policy_name)";
 crosscheck archivelog all;
 crosscheck backup;
 delete force expired archivelog all;
 delete force expired backup;
 allocate channel for maintenance device type SBT PARMS="ENV=(NB_ORA_CLIENT=client_backup_interface,NB_ORA_POLICY=policy_name)";
 delete force obsolete device type SBT;

Incrementally Updated Backups:

 run {
    allocate channel c1 type DISK;
    allocate channel c2 type DISK;
    recover copy of database with tag 'incr_update';
    delete force backup tag='DISKONLY';
    backup  incremental level 1 tag='DISKONLY' for recover of copy with tag 'incr_update'
    database;
 }

Flashback

Primary Database Flashback:
============================

create restore point gold;
flashback database to restore point gold;
alter database open resetlogs;


Standby Database Flashback:
============================

Convert this standby database to snapshot standby using this simple command:

SQL> alter database convert to snapshot standby;

SQL> shutdown immediate
ORA-01507: database not mounted
...
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

database opned in R/W mode and we can make changes in this database.

After your testing is completed, you would want to convert the snapshot standby database back to a regular physical standby database. Just follow the steps shown below:

SQL> connect / as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

...
Database mounted.
SQL> alter database convert to physical standby;

Database altered.

Now shutdown, mount the database and start managed recovery.

SQL> shutdown
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
...
Database mounted.

Start the managed recovery process:

SQL> alter database recover managed standby database disconnect;

Automatic Diagnostic Repository (ADR)

ADR is a simple file-based (directory structured) repository that contains diagnostic data generated from Oracle. It is a collection of items such as trace files, dumps, alert logs, etc. that can be used by administrators to investigate problems and the health of the database. ADR is the new unified directory structure that will hold all diagnostic data from all Oracle products and components—simplifying the search and correlation of information across all aspects of a single or multiple database instance.

ADRCI (ADR Command interface)introduced in Oracle Database Release 11g.

View diagnostic data within the Automatic Diagnostic Repository (ADR).

View Health Monitor reports.

Package incident and problem information into a zip file for transmission to Oracle Support.

Diagnostic data includes incident and problem descriptions, trace files, dumps, health monitor reports, alert log entries, and more.

ADRCI has a rich command set, and can be used in interactive mode or within scripts. In addition, ADRCI can execute scripts of ADRCI commands in the same way that SQL*Plus executes scripts of SQL and PL/SQL commands.

ADR data is secured by operating system permissions on the ADR directories, hence there is no need to log in to ADRCI.

adrci> help

HELP [topic]
Available Topics:
CREATE REPORT
ECHO
EXIT
HELP
HOST
IPS
PURGE
RUN
SET BASE
SET BROWSER
SET CONTROL
SET ECHO
SET EDITOR
SET HOMES | HOME | HOMEPATH
SET TERMOUT
SHOW ALERT
SHOW BASE
SHOW CONTROL
SHOW HM_RUN
SHOW HOMES | HOME | HOMEPATH
SHOW INCDIR
SHOW INCIDENT
SHOW PROBLEM
SHOW REPORT
SHOW TRACEFILE
SPOOL

There are other commands intended to be used directly by Oracle, type
"HELP EXTENDED" to see the list

adrci>
adrci> show alert

ADR Home = c:\oracle\sysadm\diag\rdbms\us\us:
*************************************************************************
Output the results to file: c:\temp\alert_3968_5208_us_3.ado
adrci>