Vous êtes sur la page 1sur 17

SOMMAIRE

RMAN.........................................................................................................................................2
Installation RMAN..................................................................................................................2
Cration du catalogue.........................................................................................................2
Connexions.........................................................................................................................2
Enregistrer une base............................................................................................................2
Options................................................................................................................................2
Lecteur de Bandes SBT (Networker)..................................................................................3
BCT Block Change Tracking..............................................................................................3
Sauvegarder.............................................................................................................................3
Sauvegarder.........................................................................................................................3
Incrmentale........................................................................................................................4
Valider ses sauvegardes.......................................................................................................4
Copie dun fichier...............................................................................................................4
Restauration............................................................................................................................4
RMAN sur Disque..................................................................................................................5
Sauvegarde..........................................................................................................................5
Sauvegarde dune copie de la base.....................................................................................5
Restore (controlfile / database ; resetlogs)..........................................................................6
Restore (database ; resetlogs)..............................................................................................6
RMAN sur Bandes..................................................................................................................6
Rplication de la base Offline.............................................................................................6
Sauvegarde Full..................................................................................................................7
Rplication de la base Online.............................................................................................8
Sauvegarde Incrmentale....................................................................................................8
Purge Catalogue..................................................................................................................9
Contrle / Gestion...............................................................................................................9
Restore..............................................................................................................................10
Gestion du Catalog................................................................................................................11
Maintenance......................................................................................................................11
Suppression dune sauvegarde..........................................................................................11
Incarnation / resetlogs_id..................................................................................................11
Sauvegarde / Restauration en cours......................................................................................13
Backup Catalog.....................................................................................................................13
Sauvegarde Catalogue.......................................................................................................14
Export Catalogue..............................................................................................................14
Restauration Catalogue.....................................................................................................14
Import Catalogue..............................................................................................................14
Purge catalog.....................................................................................................................14
Create catalog....................................................................................................................15
Restauration des Archivelogs................................................................................................15

RMAN
Fonctionnement et configuration de RMAN http://laurent.leturgez.free.fr/spip.php?article14
Advance RMAN Recovery Techniques
http://docs.oracle.com/cd/B14117_01/server.101/b10734/rcmrecov.htm

Installation RMAN
Cration du catalogue
Cration du tablespace qui va hberger les donnes du catalogue
$ sqlplus / as sysdba
SQL> create tablespace rman_ts datafile
2
'/u01/app/oracle/oradata/orcl/rman_01.dbf'
3
size 25M extent management local
4
/

Cration de lutilisateur
SQL> create user rman_db identified by rman_db
2 default tablespace rman_ts
3 quota unlimited on rman_ts
4 account unlock
5 /
SQL> grant recovery_catalog_owner to rman_mydb ;
SQL> grant connect,resource to rman_mydb ;

Crer le catalogue
$ rman catalog rman_db/rman_db@orcl log=catalog
RMAN> create catalog tablespace rman_ts;

Connexions
$ rman catalog rman_user/mdp[@RMAN_DB]
RMAN> connect catalog rman_user/mdb[@DB]
$ rman target sys/mdp[@SID]
RMAN> connect target sys/mdb[@SID]

Connexion un catalogue
Connexion une base cible

Enregistrer une base


$ rman catalog rman_db/rman_db@orcl
RMAN> connect target sys/orcl@mgmt
RMAN> register database ;

Connexion au catalogue
Puis connexion la base

Options
RMAN> show all ;
Configure [default] device type to sbt;
Configure retention policy to recover
windows of 7 days ;

Lister les options


Configure pour lecteur de bandes
Dlai dexpiration des sauvegardes

Lister les options


RMAN> show all;
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1; # default

CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default


CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO
'/u01/product/ora9204/dbs/snapcf_mgmt.f'; # defaul

Lecteur de Bandes SBT (Networker)


Link libobk.so / libobk.a :
$ cd $ORACLE_HOME/lib
$ ls -l libobk.*
lrwxrwxrwx 1 oracle dba

20 May

6 19:29 libobk.a -> /usr/lib/libnsrora.a

Exemple de configuration avec Networker et la libraire NMDA


RMAN> CONFIGURE DEVICE TYPE SBT_TAPE PARALLELISM 1 BACKUP TYPE TO BACKUPSET;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F';
RMAN> CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1;
RMAN> CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1;
RMAN> CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' PARMS
'ENV=(NSR_SERVER=nsr_host,NSR_CLIENT=hostname,NSR_DATA_VOLUME_POOL=nsr_pool)';

