Rman
Rman
Rman
Create a catalog
===============
create a tablespace
create a user
grant connect, resource, recovery_catalog_owner to user
rman catalog user/pass@db
create catalog tablespace "<tablespace_name>";
Note. <tablespace_name> is case sensitive (i.e. it must be uppercase)
Note. If you get the error 'rman: can't open catalog', make sure that oracle's r
man is being run (which rman). X11 also has a command called rman. Rename it if
necessary.
Register a database
================
Note. ensure the target db has a password file
rman catalog user/pass@rmandb target user/pass@db
Register database;
Un-register a database
====================
sqlplus user/pass@rmandb
select * from rc_database;
select db_key, db_id from db;
execute dbms_rcvcat.unregisterdatabase(<db_key>, <db_id>);
Delete a backup
==============
allocate channel...
delete backuppiece <number>;
release channel;
Oracle to how to purge old RMAN backups
======================================
Oracle runs on Linux, therefore I must be an Oracle expert (so goes management t
hinking). Here s how to correctly purge old RMAN backups when storage runs out of
space (thanks Nakrob):
Do not use rm to remove files. You must do it via RMAN.
$ export NLS_DATE_FORMAT='DD-MM-YY HH24:MI'
$ rman target / NOCATALOG
RMAN > crosscheck backupset;
This command will verify whether backup file is still on media.
If it is unavailable, RMAN will mark it as UNAVAILABLE or EXPIRED.
RAMN > delete expired backupset;
or
RMAN > delete expired backup;
Note : If you manually rename or zip RMAN backup files, you must manually remove
it from disk since RMAN
does not recognize them.
RMAN > report obsolete;
The command lists all backups rendered obsolete based on rentention policy.
Current Retention Policy is 'Recovery WINDOW OF 30 DAYS'.
RMAN > delete obsolete;
RMAN > list backup summary;
It will show all backupset info kept in RMAN repository.
If you want to see what RMAN keeps in each backupset, run 'list backupset N' whe
re N is Backupset ID.
RMAN > delete backupset N;
or
RMAN > delete backupset; (to delete all backups)
Restore/recover a database
=========================
Full restore and recovery
startup nomount;
run {
disk;
disk;
disk;
disk;
}
sql 'alter database open resetlogs';
Restore and roll forward to a point in time
startup nomount;
run {
set until time ="to_date('30/08/2006 12:00','dd/mm/yyyy hh24:mi')";
allocate channel t1 type disk;
allocate channel t2 type disk;
allocate channel t3 type disk;
allocate channel t4 type disk;
restore controlfile;
restore archivelog all;
alter database mount;
restore database;
recover database;
}
sql 'alter database open resetlogs';
If the archive logs are already in place:
startup mount;
run {
set until time ="to_date('08/02/2007 14:00','dd/mm/yyyy hh24:mi')";
allocate channel t1 type disk;
allocate channel t2 type disk;
allocate channel t3 type disk;
allocate channel t4 type disk;
restore database;
recover database;
}
sql 'alter database open resetlogs';
startup mount;
run {
allocate channel t1 type disk;
recover database;
}
,
,
from
,
where
and
order
/
Misc commands
===============
list backupset;
list backup of database;
list backup of archivelog all;
report obsolete;
report obsolete redundancy = 2;
delete obsolete; - remove unneeded backups
restore database validate; - check the backup
report unrecoverable;
report schema; - show current db files
crosscheck backup; - make sure the backups in the catalog still physically exist
delete expired backup; - delete epired backups found by crosscheck
rman target sys/*****@scr10 catalog rman/rman@dbarep
LIST BACKUPSET OF DATABASE;
ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
DELETE OBSOLETE REDUNDANCY = 4 device type disk;
delete obsolete REDUNDANCY = 2 device type disk;
Delete archive log older than...
DELETE NOPROMPT ARCHIVELOG UNTIL TIME "SYSDATE-5"
Crosscheck the available archivelogs (fixes RMAN-06059)
change archivelog all crosscheck;
RMAN job status
===============
select
SESSION_KEY, INPUT_TYPE, STATUS,
to_char(START_TIME,'dd-mm-yyyy:hh24:mi:ss') start_time,
to_char(END_TIME,'dd-mm-yyyy:hh24:mi:ss') end_time,
time_taken_display,OUTPUT_BYTES/1024/1024 "size in MB"
from V$RMAN_BACKUP_JOB_DETAILS where INPUT_TYPE='DB INCR' order by SESSION_KEY;
OR
select operation,status,start_time,end_time from v$rman_status; OR
SELECT * FROM V$RMAN_OUTPUT; OR
select sid, start_time, totalwork sofar, (sofar/totalwork) * 100 pct_done from v
$session_longops where totalwork > sofar
AND
opname NOT LIKE '%aggregate%'
AND