Vous êtes sur la page 1sur 30

MMO ORACLE

Datapump....................................................................................................................................3
Prparation..............................................................................................................................3
Les Exports / Imports..............................................................................................................3
Exporter la base complte (Export Full).............................................................................3
Exporter un Schma............................................................................................................3
Exporter des Tables.............................................................................................................3
INCLUDE et EXCLUDE...................................................................................................3
NETWORK_LINK.............................................................................................................4
Performance........................................................................................................................4
RMAN.........................................................................................................................................5
Installation RMAN..................................................................................................................5
Cration du catalogue.........................................................................................................5
Connexions.........................................................................................................................5
Enregistrer une base............................................................................................................5
Options................................................................................................................................5
BCT Block Change Tracking..............................................................................................6
Sauvegarder.............................................................................................................................6
Sauvegarder.........................................................................................................................6
Incrmentale........................................................................................................................6
Valider ses sauvegardes.......................................................................................................6
Copie dun fichier...............................................................................................................7
Restauration............................................................................................................................7
RMAN sur Disque..................................................................................................................7
Sauvegarde..........................................................................................................................7
Sauvegarde dune copie de la base.....................................................................................8
Restore (controlfile / database ; resetlogs)..........................................................................8
Restore (database ; resetlogs)..............................................................................................9
RMAN sur Bandes..................................................................................................................9
Rplication de la base Offline.............................................................................................9
Sauvegarde Full................................................................................................................10
Rplication de la base Online...........................................................................................10
Sauvegarde Incrmentale..................................................................................................11
Purge Catalogue................................................................................................................11
Contrle / Gestion.............................................................................................................11
Restore..............................................................................................................................12
Gestion du Catalog................................................................................................................13
Maintenance......................................................................................................................13
Suppression dune sauvegarde..........................................................................................13
Incarnation / resetlogs_id..................................................................................................14
Sauvegarde / Restauration en cours......................................................................................15
Backup Catalog.....................................................................................................................16
Sauvegarde Catalogue.......................................................................................................16
Export Catalogue..............................................................................................................16
Restauration Catalogue.....................................................................................................16
Import Catalogue..............................................................................................................17
1

Purge catalog.....................................................................................................................17
Create catalog....................................................................................................................17
Restauration des Archivelogs................................................................................................17
Erreurs RMAN......................................................................................................................18
RMAN-20005: target database name is ambiguous.........................................................18
ORA-19571: archived-log recid NNN stamp NNN not found in control file..................19
RMAN-03002: failure of alter db command at DATE.....................................................19
RMAN-06169 ... reason N................................................................................................20
RMAN-06169: could not read file header for datafile 7 error reason 9...........................20
ORA-19563: header validation failed for file..................................................................21
ArchiveLog...............................................................................................................................22
Mode ArchiveLog.................................................................................................................22
Connatre le mode ArchiveLog.........................................................................................22
Activer le mode ArchiveLog.............................................................................................22
Activer sur un cluster........................................................................................................22
Purge ArchiveLog.................................................................................................................23
Rtention / Purge Expired.................................................................................................23
Purge Forc.......................................................................................................................23
Rplication / Backup.................................................................................................................24
Synchro / Sauvegarde Online................................................................................................24
Synchro des disques et cohrence database......................................................................24
Sauvegarde des disques rpliqus.....................................................................................25
Etat Begin / End Backup...................................................................................................25
Data Guard................................................................................................................................26
Activation / Dsactivation.....................................................................................................26
Arrt / Dmarrage Broker.................................................................................................26
Contrle dgmgrl................................................................................................................27
Paramtre dgmgrl..............................................................................................................27
SwitchOver / FailOver..........................................................................................................27
SwitchOver.......................................................................................................................27
FailOver............................................................................................................................27
Mise en place base Standby..................................................................................................28
Cration sauvegarde for standby.......................................................................................28
Restauration de la base for standby sur PRA....................................................................28
Cration des REDO LOGS standby..................................................................................28
Activation des transports sur Primaire..............................................................................29
Activation des transports sur Standby...............................................................................29
Activation du broker sur standby......................................................................................29
Configuration du DataGuard Manager sur Primaire.........................................................29

