Book Image

Oracle Database 12c Backup and Recovery Survival Guide

Book Image

Oracle Database 12c Backup and Recovery Survival Guide

Overview of this book

The three main responsibilities of a successful DBA are to ensure the availability, recoverability, and performance of any database. To ensure the recoverability of any database, a DBA needs to have a strong backup and recovery skills set. Every DBA is always looking for a reference book that will help them to solve any possible backup and recovery situation that they can come across in their professional life. Oracle Database 12c Backup and Recovery Survival Guide has the unique advantage to be a reference to all Oracle backup and recovery options available, making it essential for any DBA in the world. If you are new to Oracle Database, this book will introduce you to the fantastic world of backup and recovery that is vital to your success. If you are an experienced DBA, this book will become a reference guide and will also help you to learn some possible new skills, or give you some new ideas you were never aware about. It will also help you to easily find the solution to some of the most well known problems you could find during your career as a DBA. This book contains useful screenshots, scripts, and examples that you will find more than useful. Most of the books currently available in the market concentrate only on the RMAN utility to backup and recovery. This book will be an exception to the rule and will become a must-have reference, allowing you to design a real and complete backup and recovery strategy. It covers the most important topics on Oracle database such as backup strategies, Nologging operations, new features in 12c, user managed backups and recoveries, RMAN (including reporting, catalog management, troubleshooting, and performance tuning), advanced data pump, Oracle Enterprise Manager 12c and SQL Developer. "Oracle Database 12c Backup and Recovery Survival Guide" contains everything a DBA needs to know to keep data safe and recoverable, using real-life scenarios.
Table of Contents (22 chapters)
Oracle Database 12c Backup and Recovery Survival Guide
Credits
About the Author
Acknowledgement
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Playing with RMAN, FRA, and catalog views


Now that we have all configured for RMAN (including our catalog), let's play with our environment.

Monitoring a backup

Of course, to be able to monitor a backup running in our database, we will need to first run our scripts using the following command:

RMAN> BACKUP DATABASE PLUS ARCHIVELOG;

Now that we have our backup running, open a new terminal, connect to SQL*Plus, and execute the following command:

SQL> SELECT sid, serial#, context, sofar, totalwork, round(sofar/totalwork*100,2) "%_COMPLETE"
 2   FROM   v$session_longops
 3   WHERE  opname like 'RMAN%'
 4   AND    opname not like '%aggregate%'
 5   AND    totalwork !=0
 6   AND    sofar <> totalwork
/

Note

This script will show the completed percentage of the current channels, not of the complete job.

Incremental backups

Here are some examples of incremental backup statements:

RMAN> BACKUP INCREMENTALLEVEL=0 DATABASE PLUS ARCHIVELOG DELETE INPUT;
RMAN> BACKUP INCREMENTALLEVEL=1 DATABASE PLUS ARCHIVELOG DELETE INPUT;
RMAN> BACKUP INCREMENTALLEVEL=0 CUMULATIVE DATABASE PLUS ARCHIVELOG DELETE INPUT;

Multisection backups

Have a look at the following command:

RMAN> BACKUP SECTION SIZE 10M TABLESPACE users;

FRA – checking number of redo switches

Have a look at the following command:

SQL> ALTER SESSION SET nls_date_format='dd/mm/yyyy hh24:mi:ss';

SQL> SELECT sequence#, first_time log_started,
lead(first_time, 1,null) over (order by first_time) log_ended
 2   FROM (SELECT DISTINCT sequence#, first_time
 3         FROM   dba_hist_log
 4         WHERE  archived='YES'
 5         AND    sequence#!=0
 6         ORDER BY first_time)
 7   ORDER BY sequence#;

Check for alerts

Have a look at the following command:

SQL> SELECT reason FROM dba_outstanding_alerts;

Check FRA usage

Have a look at the following command:

SQL> SELECT * FROM v$recovery_file_dest;
SQL> ALTER SYSTEM SWITCH LOGFILE;
SQL> SELECT * FROM v$recovery_file_dest;
SQL> SELECT * FROM v$flash_recovery_area_usage;

See the archived log generated by the DB target

Have a look at the following command:

SQL> SET PAGESIZE 200
SQL> SET LINESIZE 200
SQL> COLUMN name FORMAT a50
SQL> COLUMN completion_time FORMAT a25
SQL> ALTER SESSION SET nls_date_format= 'DD-MON-YYYY:HH24:MI:SS';
SQL> SELECT name, sequence#, status, completion_time
 2   FROM   CATALOG_BCK.rc_archived_log;

See the control file backups

Have a look at the following command:

SQL> SET PAGESIZE 200
SQL> SET LINESIZE 200
SQL> SELECT file#, creation_time, resetlogs_time
blocks, block_size, controlfile_type
 2   FROM   v$backup_datafile where file#=0;

SQL> COLUMN completion_time FORMAT a25
SQL> COLUMN autobackup_date FORMAT a25
SQL> ALTER SESSION SET nls_date_format= 'DD-MON-YYYY:HH24:MI:SS';
SQL> SELECT db_name, status, completion_time, controlfile_type,
autobackup_date 
 2   FROM   CATALOG_BCK.rc_backup_controlfile;

SQL> SELECT creation_time, block_size, status,completion_time,autobackup_date, autobackup_sequence
 2   FROM   CATALOG_BCK.rc_backup_controlfile;