Test simple
RMAN> run {
allocate channel t1 type 'SBT_TAPE';
send
'NSR_ENV=(NSR_SERVER=nsr_host,NSR_CLIENT=hostname,NSR_DATA_VOLUME_POOL=pool)';
CROSSCHECK ARCHIVELOG ALL;
}

Test avec sbttest :


$ sbttest file_test

BCT Block Change Tracking


mkdir /dir/.../track.f
alter database enable block change
tracking using file '/dir/.../track.f';

Par ex dans repertoire archlog


Activer BCT

alter database disable block change


tracking;
SELECT filename, status, bytes
FROM v$block_change_tracking;

Dsactiver BCT
Etat dactivation BCT

Sauvegarder
Sauvegarder
Sauvegarde complte
Backup database plus archivelog ;

Sauvegarde un tablespace
Backup tablespace system, users, tools, undotbs;

Sauvegarde un datafile
SQL> select file_id,file_name from dba_data_files;
RMAN> backup datafile 4;

Sauvegarde un controlfile
Backup current controlfile;

Sauvegarde des journaux

Backup archivelog all;


Backup archivelog time between sysdate-31 and
sysdate;

Autres paramtres
Format /tmp/%U
Filesperset 20
Maxsetsize 5G
Copies 2
TAG backup_du_lundi

Spcifie une localisation


Limite le nb de fichiers de donnes ou de log
Taille max du jeu de sauvegarde
Nombre de copie de chaque jeu de svg
Spcifie une tiquette

Ex :
RMAN>
RMAN>
%';
RMAN>
RMAN>

BACKUP TABLESPACE tools, indx, undotbs FORMAT '?/oradata/%U';


BACKUP FILESPERSET 20 FORMAT='AL_%d/%t/%s/%p' ARCHIVELOG LIKE '%arc_dest
BACKUP TAG 'weekly_full_db_bkup' DATABASE MAXSETSIZE 10M;
BACKUP COPIES 2 DEVICE TYPE sbt BACKUPSET ALL;

Incrmentale
Backup incremental level 0 database;
Backup incremental level 1 cumulative database;

La premire complte

Valider ses sauvegardes


Backup validate database archivelog all;
Backup validate tablespace tools;
Restore database validate;

Copie dun fichier


Copy current controlfile to /save/copie.ctl ;
Copy datafile 1 to /save/bkp.dbf ;

Restauration
Restauration complte
Startup [Force] mount ;
Restore database ;
Recover database ;
Alter database open ;

Force = shutdown abort / startup

Restauration incomplte
Run {
Set until time = 2000-12-09 11:44:00;
Restore database ;
Recover database ;
Alter database open resetlogs ;
}

Format NLS_DATA_FORMAT

