RMAN - scripts standards
Quelques scripts pour l'utilisation standard de RMAN.
Configuration
# rman_conf
# This script configures RMAN. It needs to be run only once, but can be reloaded befor each backup.
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
CONFIGURE DEVICE TYPE DISK PARALLELISM 2;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u01/orabackup/MYDB/%U';
#Autobackup control file to flash_recovery_area
CONFIGURE CONTROLFILE AUTOBACKUP ON;
#Autobackup control file to disk
#CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/orabackup/MYDB/ora_cf%F';
#If you want exlude a tablespace do this
#CONFIGURE EXCLUDE FOR TABLESPACE TBL_exclude
Backup FULL
# rman_bck_full
# This script makes a FULL (level 0) backup
# Run it once a week
# The database must be in ARCHIVELOG mode to do a hot backup
BACKUP INCREMENTAL LEVEL 0 CUMULATIVE DEVICE TYPE DISK DATABASE;
BACKUP DEVICE TYPE DISK ARCHIVELOG ALL DELETE ALL INPUT;
BACKUP SPFILE;
ALLOCATE CHANNEL FOR MAINTENANCE TYPE DISK;
DELETE NOPROMPT OBSOLETE DEVICE TYPE DISK;
RELEASE CHANNEL;
Backup incrémental
# rman_bck_incremental
# This script makes incremental CUMULATIVE backups. It is launched along the week, between two FULL backups.
# You need just the last FULL backup and the last CUMULATIVE backup to restore the database.
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DEVICE TYPE DISK DATABASE;
# BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG 'mydb_incr_backup' DATABASE;
# The RECOVER COPY... line will not do anything until the script has been running for more than 7 days. The BACKUP INCREMENTAL line will perform image copy backups the first day it is run (and for any new datafiles), with all subsequent backups being level 1 incremental backups. After 7 days, the RECOVER COPY... line will start to take effect, merging all incremental backups older than 7 days into the level 0 backup, effectively moving the level 0 backup forward. The effect of this is that you will permanently have a 7 day recovery window with a 7 day old level 0 backup and 6 level 1 incremental backups. Notice that the tag must be used to identify which incremental backups apply to which image copies.
BACKUP DEVICE TYPE DISK ARCHIVELOG ALL DELETE ALL INPUT;
Backup des archives uniquement
# rman_bck_arch
# This script makes an ARCHIVELOG backup and cleanup. It is launched multiple times a day
BACKUP DEVICE TYPE DISK ARCHIVELOG ALL DELETE ALL INPUT;
Validation des backups
# rman_valid_restore
Run this script when you want to control that RMAN can restore database with existing backups
RESTORE DATABASE VALIDATE;
#RESTORE TABLESPACE read_only_tablespace_name VALIDATE;
Restore et recovery
# rman_restore_recovery
#Do a full database recovery
#we need all configuration files :
#spfile, tnsnames.ora, and listener.ora at right location
#With NOCATALOG mode backup en mode, you MUST backup the DBID. To do this :
#with RMAN : RMAN target /
# RMAN>connected to target database: INVENTORY (DBID=1670954628)
#or: sqlplus "/ as sysdba"
# SQL>select dbid, name from v$database;
# Launch RMAN without "target /", only "rman" or "rman @<path>/<to>/script.rman"
# For using SET UNTIL option, the database backup file BEFORE the "set until" time (and the archivelog backup files) must be present in the backup directory.
#Put the DBID on the following line :
SET DBID <database_id>;
CONNECT TARGET /;
STARTUP NOMOUNT;
LIST BACKUP;
LIST BACKUP SUMMARY;
CROSSCHECK BACKUP;
# CATALOG START WITH '/safe/oracle/@/backup/'
RUN
{
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/safe/oracle/@/backup/ora_cf%F';
RESTORE CONTROLFILE FROM '/RAID0/orasauve/@/nom_backup_controlfile';
# Mount database BEFORE set until
ALTER DATABASE MOUNT;
# NOTE : "SET" only available in a RUN block
# SET UNTIL TIME 'SYSDATE-3';
# SET UNTIL TIME “to_date(‘04-07-2008 00:30:00′, ‘DD-MM-YYYY HH24:MI:SS’)”;
RESTORE DATABASE;
RECOVER DATABASE;
ALTER DATABASE OPEN RESETLOGS;
}
# NOTE : RESETLOGS force a new incarnation of the database
# Erreurs possibles :
# ERROR : RMAN-06004: ORACLE error from recovery catalog database: RMAN-20207: UNTIL TIME or RECOVERY WINDOW is before RESETLOGS
# Cause: UNTIL TIME and RECOVERY WINDOW cannot be less than the database creation time or RESETLOGS time.
# Action: Check the UNTIL TIME or RECOVERY WINDOW. If the database needs to be restored to an old incarnation, use the RESET DATABASE TO INCARNATION command.
# (RMAN> list incarnation;)
# difficile de remonter la dernière sauvegarde de base après avoir fait un essai de restore until. Le restore incomplet et le resetlogs sont enregistrés, une nouvelle incarnation de la base a été générée, un autobackup a été fait et une archive a peut-être été créée depuis... Le mieux pour les tests est de faire une sauvegarde COLD complète de la base avant les tests.
#if an ORA-01152 error occurs, do that :
#SQL> recover database until cancel using backup controlfile;
#SQL> Alter database open resetlogs;
Maintenance courante
# rman_maintenance
# It check for obsolete backups (see REDUDANCY parameter) and delete them
CROSSCHECK BACKUP OF DATABASE;
#REPORT NEED BACKUP;
DELETE OBSOLETE;
# To delete a specific backup do this :
#LIST BACKUP;
#DELETE BACKUPPIECE numero_BP;
# Print all existing backups
#LIST BACKUP SUMMARY;