Datapump
Prparation
Dbloquer le compte / schma et dfinir un objet DIRECTORY.
CONN / AS SYSDBA
ALTER USER scott IDENTIFIED BY tiger ACCOUNT UNLOCK;
CREATE OR REPLACE DIRECTORY test_dir AS '/u01/app/oracle/oradata/';
GRANT READ, WRITE ON DIRECTORY test_dir TO scott;

Pour visualiser les directories, utiliser la vue ALL_DIRECTORIES.


Defaut DATA_PUMP_DIR = $ORACLE_HOME/admin/<SID>/dpdump

Les Exports / Imports


Pour obtenir de l'aide :
expdp help=y

Quelques cas d'exports les plus courants :


Exporter la base complte (Export Full)
expdp system/password@db10g full=Y directory=TEST_DIR dumpfile=DB10G.dmp
logfile=expdpDB10G.log
impdp system/password@db10g full=Y directory=TEST_DIR dumpfile=DB10G.dmp
logfile=impdpDB10G.log

Exporter un Schma
Exemple du schma SCOTT
expdp scott/tiger@db10g schemas=SCOTT directory=TEST_DIR dumpfile=SCOTT.dmp
logfile=expdpSCOTT.log
impdp scott/tiger@db10g schemas=SCOTT directory=TEST_DIR dumpfile=SCOTT.dmp
logfile=impdpSCOTT.log

Exporter des Tables


Exemple des tables EMP,DEPT pour utilisateur SCOTT
expdp scott/tiger@db10g tables=EMP,DEPT directory=TEST_DIR
dumpfile=EMP_DEPT.dmp logfile=expdpEMP_DEPT.log
impdp scott/tiger@db10g tables=EMP,DEPT directory=TEST_DIR
dumpfile=EMP_DEPT.dmp logfile=impdpEMP_DEPT.log

INCLUDE et EXCLUDE
Ces paramtres fonctionnent la manire de la clause WHERE de SELECT
INCLUDE : ex ici : Inclus seulement les tables EMP et DEPT
expdp scott/tiger@db10g schemas=SCOTT include=TABLE:"IN ('EMP', 'DEPT')"
directory=TEST_DIR dumpfile=SCOTT.dmp logfile=expdpSCOTT.log

EXCLUDE : ex ici toutes les tables sauf la table BONUS

expdp scott/tiger@db10g schemas=SCOTT exclude=TABLE:"= 'BONUS'"


directory=TEST_DIR dumpfile=SCOTT.dmp logfile=expdpSCOTT.log

Multi INCLUDE
INCLUDE=TABLE,VIEW,PACKAGE:"LIKE '%API'"

NETWORK_LINK
Permet un network export/import
Cration de DB LINK
CONN / AS SYSDBA
GRANT CREATE DATABASE LINK TO test;
CONN test/test
CREATE DATABASE LINK remote_scott CONNECT TO scott IDENTIFIED BY tiger USING
'DEV';

Export dune base distante avec dump en local


expdp test/test@db10g tables=SCOTT.EMP network_link=REMOTE_SCOTT
directory=TEST_DIR dumpfile=EMP.dmp logfile=expdpEMP.log

Import dune base distante directement en local sans passer dumpfile


impdp test/test@db10g tables=SCOTT.EMP network_link=REMOTE_SCOTT
directory=TEST_DIR logfile=impdpSCOTT.log remap_schema=SCOTT:TEST

Performance
Paramtre PARALLEL utiliser avec %U de DUMPFILE
expdp scott/tiger@db10g schemas=SCOTT directory=TEST_DIR parallel=4
dumpfile=SCOTT_%U.dmp logfile=expdpSCOTT.log

Monitoring
system@db10g> select * from dba_datapump_jobs;
OWNER_NAME
JOB_NAME
OPERATION
------------------------------ ----------------------------------------------JOB_MODE
STATE
DEGREE ATTACHED_SESSIONS
------------------------------ ------------------------------ ---------------SYSTEM
SYS_EXPORT_FULL_01
EXPORT
FULL
EXECUTING
1

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;
}

Erreurs RMAN
RMAN-20005: target database name is ambiguous
Se connecter sur la base (exemple YT4) pour identifier le DBID et larrter
SQL> select DBID,NAME,CREATED,RESETLOGS_TIME,DB_UNIQUE_NAME from v$database ;
DBID NAME
CREATED
RESETLOGS DB_UNIQUE_NAME
---------- --------- --------- --------- -----------------------------232350802 YT4
10-JUN-11 10-JUN-11 YT4
SQL> shutdown immediate