Restauration un tablespace
Run {
Sql alter tablespace users offline;
Set newname for datafile 8 to /dir/file.dbf;
Restore tablespace users ;
Switch datafile all ;
Recover tablespace users ;

Si restauration un autre endroit


Si newname !

Sql alter tablespace users online;

Restauration un datafile
Sql alter database datafile 9 offline;
Restore datafile 9 ;
Recover datafile 9 ;
Sql alter database datafile 9 online;

FILE# (ici 9) de v$datafile


Set newname / switch datafile
Si besoin de restaurer ailleurs

Restauration un controlefile
Startup nomount ;
Restore controlfile ;
Alter database mount ;
Recover database ;
Alter database open resetlogs ;

Recover obligatoire (cohrence / ctlfile)


Contenu Redo-logs initialiss

RMAN sur Disque


Sauvegarde
Les bases doivent tre arrtes sur tous les nuds, le CRS dmarr
Espace de reference Ex: /arch/SID/oracle/backup_SID/
$ cd /arch/$SID/oracle/backup_$SID/
$ mkdir $SID_$Date

Cohrence des bases : archive log current


$ sqlplus / as sysdba
SQL> startup
SQL> alter system archive log current;
# alter system checkpoint;
SQL> shutdown immediate

Dmarrage de la base en tat mount


$ rman target /
RMAN> startup mount

Lancement de la sauvegarde sur un nud (par un script)


rman target / nocatalog log=brman`date "+%y%m%d"`.log <<EOF
CONFIGURE DEVICE TYPE DISK PARALLELISM ${PARALLELISM};
run {
BACKUP as compressed backupset database format '${REP}/bck_${SID}_%U';
BACKUP archivelog all format '${REP}/arch_${SID}_%U';
BACKUP current controlfile format '${REP}/cntrl_${SID}_%U';
}
CONFIGURE DEVICE TYPE DISK PARALLELISM 1;
exit;
EOF

Puis redmarrer la base sur tous les nuds


Sauvegarde dune copie de la base
Cas aprs une rplication de baie (cf. Rplication de la base)
su - ora${sid} -c "rman target / log=${RMANLOG} <<EOF
CONFIGURE DEVICE TYPE DISK PARALLELISM ${PARALLELISM};
run {
BACKUP as compressed backupset database format '${REP}/bck_${SID}_%U';
BACKUP archivelog all format '${REP}/arch_${SID}_%U';
BACKUP controlfilecopy '${CNTRLCOPY}' format '${REP}/cntrl_${SID}_%U';

}
CONFIGURE DEVICE TYPE DISK PARALLELISM 1;
exit;
EOF"

Restore (controlfile / database ; resetlogs)


Les bases doivent tre arrtes sur tous les nuds, le CRS dmarr sur un seul noeud
Espace de reference Ex: /arch/SID/oracle/backup_SID/
$ cd /arch/$SID/oracle/backup_$SID/$SID_$Date
$ ls lrt cntrl*

Lancement de la restauration sur un noeud


$ rman target /
RMAN> startup nomount
RMAN> restore controlfile from
'/saparch/<SID>/oracle/backup_<SID>/<SID>_<Date>/cntrl_<SID>_<U>';
RMAN> mount database ;
RMAN> restore database ;
RMAN> recover database ;

Pour connatre la taille de la base restaurer


RMAN> report schema ;

Reset des logs :


$ sqlplus / as sysdba
SQL> alter database open resetlogs ;
SQL> shutdown immediate

Puis redmarrer la base sur tous les nuds


Restore (database ; resetlogs)
Sans restauration du controlfile on ajoute les backupset dans le controlfile courrant
$ rman target /
RMAN> mount database ;
RMAN> catalog start with '/saparch/<SID>/oracle/backup_<SID>/<SID>_<Date>';
RMAN> restore database ;
RMAN> recover database ;

RMAN sur Bandes


Variables pour scripts suivants
TNS=SVG
# SID hebergeant le catalogue RMAN
NWPOOL=SVGSID
# Nom du pool de sauvegarde
NWSERVER=HostBackup
NWBROWSE=2 Days
# Valeur pour la "browse policy"
NWRETENTION=1Months # Valeur pour la "retention policy"
NWCLIENT=host
# Nom du client Networker
SVGDATE=`date +%Y%m%d-%H%M%S`
CNTRLCOPY=$ORA_ARCH/oracle/$SID/svg/cntrl/cntrl${SID}.dbf

Rplication de la base Offline


Ici il sagit dune base rplique (rplication de baie par exemple) et dont le controlfile est en
mode BACKUP et non en mode CURRENT Sauvegarde CONTROLFILECOPY
Resync tous VG

SQL> shutdown immediate


SQL> startup mount
rman target / catalog /@STN
RMAN> copy current controlfile to
filedir;
RMAN> resync catalog ;
SQL> execute
dbms_backup_restore.bctswitch();
SQL> shutdown immediate

Arrt applicatif et arrt de la base


Mount database
Copy du controlfile
Mettre les droits en 660
Synchronisation du catalog
Switch le Block Change Tracking
Arrt de la base & dmontage FS
Split tous VG

Partie excuter sur le serveur hbergeant la copie


Ici la base dorigine est orasid et sur la copie le catalogue est oracle
importvg ... ; mount ...
Importer les VG, monter les FS
chown R oracle ...
Changer les droits en oracle
SQL> startup mount ;
Mount DB
(cf. Sauvegarde Full)
BACKUP de la base
(cf. Purge Catalog)
Purge Catalogue
RMAN> backup validate check logical
Backup Validate
database archivelog all ;
SQL> shutdown immediate
chown R ora<sid> ...
exportvg ... ; umount ...

Arrt de la base
Retour des droits dorigines
Dmonter les FS, Exporter les VG

Sauvegarde Full
Script SAUVEGARDE FULL (exemple avec Networker)
Base de donne (incremental level 0 database)
Archivelog
ControlFile
> rman target / catalog rman/${PASSWD}@${TNS} @/u04/rman/restaure.rcv
> cat /u04/rman/restaure.rcv
run {
allocate channel t1 type 'SBT_TAPE';
allocate channel t2 type 'SBT_TAPE';
allocate channel t3 type 'SBT_TAPE';
allocate channel t4 type 'SBT_TAPE';
send 'NSR_ENV=(NSR_SERVER=${NWSERVER},NSR_CLIENT=${NWCLIENT},
NSR_DATA_VOLUME_POOL=${NWPOOL},NSR_SAVESET_BROWSE=${NWBROWSE},
NSR_SAVESET_RETENTION=${NWRETENTION})';
CROSSCHECK ARCHIVELOG ALL;
CATALOG CONTROLFILECOPY '${CNTRLCOPY}';
BACKUP TAG='${SID}_base_incr0_${SVGDATE}' incremental level 0 database FORMAT
'${SID}_base_incr0_${SVGDATE}_%U';
BACKUP TAG='${SID}_archivelog_${SVGDATE}' archivelog all FORMAT '$
{SID}_archivelog_${SVGDATE}_bck_%U';
BACKUP TAG='${SID}_cntrl_incr0_${SVGDATE}' FORMAT '${SID}_cntrl_${SVGDATE}_
%U' CONTROLFILECOPY '${CNTRLCOPY}';
release channel t1;
release channel t2;
release channel t3;
release channel t4;
}
EXIT

