Monday, January 14, 2008

RMAN: find what has been backed up

$ rman target / catalog rman/rman_pwd@mcat
(run this on the target db server to connect to RMAN first)

1. list command
RMAN> list backup of database completed after 'sysdate-3';

-- Show how many times a datafile has been backed up (and valid)
RMAN> list backup of datafile nnn;

-- Show how many times an archivelog has been backed up (in RAC).
RMAN> list backup of archivelog sequence nnnn thread 2;

2. Restore preview

The "restore database preview" gives a report of all the backup pieces and archivelogs that are required to restore/recover the database, by checking the target database controlfile or RMAN catalog. It usually gives the start sequence and end sequence of archivelogs for planning your restore and recovery operation.

3. Restore validate (Note:466221.1)

RMAN command "restore database validate" will read and validate the physical RMAN backuppieces whether they are on tape or on disk and "validate backupset BS_KEY" will test the backups block by block. For example,

RMAN> run {
allocate channel c1 TYPE 'SBT_TAPE';
restore archivelog from sequence xxx until sequence yyy validate;
}

Replace the xxx, yyy with the start and end archivelog sequence reported by "restore database preview" command.

RMAN> run {
set until time "to_date('2008-01-09:21:05:15', 'YYYY-MM-DD:HH24:MI:SS')" ;
allocate channel t1 type 'sbt_tape';
restore database validate;
release channel t1; }

RMAN> run {
ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE';
ALLOCATE CHANNEL ch02 TYPE 'SBT_TAPE';
ALLOCATE CHANNEL ch03 TYPE 'SBT_TAPE';
restore database validate;
RELEASE CHANNEL ch00;
RELEASE CHANNEL ch01;
RELEASE CHANNEL ch02;
RELEASE CHANNEL ch03;
}

The result should like:

Starting restore at 14-JAN-08
channel ch00: starting validation of datafile backupset
channel ch01: starting validation of datafile backupset
channel ch02: starting validation of datafile backupset
channel ch03: starting validation of datafile backupset
channel ch00: reading from backup piece bk_a3j634f9_1_1_643928553
channel ch01: reading from backup piece bk_a4j634f9_1_1_643928553
channel ch02: reading from backup piece bk_a5j634f9_1_1_643928553
channel ch03: reading from backup piece bk_a2j634f8_1_1_643928552
channel ch00: restored backup piece 1
piece handle=bk_a3j634f9_1_1_643928553 tag=TAG20080113T210228
channel ch00: validation complete, elapsed time: 02:07:46
channel ch01: restored backup piece 1
piece handle=bk_a4j634f9_1_1_643928553 tag=TAG20080113T210228
channel ch01: validation complete, elapsed time: 02:10:21
channel ch03: restored backup piece 1
piece handle=bk_a2j634f8_1_1_643928552 tag=TAG20080113T210228
channel ch03: validation complete, elapsed time: 02:14:26
channel ch02: restored backup piece 1
piece handle=bk_a5j634f9_1_1_643928553 tag=TAG20080113T210228
channel ch02: validation complete, elapsed time: 02:14:27
Finished restore at 14-JAN-08

4. Backup validate: to validate that all database files and archived redo logs can be backed up.
RMAN> run {
ALLOCATE CHANNEL ch1 TYPE 'sbt_tape';
BACKUP VALIDATE DATABASE
ARCHIVELOG ALL;
}

5. Control File and Spfile

RMAN> list backup of controlfile;

If you see it, use below command to restore it:
RMAN> run {
ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE';
RESTORE CONTROLFILE FROM 'bk_a6j63cae_1_1_643936590';
}

allocated channel: ch00
channel ch00: sid=319 devtype=SBT_TAPE
channel ch00: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)

allocated channel: ch01
channel ch01: sid=318 devtype=SBT_TAPE
channel ch01: VERITAS NetBackup for Oracle - Release 6.0 (2006110304)

Starting restore at 14-JAN-08

channel ch01: skipped, autobackup already found
channel ch00: restoring control file
channel ch00: restore complete, elapsed time: 00:02:25
output filename=+ARCH/db_name/controlfile/current.269.644253071
output filename=+DATA/db_name/controlfile/current.357.644253071
Finished restore at 14-JAN-08
released channel: ch00
released channel: ch01

RMAN> list backup of spifile;

RMAN> run {
ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE';
restore spfile from 'bk_a7j63cc6_1_1_643936646';
RELEASE CHANNEL ch00;
RELEASE CHANNEL ch01;
}

or

RMAN> run {
ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE';
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE';
RESTORE SPFILE to '/u01/oracle/admin/db_name/pfile/spfile.ora' FROM 'bk_a7j63cc6_1_1_643936646';
}

6. Archive Logs
RMAN> list backup of archivelog all;
RMAN> list backup of archivelog all completed after 'sysdate -1';
RMAN> list copy of archivelog all;
RMAN> list backup of archivelog from scn 7966093 until scn 7966100;
RMAN> list backup of archivelog from logseq 1220;
RMAN> list backupset 802;

7. show all: to view all configuration parameters.
RMAN> show all;

8. Database views
On the target db server, views can also be used to confirm the backups of the individual database. If you see column COMPLETION_TIME is null, the backup is never completed (such as disk was full). The LIST and REPORT commands are based on those views:

V$BACKUP_SET
V$BACKUP_PIECE
V$BACKUP_REDOLOG
V$BACKUP_DATAFILE


On the RMAN catalog database, you can find views RC_XXXXX are very useful. For example, RC_BACKUP_SET_SUMMARY provides aggregate information about available backup sets for each database registered in the recovery catalog (Oracle® Database Backup and Recovery Reference10g Release 2 (10.2), Part Number B14194-03). It is good for finding what the RMAN catalog server is backing up.

select db_name, max(newest_backup_time), sum(num_backupsets)
from rc_backup_set_summary
group by db_name order by db_name;

No comments: