0% found this document useful (0 votes)
55 views

Rman Comm

Rman command

Uploaded by

martin_sea
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Rman Comm

Rman command

Uploaded by

martin_sea
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

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

LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST

BACKUP; BACKUP OF DATABASE; BACKUP SUMMARY; INCARNATION; BACKUP BY FILE; COPY OF DATABASE ARCHIVELOG ALL; COPY OF DATAFILE 1, 2, 3; BACKUP OF DATAFILE 11 SUMMARY; BACKUP OF ARCHIVELOG FROM SEQUENCE 1437; CONTROLFILECOPY "/tmp/cntrlfile.copy"; BACKUPSET OF DATAFILE 1;

RMAN> RMAN> RMAN> RMAN> RMAN>

CROSSCHECK CROSSCHECK CROSSCHECK CROSSCHECK CROSSCHECK

BACKUP; COPY; backup of database; backup of controlfile; archivelog all;

Restore and recover the whole Database: RMAN> RMAN> RMAN> RMAN> STARTUP FORCE MOUNT; RESTORE DATABASE; RECOVER DATABASE; ALTER DATABASE OPEN;

Restore and recover a Tablespace: RMAN> RMAN> RMAN> RMAN> SQL 'ALTER TABLESPACE users OFFLINE'; RESTORE TABLESPACE users; RECOVER TABLESPACE users; SQL 'ALTER TABLESPACE users ONLINE';

Restore and recover a Datafile: RMAN> RMAN> RMAN> RMAN> SQL 'ALTER DATABASE DATAFILE 64 OFFLINE'; RESTORE DATAFILE 64; RECOVER DATAFILE 64; SQL 'ALTER DATABASE DATAFILE 64 ONLINE';

Restore the Control file, (to all locations specified in the parameter file) then restore the database, using that control file: STARTUP NOMOUNT; RUN { ALLOCATE CHANNEL c1 DEVICE TYPE sbt; RESTORE CONTROLFILE; ALTER DATABASE MOUNT; RESTORE DATABASE; } Restore Validation confirms that a restore could be run, by confirming that all database files exist and are free of physical and logical corruption, this does not generate any output. Example: RMAN> RESTORE DATABASE VALIDATE;

There are many ways to restore a database using an RMAN backup - this example assumes you are performing a DisasterRecovery restore of all data and recovering the entire database with the same SID and the same disk/tablespace layout. You will need the following information: Database SID: ________ Database SYS password: ________ Disk layout and sizes: ________ Database ID (DBID): ________ There are 5 steps to recover the database:

1) Create a new (empty) database instance 2) Mount the instance 3) Restore the datafiles 4) Recover the database 5) Reset the logs 1) Create a new (empty) database instance Configure the new server with same disk layout as the original database - if neccecary use Symbolic Links (or in Windows use disk manager to re-assign drive letters.) Ensure you have enough disk space for both the backup files plus the restored database files. Create a new database with the database configuration assistant (DBCA) and set the SYS password and global database_name to the same as the original database. If the database to be restored is in archive log mode, set the LOG_ARCHIVE_FORMAT parameter to match the setting in the original database. The ORAPWD utility can also be used to change the SYS password. 2) Mount the empty instance SQL> Shutdown immediate; SQL> Startup mount; or specifying the pfile explicitly: SQL> CREATE PFILE='C:\oracle\Database\initLive.ora' FROM SPFILE; SQL> Shutdown immediate;

SQL> Startup mount pfile=C:\oracle\Database\initLive.ora 3) Restore the datafiles In this case we have copied the RMAN backup files and archive logs to R:\Rman\ Change the dbid to match that of the database being restored RMAN> SET dbid = 477771234; RMAN> run { ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT 'R:\Rman\%U'; restore database; } At this point the datafiles and tablespaces will be re-created. For a large database it can take a long time to restore each tablespace - for better performance during a restore place the RMAN backup files on a separate disk to the Oracle datafiles to reduce disk contention. 4) Recover the database SQL> Recover from 'L:\oradata\live' database until cancel using backup controlfile; SQL> cancel 5) Reset the logs SQL> alter database open resetlogs; This will update all current datafiles and online redo logs and all subsequent archived redo logs with a new RESETLOGS SCN and time stamp.