Rplication de la base Online


Pour faire des sauvegardes incrmentales sur une base rplique
Ici 3 VG : appli pour les applications / moteur de base, data et arch
Resync tous VG
Split VG appli
SQL> alter system archive log current ;
Switchlog
SQL> alter database begin backup ;
Suspension de la base
Split VG data
SQL> alter database end backup ;
Reprise de la base
SQL> alter system archive log current ;
Switchlog
RMAN> copy current controlfile to
Copy du controlfile
filedir;
Mettre les droits en 660
RMAN> resync catalog ;
Synchronisation du catalog
SQL> execute
Switch le Block Change Tracking
dbms_backup_restore.bctswitch();

Split VG arch
Partie excuter sur le serveur hbergeant la copie Il faut mettre la base en END BACKUP
Importer les VG, monter les FS
Changer les droits en oracle
SQL> startup mount ;
Mount DB
SQL> alter database end backup ;
Suspension de la base
(cf. Sauvegarde Full)
BACKUP de la base
(cf. Purge Catalog)
Purge Catalogue
SQL> shutdown immediate
Arrt de la base
chown R ora<sid> ...
Retour des droits dorigines
exportvg ... ; umount ...
Dmonter les FS, Exporter les VG
importvg ... ; mount ...
chown R oracle ...

Sauvegarde Incrmentale
Script SAUVEGARDE INCREMENTAL (exemple avec Networker)
rman <<EOF
connect target
connect catalog rman/${PASSWD}@${TNS}
run {
allocate channel t1 type 'SBT_TAPE';
send 'NSR_ENV=(NSR_SERVER=${NWSERVER},NSR_CLIENT=${NWCLIENT},
NSR_DATA_VOLUME_POOL=${NWPOOL})';
CROSSCHECK ARCHIVELOG ALL;
CATALOG CONTROLFILECOPY '${CNTRLCOPY}';
BACKUP TAG='${SID}_base_incr1_${SVGDATE}' incremental level 1 cumulative
database FORMAT '${SID}_base_incr1_${
SVGDATE}_%U';
BACKUP TAG='${SID}_archivelog_${SVGDATE}' archivelog all FORMAT '$
{SAP_INSTANCE}_archivelog_${SVGDATE}_%U';
BACKUP TAG='${SID}_cntrl_incr1_${SVGDATE}' FORMAT '${SID}_cntrl_${SVGDATE}_
%U' CONTROLFILECOPY '${CNTRLCOPY}';
release channel t1;
}
EXIT
EOF

Purge Catalogue
su - ${ORAU} -c "rman target / catalog ${TNS_STRING} << EOF
run {
allocate channel t1 type 'SBT_TAPE';
send 'NSR_ENV=(NSR_SERVER=${NWSERVER},NSR_CLIENT=${NWCLIENT})';
CROSSCHECK BACKUP;
DELETE NOPROMPT EXPIRED BACKUP COMPLETED BEFORE 'SYSDATE-${NBRE_JOURS}'
DEVICE TYPE sbt;
DELETE NOPROMPT EXPIRED BACKUP OF ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7'
DEVICE TYPE sbt;
release channel t1;
}
EXIT
EOF" > $LOG_FULL 2>&1

