rman.txt
TRANSCRIPT
run {allocate channel c1 type disk;allocate channel c2 type disk;allocate channel c3 type disk;allocate channel c4 type disk;allocate channel c5 type disk;backup as compressed backupset format='/backup/clone/CLONE_%U.rman' DATABASE PLUS ARCHIVELOG;release channel c1;release channel c2;release channel c3;release channel c4;release channel c5;}
Create a catalog===============create a tablespacecreate a usergrant connect, resource, recovery_catalog_owner to user
rman catalog user/pass@dbcreate 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 rman 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@rmandbselect * from rc_database;select db_key, db_id from db;
execute dbms_rcvcat.unregisterdatabase(<db_key>, <db_id>);
Reset the catalog after a restlogs on the target=======================================reset database;
Resync the catalog with the target controlfile=====================================resync catalog;
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 thinking). 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;orRMAN > delete expired backup;
Note : If you manually rename or zip RMAN backup files, you must manually remove it from disk since RMANdoes 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' where N is Backupset ID.
RMAN > delete backupset N;orRMAN > delete backupset; (to delete all backups)
Once fair amount of space is reclaimed, do full backup.Not sure how much full back space is needed but not less than 20G.
RMAN > backup database;
RMAN > list backup;Full backup may have more than one backupset.Look for last backupsets. It will list backup db files.
RMAN > delete obsolete;Rerun this command to delete unwanted existing backupsets (if have) after completed full backup.
Backup a database=================backup database plus archivelog format '/u01/ora_backup/rman/%d_%u_%s';
run {allocate channel t1 type disk;backup current controlfile format '/u01/ora_backup/rman/%d_%u_%s';backup database format '/u01/ora_backup/rman/%d_%u_%s';backup archivelog all delete input format '/u01/ora_backup/rman/arch_%d_%u_%s';release channel t1;}
run {allocate channel t1 type disk;backup archivelog all delete input format '/u01/ora_backup/rman/arch_%d_%u_%s';release channel t1;}
Cold backup (archivelog or noarchivelog mode)
run {allocate channel t1 type disk;shutdown immediate;startup mount;backup database include current controlfile format '/u01/ora_backup/rman/%d_%u_%s';alter database open;}
run { allocate channel t1 type disk; backup archivelog all delete input;}
Restore/recover a database=========================Full restore and recovery
startup nomount;run {
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';
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;}
Show the controlfile backup record==============================set pages 999 lines 100col name format a60break on set_stamp skip 1select set_stamp
, to_char(ba.completion_time, 'HH24:MI DD/MM/YY') finish_time, df.namefrom v$datafile df, v$backup_datafile bawhere df.file# = ba.file#and ba.file# != 0order by set_stamp, ba.file#/
Misc commands===============list backupset;list backup of database;list backup of archivelog all;report obsolete;report obsolete redundancy = 2;delete obsolete; - remove unneeded backupsrestore database validate; - check the backupreport unrecoverable;report schema; - show current db filescrosscheck backup; - make sure the backups in the catalog still physically existdelete expired backup; - delete epired backups found by crosscheckrman target sys/*****@scr10 catalog rman/rman@dbarepLIST 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===============selectSESSION_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 > sofarANDopname NOT LIKE '%aggregate%'AND
opname like 'RMAN%';
nohup rman script===============nohup rman target / log=restore_db.log cmdfile=restore.rcv &
run {allocate channed ch1 device type disk;restore database;}
using simple file==============nohup ksh -x restore.sh &
rman << EOFconnect target;restore database;exitEOF