Se connecter ensuite sur la base RMAN pour lister tous les BDID li la base YT4
oracle@zep302kx:/home/oracle> sqlplus rman/oracle@STN3
SQL> select * from rc_database where name='YT4' order by resetlogs_time ;
DB_KEY DBINC_KEY
DBID NAME
RESETLOGS_CHANGE# RESETLOG
---------- ---------- ---------- -------- ----------------- -------103815
486479 192744664 YT4
320768397 01/03/11
792588
792589 232350802 YT4
1 10/06/11

Se connecter au catalogue de la base YT4 et on supprime les anciennes valeurs BDIF


zep302kx:orayt4 1> rman target / catalog /@STN3
RMAN> set dbid 192744664;
database name is "YT4" and DBID is 192744664
RMAN> unregister database;
RMAN> set dbid 232350802;
RMAN> startup nomount
...

ORA-19571: archived-log recid NNN stamp NNN not found in control file
Se connecter sur le catalog et enregistrer les archivelogs dans le catalog
$ rman catalog <Chaine> target /
RMAN> catalog start with <DIR Archivelog>;

RMAN-03002: failure of alter db command at DATE


After le scenario ( http://damir-vadas.blogspot.fr/2010/02/how-to-find-correct-scn.html )
1. startup nomount
2. restore control file
3. alter database mount
4. restore database
RMAN-03002: failure of alter db command at 01/11/2010 12:08:19
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '+DATA/hac/datafile/system.366.708004385'

Rcuprer le SCN
1) Via RMAN list backup

RMAN> list backup of datafile 1;


...
File LV Type Ckp SCN
Ckp Time Name
---- -- ---- ---------- --------- ---1
Full 35728924
06-DEC-09 +DATA/hac/datafile/system.282.694017165

2) Via x$ tables Oracle


set linesize 200;
set pagesize 100;
col inst_id for 9999999 heading 'Instance #'
col file_nr for 9999999 heading 'File #'
col file_name for A50 heading 'File name'
col checkpoint_change_nr for 99999999999999 heading 'Checkpoint #'
col checkpoint_change_time for A20 heading 'Checkpoint time'
col last_change_nr for 99999999999999 heading 'Last change #'
SELECT
fe.inst_id,
fe.fenum file_nr,
fn.fnnam file_name,
TO_NUMBER (fe.fecps) checkpoint_change_nr,
fe.fecpt checkpoint_change_time,
fe.fests last_change_nr,
DECODE (
fe.fetsn,
0, DECODE (BITAND (fe.festa, 2), 0, 'SYSOFF', 'SYSTEM'),
DECODE (BITAND (fe.festa, 18),
0, 'OFFLINE',
2, 'ONLINE',
'RECOVER')
) status
FROM x$kccfe fe,
x$kccfn fn
WHERE
(
(fe.fepax != 65535 AND fe.fepax != 0 )
OR (fe.fepax = 65535 OR fe.fepax = 0)
)
AND fn.fnfno = fe.fenum
AND fe.fefnh = fn.fnnum
AND fe.fedup != 0
AND fn.fntyp = 4
AND fn.fnnam IS NOT NULL
AND BITAND (fn.fnflg, 4) != 4
ORDER BY fe.fenum
;
Inst# File# File name
Checkpoint#
- - ---------------------------- -----2 1 /u01/system.312.711642293
891734
2 2 /u01/undotbs1.311.711642299 891734
...

Checkpoint time Last change


------------------- ------02/25/2010 10:24:21 891734
02/25/2010 10:24:21 891734

STATUS
-----SYSTEM
ONLINE

Restore until SCN


RMAN>
RMAN>
RMAN>
RMAN>
RMAN>
RMAN>
RMAN>

startup nomount;
restore controlfile;
alter database mount;
set until scn xxxxxxxx+1;
restore database;
recover database [noredo];
alter database open resetlogs;

Si tous les SCN sont les mme, la base peut avoir une consistance suffisant et le recover peut ne
pas tre ncessaire. La commande recover database noredo peut tre utilise.

RMAN-06169 ... reason N