Contrle / Gestion
Liste les sauvegardes (ici SID=YT1)
$ rman target / catalog rman/oracle@HostBackup
RMAN> list backup summary ;
Key
TY LV S Dev Type Time #Pieces #Copies Compressed Tag
------- -- -- - -------- ---- ------- ------- ---------- --3176091 B F A DISK
19-OCT-11 1 1 YES YT1_BASE_20111019
3176101 B A A DISK
19-OCT-11 1 1 YES YT1_ARCH_20111019
3176108 B F A DISK
19-OCT-11 1 1 NO
YT1_CNTRL_20111019
4905956 B 0 A SBT_TAPE 16-NOV-11 1 1 NO
YT1_BASE_INCR0_20111116-122814
4905957 B 0 A SBT_TAPE 16-NOV-11 1 1 NO
YT1_BASE_INCR0_20111116-122814
4905958 B 0 A SBT_TAPE 16-NOV-11 1 1 NO
YT1_BASE_INCR0_20111116-122814
4905959 B 0 A SBT_TAPE 16-NOV-11 1 1 NO
YT1_BASE_INCR0_20111116-122814
4906120 B A A SBT_TAPE 16-NOV-11 1 1 NO
YT1_ARCHIVELOG_20111116-122814
4906121 B A A SBT_TAPE 16-NOV-11 1 1 NO
YT1_ARCHIVELOG_20111116-122814
4906122 B A A SBT_TAPE 16-NOV-11 1 1 NO
YT1_ARCHIVELOG_20111116-122814
4906123 B A A SBT_TAPE 16-NOV-11 1 1 NO
YT1_ARCHIVELOG_20111116-122814
4906285 B F A SBT_TAPE 16-NOV-11 1 1 NO
YT1_CNTRL_INCR0_20111116-122814
RMAN> list backup tag YT1_BASE_INCR0_20111116-122814
BS Key Type LV Size
Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ --------------4905956 Incr 0 167.11G
SBT_TAPE
00:21:24
16-NOV-11
BP Key: 4905960
Status: AVAILABLE Compressed: NO Tag: YT1_BASE_...
Handle: YT1_base_incr0_20111116-122814_dumrq28o_1_1
Media:
List of Datafiles in backup set 4905956
File LV Type Ckp SCN
Ckp Time Name
---- -- ---- ---------- --------- ---1
0 Incr 1845443701 16-NOV-11 /data/YT1/oracle/system_1/system.data1
6
0 Incr 1845443701 16-NOV-11 /sapdata/YT1/oracle/data2/data001.dbf
...

Statut des sauvegardes (AVAILABLE ou EXPIRED)


RMAN> run { allocate channel t1 type 'SBT_TAPE';
send 'NSR_ENV=(NSR_SERVER=<NWSERVER>,NSR_DATA_VOLUME_POOL=<NWPOOL>,
NSR_CLIENT=<NWCLIENT>)';
crosscheck backup;
release channel t1; }

Suppression dune sauvegarde dtermine


RMAN> run { allocate channel t1 type 'SBT_TAPE';
send 'NSR_ENV=(NSR_SERVER=<NWSERVER>,NSR_DATA_VOLUME_POOL=<NWPOOL>,
NSR_CLIENT=<NWCLIENT>)';
DELETE BACKUP TAG='<TAG>';
release channel t1; }

Restore
Lister et choisir la sauvegarde restaurer TAG_CNTRL et TAG_BASE
Exemple dune restauration avec incrmentale
TAG_CNTRL=SID_CNTRL_INCR1_20101124-114522 (prendre le dernier incremental)
TAG_BASE= SID_BASE_INCR0_20101121-105531 (prendre le dernier full)
$ rman target / catalog rman/oracle@HostBackup
RMAN> startup nomount ;
RMAN> list backup summary ;

Restauration du fichier de contrle


RMAN> run {
allocate channel t1 type 'SBT_TAPE';
send 'NSR_ENV=(NSR_SERVER=<NWSERVER>)';
restore controlfile from tag '<TAG_CNTRL>';
release channel t1;
}

Restauration du database
RMAN> set parallelmediarestore off;
RMAN> run {
allocate channel t1 type 'SBT_TAPE';
allocate channel t2 type 'SBT_TAPE';
allocate channel t3 type 'SBT_TAPE';
allocate channel t4 type 'SBT_TAPE';
send 'NSR_ENV=(NSR_SERVER=<NWSERVER>)';
restore database from tag '<TAG_BASE>';
release channel t1;
release channel t2;
release channel t3;
release channel t4;
}