See the corrupted list that exists in datafile backups

Have a look at the following command:

SQL> SELECT db_name, piece#, file#, block#, blocks, corruption_type
 2   FROM   CATALOG_BCK.rc_backup_corruption where db_name='ORCL';

See block corruption in the DB, populated when backup or backup validate

Have a look at the following command:

SQL> SELECT file#, block#, corruption_type
 2   FROM   v$database_block_corruption;

See all RMAN configurations (equivalent to show all)

Have a look at the following command:

SQL> COLUMN value FORMAT a60
SQL> SELECT db_key,name, value
 2   FROM   CATALOG_BCK.rc_rman_configuration;

Monitor backup outputs (RMAN)

Have a look at the following command:

SQL> SELECT output FROM v$rman_output ORDER BY stamp;

Offline backups with RMAN

Have a look at the following command:

$ rman target / catalog=catalog_bck/rmancatalog@pdborcl
RMAN> SHUTDOWN IMMEDIATE
RMAN> STARTUP MOUNT
RMAN> BACKUP AS COMPRESSED BACKUPSET DATABASE;
RMAN> ALTER DATABASE OPEN;

Offline backup without using configured defaults

Have a look at the following command:

SHUTDOWN IMMEDIATE
STARTUP MOUNT
RUN
{
ALLOCATE CHANNEL c1 DEVICE TYPE DISK FORMAT '/DB/u02/backups/other/bck1/orcl_%U';
ALLOCATE CHANNEL c2 DEVICE TYPE DISK FORMAT '/DB/u02/backups/other/bck2/orcl_%U';
BACKUP AS COMPRESSED BACKUPSET DATABASE;
BACKUP CURRRENT CONTROLFILE;
}

Using backup limits (duration)

Have a look at the following command:

RMAN> BACKUP DURATION 00:05 DATABASE;
RMAN> BACKUP DURATION 00:05 MINIMIZE TIME DATABASE;
RMAN> BACKUP DURATION 00:05 MINIMIZE LOAD DATABASE;

Modifying the retention policy for a backup set (archival backups)

Have a look at the following command.

Note

In Oracle 11g, the KEEP command overrides the default criteria; this cannot use the FRA.

RMAN> BACKUP DATABASE KEEP FOREVER;
RMAN> BACKUP DATABASE FORMAT '/DB/u02/backups/other/bck1/orcl_%U' KEEP untiltime='sysdate+180' TAG keep_backup;

Archive deletion policy

Have a look at the following command:

RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 2 TIMES TO DEVICE TYPE DISK;

Using RMAN to scan DB for physical and logical errors

Have a look at the following command:

RMAN> BACKUP VALIDATE CHECK LOGICAL DATABASE;

Configuring tablespaces for exclusion from whole database backups

Have a look at the following command:

RMAN> CONFIGURE EXCLUDE FOR TABLESPACE example;
RMAN> BACKUP DATABASE;
# backs up the whole database, including example
RMAN> BACKUP DATABASE NOEXCLUDE;
RMAN> BACKUP TABLESPACE example;  # backs up only  example
RMAN> CONFIGURE EXCLUDE FOR TABLESPACE example CLEAR;

Skipping offline, inaccessible, or read-only datafiles

Have a look at the following command:

RMAN> BACKUP DATABASE SKIP READONLY;
RMAN> BACKUP DATABASE SKIP OFFLINE;
RMAN> BACKUP DATABASE SKIP INACCESSIBLE;
RMAN> BACKUP DATABASE SKIP READONLY SKIP OFFLINE SKIP INACCESSIBLE;

Forcing backups of read-only datafiles

Have a look at the following command:

RMAN> BACKUP DATABASE FORCE;

Backup of newly added datafiles

Add a new datafile for the tablespace example and execute using the following command:

RMAN> BACKUP DATABASE NOT BACKED UP;

Backup files not backed up during a specific period

Have a look at the following command:

RMAN> BACKUP DATABASE NOT BACKED UP SINCE time='sysdate-2';
RMAN> BACKUP ARCIVELOG ALL NOT BACKED UP 1 TIMES;
RMAN> BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG NOT BACKED UP 1 TIMES DELETE INPUT;

General backup examples

Have a look at the following command:

RMAN> BACKUP TABLESPACE USERS INCLUDE CURRENT CONTROLFILE PLUS ARCHIVELOG;
RMAN> BACKUP DATAFILE 2;
RMAN> BACKUP ARCHIVELOG ALL;
RMAN> BACKUP ARCHIVELOG FROM TIME 'sysdate-1';
RMAN> BACKUP ARCHIVELOG FROM SEQUENCE 123; (Enter here a valid sequence from your database)
RMAN> BACKUP ARCHIVELOG ALL DELETE INPUT;
RMAN> BACKUP ARCHIVELOG FROM SEQUENCE xxx DELETE INPUT;
RMAN> BACKUP ARCHIVELOG NOT BACKED UP 3 TIMES;
RMAN> BACKUP ARCHIVELOG UNTIL TIME 'sysdate - 2' DELETE ALL INPUT;

Backup copies

Have a look at the following command.

Note

RMAN will use FRA if it is configured.

RMAN> BACKUP AS COPY DATABASE;
RMAN> BACKUP AS COPY TABLESPACE USERS;
RMAN> BACKUP AS COPY DATAFILE 1;
RMAN> BACKUP AS COPY ARCHIVELOG ALL;