Avec N la signification ci-dessous
1 - "filename is MISSINGxx in the control file"
2 - file is offline
3 - file is not verified
4 - DBWR could not find the file
5 - unable to open file
6 - I/O error during read
7 - file header is corrupt
8 - file is not a datafile
9 - file does not belong to this database
10 - file number is incorrect
12 - wrong file version
15 - control file is not current.
RMAN-06169: could not read file header for datafile 7 error reason 9
(http://oracledatabasemanagementworld.blogspot.fr/2013/05/rman-06169-could-not-read-fileheader.html)
There is a problem with the datafile 7. It could be due to corruption, or any other problem with the
datafile.
Check the status of the datafile
SQL> select file#, status, enabled from v$datafile where file# = 7;
FILE# STATUS ENABLED
---------- ------- ---------7 RECOVER READ WRITE

Restore the datafile from backup and then recover


RMAN> restore datafile 7;
RMAN> recover datafile 7;

ORA-19563: header validation failed for file


RMAN> backup archivelog all format '/Refresh/YT4/20140429_FULL/arch_YT4_%U' ;

RMAN-03002: failure of backup command at 04/29/2014 13:15:31


ORA-19563: header validation failed for file

Il peut manquer des fichiers


# ls -l /oracle/YT4/oraarch/
RMAN> list archivelog all;
RMAN> crosscheck archivelog all;
RMAN> backup archivelog all format '/Refresh/YT4/20140429_FULL/arch_YT4_%U' ;

ORA-27211: Failed to load Media Management Library


(http://docs.oracle.com/cd/B14117_01/server.101/b10734/rcmtroub.htm)
Utiliser : sbttest test_file
Regarder lerreur AlertSID.log dans USER_DUMP_DEST
SKGFQ OSD: Error in function sbtinit on line 2396
SKGFQ OSD: Look for SBT Trace messages in file /oracle/rdbms/log/sbtio.log

SBT Initialize failed for oracle.static

The last line of this output indicates that Oracle is loading the default static library instead of the
media management library that you installed. You may find more detailed information in the file
sbtio.log,

ArchiveLog
Mode ArchiveLog
Connatre le mode ArchiveLog
Switch Log dans un script
SQL> ARCHIVE LOG LIST
Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence

Archive Mode
Enabled
/oracle/YT4/oraarch/YT4arch
114
117
117

Juste le mode
SELECT LOG_MODE FROM SYS.V$DATABASE;

Connatre le volume darchivelog gnr par une instance


SQL> SELECT TO_DATE(TO_CHAR(next_time, 'dd/mm/yyyy'), 'dd/mm/yyyy') Jour, ROUND
(SUM(blocks*block_size/1024/1024)) Mo
FROM v$archived_log
GROUP BY TO_DATE(TO_CHAR(next_time, 'dd/mm/yyyy'), 'dd/mm/yyyy')
ORDER BY 1 DESC ;

Activer le mode ArchiveLog


On peut dfinir une flash recovery area,
SQL> alter system set db_recovery_file_dest_size = 2G scope=both;
SQL> alter system set db_recovery_file_dest ='/safe/oraflash' scope=both;

On peut dfinir les paramtres: log_archive_format et log_archive_dest.


LOG_ARCHIVE_DEST = C:\ORANT\DATABASE\ARCHIVE
LOG_ARCHIVE_FORMAT = "ORCL%S.ARC"

%S numro de squence, %T numro instance (RAC), %d identifiant base


Activation
SQL>
SQL>
SQL>
SQL>

SHUTDOWN
STARTUP MOUNT
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;

Le changement du mode d'archivage mettra jours le fichier de contrle et rendra les anciennes
sauvegardes inutilisables.
Afin de voir immdiatement le rsultat, on peut faire :
SQL> alter system switch logfile

Multiplexage des fichiers ARCHIVELOGS


SQL> SQL> show parameter log_archive_dest_;
NAME
TYPE
VALUE
------------------------------------ ----------- -----------------------------log_archive_dest_1
string
LOCATION=/saparch/YT1/arch
log_archive_dest_2
string
SQL> alter system set log_archive_dest_2="LOCATION=/saparch2" scope=spfile;

Redmarrer la base
Activer sur un cluster
Activation sur un cluster

c:\ srvctl stop database -d base


sqlplus / as sysdba
sql> startup nomount;
sql> alter system set cluster_database=false scope=spfile;
sql> shutdown immediate;
sql> exit
c:\ sqlplus / as sysdba
sql> startup mount
sql> alter database archivelog;
sql> alter system set cluster_database=true scope=spfile;
sql> shutdown immediate;
sql> exit
c:\ srvctl start database -d base

Purge ArchiveLog
Rtention / Purge Expired
Connatre ltat des expired
SQL> SELECT type,count(*) FROM v$deleted_object GROUP BY type ;
TYPE
COUNT(*)
-------------------------- ---------ARCHIVED LOG
16139
DATAFILE COPY
533
ARCHIVED LOG EXPIRED
10256

Affiche la rtention par dfaut


RMAN> SHOW RETENTION POLICY;
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;

Par dfaut, Rman considre qu'un seul backup de chaque fichier est ncessaire
Configurer la rtention
RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY n;
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF n DAYS;
RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;

Le delete Obsolete nettoye bien backup ET archives obsoletes,


RMAN> DELETE OBSOLETE;

Puis faire un crosscheck


RMAN> CROSSCHECK ARCHIVELOG ALL;

Suppression par le systme dexploitation


RMAN> delete expired archivelog all;
(suppression des fichiers)
RMAN> CROSSCHECK ARCHIVELOG ALL;

Purge Forc
Suppression avant une date
rman target / LOG purge.log
RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE 'your_date';
RMAN> delete noprompt force archivelog until time='sysdate-7';

Rplication / Backup
Synchro / Sauvegarde Online
Synchro des disques et cohrence database
Rplication des disques entre le serveur de donne et le serveur de sauvegarde
Switch Log dans un script
sqlplus /nolog << EOF
connect / as sysdba
WHENEVER SQLERROR exit 1
alter system archive log current;
exit;
EOF

Sauvegarde du controlfile
REP_CNTRL=$ORA_ARCH/oracle/$SID/svg/cntrl
# Copy du ControlFile
rman target / << EOF
run {
copy current controlfile to '${REP_CNTRL}/cntrl${SID}.dbf';
copy current controlfile to '${REP_CNTRL}/cntrlS${SID}.dbf';
}
chmod 660 ${REP_CNTRL}/cntrl${SID}.dbf
# RMAN Block Change Tracking (BCT)
sqlplus /nolog << EOF
connect / as sysdba
execute dbms_backup_restore.bctswitch();
exit
EOF
# Synchro RMAN
rman target / catalog rman/${PASSWD}@${HostBackup} << EOF
run { resync catalog; }
EXIT
EOF

Synchronisation DB Arch
Switch Log
Suspend (Begin Backup)
Split DB
Reprise (End Backup)
Switch Log
sauvegarde du controlfile

Business Copy Sync datafile archlog


sqlplus> alter system archive log current
sqlplus> alter database begin backup
Business Copy Split datafile
sqlplus> alter database end backup
sqlplus> alter system archive log current
rman> copy current controlfile to +FRAGD/ctrl_start
rman> copy current controlfile to +FRAGD/ctrl_back
sqlplus> execute dbms_backup_restore.bctswitch();
Synchro RMAN sur HostBackup rman> resync catalog
Split Arch
Business Copy Split archlog
Pour connatre ltat BEGIN BACKUP

SELECT t.name, d.file# as, b.status


FROM V$DATAFILE d, V$TABLESPACE t, V$BACKUP b
WHERE d.TS#=t.TS# AND b.FILE#=d.FILE#;
NAME
FILE# STATUS
---------- ---------- -----------------SYSTEM
1 ACTIVE
UNDOTBS1
2 ACTIVE
SYSAUX
3 ACTIVE
USERS
4 ACTIVE
TB1
5 ACTIVE
TB2
6 ACTIVE

ACTIVE = Tablespace in BACKUP MODE


NOT ACTIVE = Tablespace NOT in BACKUP MODE
Sauvegarde des disques rpliqus
Sur le serveur de contenant la copie de la base, dmarrer la base en mode MOUNT
rman target / << EOF
RUN {
STARTUP MOUNT;
}
EXIT
EOF

Lancement de la SAUVEGARDE
Arrt de la base
sqlplus /nolog << EOF
connect / as sysdba
shutdown immediate
EOF

Etat Begin / End Backup


Dmarrer la base en mode MOUNT
select * from v$backup ;
FILE#
---------1
2
3
4
...

STATUS
-----------------ACTIVE
ACTIVE
ACTIVE
ACTIVE

CHANGE#
---------2120697537
2120697537
2120697537
2120697537

TIME
--------19-SEP-13
19-SEP-13
19-SEP-13
19-SEP-13

Data Guard
Activation / Dsactivation
Arrt / Dmarrage Broker
Sur le primaire
SQL> alter system set dg_broker_start=true|false scope=both ;

Arrt sur le secours


SQL> alter database recover managed standby database cancel ;

Dmarrage sur le secours


SQL> alter database recover managed standby database using current logfile
nodelay disconnect parallel 8 ;

Descendre le dlai dapplication des archives pour tre sr que tout soit appliqu
$ dgmgrl sys/password
dgmgrl> EDIT DATABASE <SID> SET PROPERTY

DelayMins ='0';

Contrle
SQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM
V$MANAGED_STANDBY;
PROCESS
STATUS
THREAD# SEQUENCE#
BLOCK#
BLOCKS
--------- ------------ ---------- ---------- ---------- ---------ARCH
CLOSING
1
51
1
22
ARCH
CLOSING
2
51
1
3
ARCH
CLOSING
1
52
131073
880
ARCH
CLOSING
1
49
1
18
RFS
IDLE
0
0
0
0
RFS
IDLE
0
0
0
0
RFS
IDLE
2
52
20577
6
RFS
IDLE
0
0
0
0
MRP0
WAIT_FOR_LOG
2
45
0
0
RFS
IDLE
1
53
678
6

WAIT_FOR_LOG = En attente de Log (normal)


APPLY_LOG = Application des logs en cours
WAIT_FOR_GAP = Erreur critique, manqu de log
Sil y a des GAP regarder la vue v$dataguard_status
Severity = Control / Informational / Warning
SQL> select count(SEVERITY), SEVERITY from v$dataguard_status group by
SEVERITY ;
SQL> select TIMESTAMP, MESSAGE from v$dataguard_status where SEVERITY =
'Warning';

Ou regarder dans alert$SID.log


RFS[54]: Archived Log:
'/saparch/YT2/oracle/YT2/oraarch/ST2arch1_4549_802286343.dbf'
Mon Jan 21 10:37:09 NFT 2013
RFS[54]: Archive log thread 1 sequence 4549 available in 239 minute(s)
Mon Jan 21 10:37:33 NFT 2013
FAL[client]: Failed to request gap sequence
GAP - thread 1 sequence 2522-2621
DBID 114972913 branch 802286343
FAL[client]: All defined FAL servers have been attempted.

Identifier si les archivelog correspond sont toujours disponible sur le primaire


${SID}arch${thread}_${sequence}_${branch}.dbf
$ ls

DB1arch2_43_768492915.dbf
DB1arch2_46_768492915.dbf
DB1arch2_49_768492915.dbf

DB1arch2_44_768492915.dbf DB1arch2_45_768492915.dbf
DB1arch2_47_768492915.dbf DB1arch2_48_768492915.dbf
<SID>arch<thread>_<sequence>_<branch>.dbf

DelayMins=240; il y a un dlai pour appliquer les derniers logs reus


Contrle dgmgrl
Sur le primaire
$ dgmgrl sys/password
dgmgrl> show configuration

SUCCESS
dgmgrl> show database verbose <SID>
dgmgrl> show database verbose <SID_STBY>

Paramtre dgmgrl
dgmgrl> EDIT DATABASE <SID> SET PROPERTY
dgmgrl> EDIT DATABASE <SID> SET PROPERTY

ArchiveLagTarget ='1800';
DelayMins = '240';

SwitchOver / FailOver
SwitchOver
Sur le primaire : assurer quil ny a plus daccs
SQL@Master> shutdown immediate
SQL@Master> startup [restrict]

Prparer le SwitchOver
Master> alter database commit to switchover to standby with session shutdown ;
Standby> alter database commit to switchover to primary ;

SwitchOver
SQL@Standby> shutdown immediate
SQL> startup mount
SQL> alter database recover managed standby database disconnect ;
SQL> alter databae open ;

Avec DGMGRL
dgmgrl> switchover to <SID_STBY>

Controle
SQL> select status from v$instance;
OPEN
SQL> select CONTROLFILE_TYPE, PROTECTION_MODE, PROTECTION_LEVEL, DATABASE_ROLE
from v$database;
CONTROL PROTECTION_MODE
PROTECTION_LEVEL
DATABASE_ROLE
------- -------------------- -------------------- ---------------CURRENT MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE PRIMARY

Sur le primaire, la base est MOUNTED et le role est PHYSICAL STANDBY


Retour arrire avec DGMGRL
dgmgrl> switchover to <SID>

FailOver
A excuter si le SwitchOver ne peut tre xcut

SQL@Standby> alter database recover managed standby database finish ;


SQL> alter database commit to switchover to primary ;
SQL> alter databae open ;

Mise en place base Standby


Cration sauvegarde for standby
Sauvegarde RMAN sur disque du Master
$ rman target /
RMAN> run {
allocate channel ch1 type disk;
allocate channel ch2 type disk;
backup database format '<CHEMIN_BACKUP_STBY>/%d_%u_%s';
backup current controlfile for standby format '<CHEMIN_BACKUP_STBY>/%d_%u_%s';
}

Envoi du backup sur le serveur PRA (scp ...)


Cration de larborescence TableSpace sur le site PRA lidentique du site primaire (mkdir ...)
Passer la base de PRA en nomount
ORAPWD sur primaire
oracle$ cd $ORACLE_HOME/dbs
$ ln s orapw<SID> orapw<SID_RAC>

ORAPWD sur standby


oracle$ cd $ORACLE_HOME/dbs
$ orapwd file=orapw$ORACLE_SID entries=10 password=<PASSWORD> ;

Restauration de la base for standby sur PRA


Restauration RMAN
$ rman target sys/<SYSPWD>@<SID>_PRIM auxiliary /
RMAN> duplicate target database for standby nofilenamecheck ;

Cration des REDO LOGS standby


Rcuprer la taille des redologs
$ sqlplus / as sysdba
SQL> column member format a50 ;
SQL> SELECT GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS, bytes/1024/1024 "size"
from V$LOG;

Soit <Redo Size> sa taille


Cration des RedoLogFiles standby faire sur Primaire puis sur Standby
Il faut crer 4 REDO LOGS + 1 par THREAD
Chaque REDO LOGS est associ un GROUP
Ex: Thread 1 : du group 110 au group 114
Exemple de Cration du Thread <T> Group <G>
SQL> alter database add standby logfile THREAD <T> GROUP <G>
('$SAPDATA_HOME/redostby/srl_t<T>_<G>a.dbf','$SAPDATA_HOME/redostby/srl_t<T
>_<G>b.dbf') size <Redo_Size>m;

Vrification
SQL> select group#,thread#,sequence#,archived,status from v$standby_log;

Activation des transports sur Primaire


SQL> alter system set
log_archive_dest_1='location=/saparch/<SID>/oracle/<SID>/oraarch/<SID>arch
valid_for=(online_logfiles,all_roles) db_unique_name=<SID>' scope=both
sid=*;
SQL> alter system set log_archive_dest_2='service=<SID_STBY> lgwr sync affirm
nodelay net_timeout=20 reopen=10 max_failure=100 max_connections=2
valid_for=(online_logfiles,primary_role) db_unique_name=<SID_STBY>'
scope=both sid='*';
SQL> alter system set standby_archive_dest='
location=/saparch/<SID>/oracle/<SID>/oraarch/<SID_STBY>arch' scope=both
sid='*';

Pour chaque instance RAC


SQL> alter system set fal_client='<SID>X' scope=both

sid='<SID>X';

SQL> alter system set fal_server='<SID_STBY>' scope=both sid='*';


SQL> alter system set log_archive_dest_state_2=enable scope=both sid='*';
SQL> alter system set
log_archive_dest_3='location=/saparch/<SID>/oracle/<SID>/oraarch/<SID_STBY>
arch valid_for=(standby_logfiles,standby_role) db_unique_name=<SID>'
scope=both sid='*' ;

Activation des transports sur Standby


...
Activation du broker sur standby
SQL> alter system set dg_broker_start=true scope=both;

Configuration du DataGuard Manager sur Primaire


dgmgrl sys/<PWDSYS>@<SID>
DGMGRL> create configuration SAP_DATAGUARD_<COMPOSANT_SAP> as primary database
is <SID> connect identifier is <SID>;
DGMGRL> add database <SID_STBY> as connect identifier is <SID_STBY> maintained
as physical;
DGMGRL> show configuration;
...
DISABLED
DGMGRL> enable configuration;

Vous aimerez peut-être aussi