Nettoyage des redo logs


$ sqlplus / as sysdba
SQL> alter database clear logfile group 1;
SQL> alter database clear logfile group 2;
...

Suppression des archivelogs obsoletes


$ rman target / catalog rman/oracle@STN1
RMAN> crosscheck archivelog all;
RMAN> delete noprompt expired archivelog all;

Application des archivelogs jusqu <DATE>


RMAN> set parallelmediarestore off;
RMAN> run {
allocate channel t1 type 'SBT_TAPE';
allocate channel t2 type 'SBT_TAPE';
send 'NSR_ENV=(NSR_SERVER=<NWSERVER>)';
set until time "to_date('<DATE>','dd-mm-yyyy hh24:mi:ss')";
recover database;
release channel t1;
release channel t2;
}

Pour connatre la taille restaurer


RMAN> rapport schema ;

Reset des logs et arrt des bases


$ sqlplus / as sysdba
SQL> alter database open resetlogs;
SQL> shutdown immediate;

SQL> exit;

Recopie des contrle file dans chaque rpertoire

Gestion du Catalog
Maintenance
Report need backup ;
Report obsolete ;
delete obsolete ;

Les fichiers qui ont besoin de sauvegarder


Afficher les sauvegardes obsoltes
Supprimer les sauvegardes obsoltes

Resync catalog ;
Crosscheck backup ;
Crosscheck archivelog all;
Delete backup tag=TAG

A chaque modification de fichier de contrle


Vrification des jeux de sauvegarde
Vrification des archivelog

Suppression dune sauvegarde


Crosscheck backup ;
List backup summary ;
List backup tag=TAG ;
Delete backup tag=TAG ;

Vrification des jeux de sauvegarde


Liste les backups
Dtail du backup identifi par le TAG
Supprime un backup identifi par le TAG

Incarnation / resetlogs_id
Liens resetlogs_id (incarnation) avec nom de fichiers archlogs
SQL> startup nomount ;
SQL> select incarnation#, resetlogs_change#, resetlogs_time, status,
resetlogs_id from v$database_incarnation ;
INCARNATION# RESETLOGS_CHANGE# RESETLOGS_TIME STATUS RESETLOGS_ID
------------ ----------------- --------------- ------- -----------12
272142935 16-JUL-12
PARENT
788801284
13
289922898 08-AUG-12
CURRENT
790786773

Le numro RESETLOGS_ID apparat dans les noms se fichiers archlogs


<SID>arch1_NNN_<RESETLOGS_ID>
Ex: YT2arch1_6760_790786773.dbf
Lister les incarnation
RMAN> startup nomount ;
RMAN> list incarnation ;
DB Key Inc Key DB Name
------- ------- -------2654412 4867580 YT2
2654412 5655850 YT2
2654412 5497420 YT2
2654412 5465921 YT2

DB ID
---------------114972913
114972913
114972913
114972913

STATUS Reset SCN Reset Time


--- ---------- ---------PARENT 211298351 15-NOV-11
CURRENT 211750053 29-NOV-11
ORPHAN 211750053 25-NOV-11
ORPHAN 212606138 23-NOV-11

Changer dincarnation
RMAN> reset database to incarnation N

Exemples
Resetting RMAN to a Previous Incarnation in NOCATALOG
CONNECT TARGET / NOCATALOG

# step 1: start and mount a control file that knows about the incarnation to
which
# you want to return. if the current control file does not know about it, then
# you must restore an older control file
STARTUP NOMOUNT;
RESTORE CONTROLFILE UNTIL TIME 'SYSDATE-250';
ALTER DATABASE MOUNT;
# step 2: obtain the primary key of old incarnation
LIST INCARNATION OF DATABASE trgt;
List of
DB Key
------1
1

Database Incarnations
Inc Key DB Name DB ID
------- -------- ------------2
TRGT
1334358386
116
TRGT
1334358386

STATUS
------PARENT
CURRENT

Reset SCN
---------154381
154877

Reset Time
---------OCT 30 2001
OCT 30 2001

# step 3: in this example, reset database to incarnation key 2