As soon as you have done a resetlogs run a full backup, this is important as should you suffer a second failure you will not be able to perform a second recovery because after resetting the logs the SCN numbers will no longer match any older backup files. Notes: The DBID can be retrieved in several places, if the database is running: Select dbid from V$DATABASE; The RMAN client displays the dbid at startup when connecting to a database: Copyright (c) 1995, 2003, Oracle. All rights reserved. connected to target database: RDBMS (DBID=7776644123)

There are many ways to restore a database using an RMAN backup - this example assumes you are running RMAN without a Catalog and are performing a Restore & Point-In-Time Recovery of all data back to a particular date/time in the past. If you are running in Archive log mode and recover without specifying a date/time then RMAN will apply all Archived logs it can find, ofter recovering the database right back to the time when you started the restore operation! If you are running in Archive log mode (and you should be), point-in time is probably the most common recovery scenario. You will need the following information: Database SID: ________ Database SYS password: ________

The Date and Time to restore to : ________ There are 5 steps to recover the database: 1) Restore backup files from tape 2) Mount the instance 3) Restore the datafiles 4) Recover the database 5) Reset the logs Restore backup files from tape If you are looking to restore the database to a time of (say 09:00) you will need the most recent RMAN backup files prior to the date (say 23:00 from the previous day) plus all the archive logs from the backup time until the restore time, in this case from 23:00 until 09:00. If any of these files have been moved (e.g. archived to tape) restore them to the default locations on the oracle database server. Mount the instance C:\> Set ORACLE_SID=Live C:\> rman TARGET SYS/Password NOCATALOG RMAN:> shutdown immediate; RMAN:> startup mount; Restore and recover the datafiles RMAN> run { allocate channel dev1 type disk; set until time "to_date('2010-30-12:00:00:00', 'yyyy-dd-mm:hh24:mi:ss')";

restore database; recover database; } For a large database it can take a long time to restore each tablespace - for better performance during a restore place the RMAN backup files on a separate disk to the Oracle datafiles to reduce disk contention. Open the database and reset logs RMAN> alter database open resetlogs; This will update all current datafiles and online redo logs and all subsequent archived redo logs with a new RESETLOGS SCN and time stamp. As soon as you have done a resetlogs run a full backup, this is important as should you suffer a second failure you will not be able to perform a second recovery because after resetting the logs the SCN numbers will no longer match any older backup files.

Example Change an ordinary backup into a long-term backup: CHANGE BACKUPSET 431 KEEP FOREVER NOLOGS;

Examples Show all configurable settings: RMAN>SHOW ALL;

Write disk backups to the /tmp directory: (%U will be replaced with unique filenames) RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/tmp/%U'; Backup using a flash recovery area rather than disk RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT CLEAR; Configure RMAN to back up the control file after each backup RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON; By default, RMAN automatically names control file backups and stores them in the flash recovery area. To configure RMAN to write control file backups to the /cfilebackups directory: ( %F will generate a unique filename) RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/cfilebackups/cf%F'; Ensure that RMAN retains all backups needed to recover the database to any point in time in the last 7 days: RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS; Retain three backups of each datafile: RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 3; Delete backups no longer required by the retention policy: RMAN> DELETE OBSOLETE

To override the configured retention policy for individual backups - use BACKUP.. KEEP (or CHANGE.. KEEP) Configure backups to run in parallel by assigning two sbt channels: RMAN> CONFIGURE DEVICE TYPE sbt PARALLELISM 2; Reset any CONFIGURE setting to its default by running the command with the CLEAR option RMAN> CONFIGURE CHANNEL DEVICE TYPE sbt CLEAR; RMAN> CONFIGURE RETENTION POLICY CLEAR; Unique filenames are: DBID, day, month, year, and sequence number.