RESET DATABASE TO INCARNATION 2;
# step 4: restore and recover the database to a point before the RESETLOGS
RESTORE DATABASE UNTIL SCN 154876;
RECOVER DATABASE UNTIL SCN 154876;
# step 5: make this incarnation the current incarnation and then list
incarnations:
ALTER DATABASE OPEN RESETLOGS;
LIST INCARNATION OF DATABASE trgt;
List of
DB Key
------1
1
1

Database Incarnations
Inc Key DB Name DB ID
------- -------- ---------------2
TRGT
1334358386
116
TRGT
1334358386
311
TRGT
1334358386

STATUS
------PARENT
PARENT
CURRENT

Reset SCN
---------154381
154877
154877

Reset Time
---------OCT 30 2001
OCT 30 2001
AUG 13 2002

Resetting the Database After Incomplete Recovery


% rman target / catalog rman/rman@catdb
Recovery Manager: Release 10.1.0.2.0 - Production
Copyright (c) 1995, 2003, Oracle.

All rights reserved.

connected to target database: TRGT (DBID=1334531173)


connected to recovery catalog database
RMAN> RESYNC CATALOG;
RMAN-00571:
RMAN-00569:
RMAN-00571:
RMAN-03009:
RMAN-20003:

===========================================================
=============== ERROR MESSAGE STACK FOLLOWS ===============
===========================================================
failure of resync command on default channel at 11/01/2001 12:00:43
target database incarnation not found in recovery catalog

RMAN> RESET DATABASE;


new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

Sauvegarde / Restauration en cours


Liste les process Oracle
SQL> select SID, SERIAL#, STATUS, PROGRAM from v$session ;
...
SID SERIAL# STATUS
PROGRAM
---- -------- -------- -----------------------------------------------159
1 ACTIVE
oracle@zeq302lx (MMON)
154
24 ACTIVE
rman@zeq302lx (TNS V1-V3)
150
1 ACTIVE
rman@zeq302lx (TNS V1-V3)
149
1 ACTIVE
rman@zeq302lx (TNS V1-V3)
148
1 ACTIVE
rman@zeq302lx (TNS V1-V3)
162
1 ACTIVE
oracle@zeq302lx (SMON)
147
6 ACTIVE
sqlplus@zeq302lx (TNS V1-V3)
156
17 INACTIVE rman@zeq302lx (TNS V1-V3)
155
17 INACTIVE rman@zeq302lx (TNS V1-V3)

Etat des sessions


SQL> select SID,TIME_REMAINING,ELAPSED_SECONDS,MESSAGE from v$session_longops;
SID TIME_REMAINING ELAPSED_SECONDS
---- -------------- --------------MESSAGE
------------------------------------------------------------------------------157
0
RMAN: aggregate input: backup 20: 0 out of 15431950 Blocks done

Progression des sauvegardes


###LONGOPS Pendant Backup ou Restore
COLUMN sid FORMAT 999
COLUMN serial# FORMAT 9999999
COLUMN machine FORMAT A30
COLUMN progress_pct FORMAT 99999999.00
COLUMN elapsed FORMAT A10
COLUMN remaining FORMAT A10
SELECT s.sid,
s.serial#,
s.machine,
TRUNC(sl.elapsed_seconds/60) || ':' || MOD(sl.elapsed_seconds,60) elapsed,
TRUNC(sl.time_remaining/60) || ':' || MOD(sl.time_remaining,60) remaining
# ,ROUND(sl.sofar/sl.totalwork*100, 2) progress_pct
FROM
v$session s,
v$session_longops sl
WHERE s.sid
= sl.sid
AND
s.serial# = sl.serial#;

Nouvelle version
alter session set nls_date_format='dd/mm/yy hh24:mi:ss'
/
select SID, START_TIME,TOTALWORK, sofar, round(sofar/totalwork,3) * 100 done,
sysdate + TIME_REMAINING/3600/24 end_at
from v$session_longops
where totalwork > sofar
AND opname NOT LIKE '%aggregate%'
AND opname like 'RMAN%'
/

Backup Catalog
Variables pour scripts suivants
SVGDATE=`date +%Y%m%d-%H%M%S`
DISK=/oracle/svg/backup_catalog

Sauvegarde Catalogue
$ export ORACLE_SID=<SID_RMAN>
$ rman target /
RMAN> shutdown immediate
RMAN> startup mount
RMAN> run {
BACKUP as compressed backupset TAG='${SID}_base_${SVGDATE}' incremental level 0
database FORMAT '${DISK}/${SAP_INSTANCE}_base_incr0_${SVGDATE}_%U';
BACKUP TAG='${SID}_cntrl_${SVGDATE}' CURRENT CONTROLFILE FORMAT
'${DISK}/${SID}_cntrl_${SVGDATE}_%U';
}

Export Catalogue
$ exp rman/${PASSWD}@${SID} file=${FILE_DMP} log=${LOG} owner=rman
statistics=NONE

Restauration Catalogue
$ rman target /
RMAN> run {
startup nomount ;
restore controfile from ${DISK}/${CONTROLFILE};
mount database;
restore database;
sql alter database open resetlogs ;
}

Import Catalogue
Suppresion du schma (exemple dans un script)
sqlplus /nolog <<EOF
connect / as sysdba
whenever sqlerror exit 1
drop user rman cascade;
EOF

Recration du schma (exemple dans un script)


sqlplus /nolog << EOF
connect / as sysdba
whenever sqlerror exit 1
CREATE USER rman IDENTIFIED BY $PASSWD
Temporary tablespace temp default tablespace tools
QUOTA UNLIMITED ON tools;
GRANT RECOVERY_CATALOG_OWNER TO rman;
EOF

Import de la base RMAN


SQL> exec UTL_RECOMP.recomp_serial()

Dmarrage du listener
$ lsnrctl start listener

Purge catalog
Purge dans catalog
rman target / catalog ...
RMAN> run {
allocate channel t1 type 'SBT_TAPE';
send 'NSR_ENV=NSR_SERVER=${NWSERVER},NSR_CLIENT=${NWCLIENT})';
crosscheck backup ;

delete noprompt expired backup completed before sysdate-${NB_JOURS} device


type sbt ;
release channel t1;
}
RMAN> DELETE BACKUPSET 101, 102, 103;
RMAN> DELETE BACKUPSET TAG weekly_bkup;

Purge dans controlfile


rman target /
RMAN> CROSSCHECK ARCHIVELOG ALL;
RMAN> DELETE FORCE EXPIRED ARCHIVELOG ALL;
RMAN> LIST ARCHIVELOG ALL;

Autre methode
RMAN> CHANGE ARCHIVELOG like '%317009%' UNCATALOG;

Create catalog
Cas o une sauvegarde sur disque est copi dun serveur vers un autre
RMAN> catalog start with '/<dir_backup> ;

Restauration des Archivelogs


Se connecter sur le base de donnes
Rcuprer le SCN et DBID (<dbid>) du controlfile
SQL> select CONTROLFILE_TYPE,CONTROLFILE_CHANGE#,DBID from v$database;

Rcuprer le SCN le plus petit (<min_sequence>)


SQL> select min(checkpoint_change#) from v$datafile_header ;

Se connecter sur la base RMAN


Dterminer le numro de sequences de la premire et de la dernire archivelog sauvegarde dans
le catalogue RMAN pour les threads 1 et 2 (colonne SEQUENCE#)
$ sqlplus rman/<passwd>
SQL> select b.DB_NAME,b.THREAD#,SEQUENCE# from RC_BACKUP_REDOLOG b,
rc_database_incarnation i
where b.DBINC_KEY = i.DBINC_KEY and i.CURRENT_INCARNATION='YES' and
i.DBID=<dbid>
and b.NEXT_CHANGE# >= <min_sequence>
order by THREAD#,SEQUENCE#;

<seq_min_1> = 1er numro de sequence pour le thread 1 puis soustraire 1


<seq_max_1> = dernier numro de sequence pour le thread 1 puis ajouter 1
Se connecter sur le serveur de donnes
Lancer la restauration
$ rman target / catalog rman/<passwd>@<Host_Backup>
RMAN> run {
allocate channel t1 type 'SBT_TAPE';
allocate channel t2 type 'SBT_TAPE';
send 'NSR_ENV=(NSR_SERVER=<NWSERVER>)'
restore archivelog from logseq <seq_min_1> thread 1 until logseq <seq_max_1>
thread 1;
restore archivelog from logseq <seq_min_2> thread 2 until logseq <seq_max_2>
thread 2;
release channel t1;
release channel t2;
}

Application des archivelogs

RMAN> crosscheck archivelog all;


RMAN> recover database;
RMAN> exit;

Application des archivelogs jusqu une date


RMAN> crosscheck archivelog all;
RMAN> run {
set until time "to_date('<JJ>-<MM>-<YYYY> <HH>:<MM>:<SS>','dd-mm-yyyy
hh24:mi:ss')";
RECOVER database;
}