SHOW { RETENTION POLICY | [DEFAULT] DEVICE TYPE | [AUXILIARY] CHANNEL [FOR DEVICE TYPE deviceSpecifier] | MAXSETSIZE | { DATAFILE | ARCHIVELOG } BACKUP COPIES | BACKUP OPTIMIZATION | SNAPSHOT CONTROLFILE NAME | AUXNAME | EXCLUDE | CONTROLFILE AUTOBACKUP [FORMAT] | ALL }; Examples
SHOW RETENTION POLICY; SHOW DEVICE TYPE; SHOW DEFAULT DEVICE TYPE;

SHOW CHANNEL; SHOW MAXSETSIZE; SHOW ALL;

Syntax: RUN { ... } Example RUN { ALLOCATE CHANNEL dev1 DEVICE TYPE DISK FORMAT '/fs1/%U'; ALLOCATE CHANNEL dev2 DEVICE TYPE DISK FORMAT '/fs2/%U'; BACKUP (TABLESPACE system,finance,marketing FILESPERSET 20) (DATAFILE 62,63,64);
}

Examples Restore and recover the whole database RMAN> STARTUP FORCE MOUNT; RMAN> RESTORE DATABASE; RMAN> RECOVER DATABASE; RMAN> ALTER DATABASE OPEN; Restore and recover a tablespace RMAN> SQL 'ALTER TABLESPACE users OFFLINE'; RMAN> RESTORE TABLESPACE users; RMAN> RECOVER TABLESPACE users;

RMAN> SQL 'ALTER TABLESPACE users ONLINE'; Restore and recover a datafile RMAN> SQL 'ALTER DATABASE DATAFILE 64 OFFLINE'; RMAN> RESTORE DATAFILE 64; RMAN> RECOVER DATAFILE 64; RMAN> SQL 'ALTER DATABASE DATAFILE 64 ONLINE'; Steps for media recovery: 1. Mount or open the database. Mount the database when performing whole database recovery, or open the database when performing online tablespace recovery. 2. To perform incomplete recovery, use the SET UNTIL command to specify the time, SCN, or log sequence number at which recovery terminates. Alternatively, specify the UNTIL clause on the RESTORE and RECOVER commands. 3. Restore the necessary files with the RESTORE command. 4. Recover the datafiles with the RECOVER command. 5. Place the database in its normal state. For example, open it or bring recovered tablespaces online.

Syntax: BACKUP FULL Options BACKUP FULL AS (COPY | BACKUPSET) Options BACKUP INCREMENTAL LEVEL [=] integer Options BACKUP INCREMENTAL LEVEL [=] integer AS (COPY | BACKUPSET) Options BACKUP AS (COPY | BACKUPSET) Options BACKUP AS (COPY | BACKUPSET) (FULL | INCREMENTAL LEVEL [=] integer) Options

Examples Back up the database, and then the control file: (which contains a record of the backup) RMAN> BACKUP DATABASE; RMAN> BACKUP CURRENT CONTROLFILE; Backup datafiles: RMAN> BACKUP AS BACKUPSET DATAFILE 'ORACLE_HOME/oradata/trgt/users01.dbf', 'ORACLE_HOME/oradata/trgt/tools01.dbf'; Backup all datafiles in the database: (bit-for-bit copies, created on disk) RMAN> BACKUP AS COPY DATABASE; Backup archive logs: RMAN> BACKUP ARCHIVELOG COMPLETION TIME BETWEEN 'SYSDATE-28' AND 'SYSDATE-7'; Backup tablespace: RMAN> BACKUP TABLESPACE system, users, tools; Backup controlfile: RMAN> BACKUP CURRENT CONTROLFILE TO '/backup/cntrlfile.copy'; Backup parameter file: RMAN> BACKUP SPFILE; Backup everything: RMAN> BACKUP BACKUPSET ALL; Create a consistent backup and keep the backup for 1 year: (exempt from the retention policy) RMAN> SHUTDOWN; RMAN> STARTUP MOUNT;

RMAN> BACKUP DATABASE UNTIL 'SYSDATE+365' NOLOGS; Backup Validation confirms that a backup could be run, by confirming that all database files exist and are free of physical and logical corruption, this does not generate any output. Example: RMAN> BACKUP VALIDATE DATABASE ARCHIVELOG ALL;

You might also like