Rman Commands
Rman Commands
General
Note:$ORACLE_HOME/rdbms/admin/prgrmanc.sql
Encryption Algorithms
Format Description
Format Directives
%a Current database activation id
%A Zero-filled activation ID
The copy number of the backup piece within a set of duplexed backup pieces.bMaximum
%c
value is 256
%d Database name
%D Current day of the month from the Gregorian calendar in format DD
%e Archived log sequence number
%f Absolute file number
%F Combines the DBID, day, month, year, and sequence into a unique and repeatable
generated name
1
Bhaskar Reddy Page 2 12/7/2021
2
Bhaskar Reddy Page 3 12/7/2021
$ mkdir /u01
$ chown oracle:dba /u01
$ chmod 755 /u01
$ cd /etc
$ vi fstab
-- using OMF
3
Bhaskar Reddy Page 4 12/7/2021
4
Bhaskar Reddy Page 5 12/7/2021
startup mount;
Execute a series of script of RMAN commands stored in an operating system file. Do not leave whitespace between the @ and
filename.
@<path_and_file_name> rman TARGET / @backup_db.rcv
or
@@
Execute script files located in the same directory as the file from which it has been called
@@<path_and_file_name TBD
5
Bhaskar Reddy Page 6 12/7/2021
>
ADVISE FAILURE
Displays repair options for the specified failures. Prints a summary of the failures identified by the Data Recovery Advisor and
implicitly closes all open failures that are already fixed.
ADVISE FAILURE <ALL | RMAN> LIST FAILURE;
CRITICAL | HIGH | LOW | RMAN> ADVISE FAILURE ALL;
failure_number_list> RMAN> REPAIR FAILURE;
EXCLUDE FAILURE
<failure_number_list>
ALLOCATE CHANNEL
To manually allocate a channel, which is a connection between RMAN and a database instance. Each connection initiates an
database server session on the target or auxiliary instance: this server session performs the work of backing up, restoring, or
recovering RMAN backups.
Manually allocated channels (allocated by using ALLOCATE) should be distinguished from automatically allocated channels
(specified by using CONFIGURE). Manually allocated channels apply only to the RUN job in which you issue the command.
Automatic channels apply to any RMAN job in which you do not manually allocate channels. You can always override automatic
channel configurations by manually allocating channels within a RUN command.
Each channel operates on one backup set or image copy at a time. RMAN automatically releases the channel at the end of the
job.
You can control the degree of parallelism within a job by allocating the desired number of channels. Allocating multiple
channels simultaneously allows a single job to read or write multiple backup sets or disk copies in parallel. If you establish
multiple connections, then each connection operates on a separate backup set or disk copy.
Whether ALLOCATE CHANNEL causes operating system resources to be allocated immediately depends on the operating
system. On some platforms, operating system resources are allocated at the time the command is issued. On other platforms,
operating system resources are not allocated until you open a file for reading or writing.
Allocating a Single Backup Channel
6
Bhaskar Reddy Page 7 12/7/2021
7
Bhaskar Reddy Page 8 12/7/2021
ALTER DATABASE
8
Bhaskar Reddy Page 9 12/7/2021
}
BACKUP
-- Back up a database, tablespace, datafile (current or copy), control file (current or copy), SPFILE, archived log, or backup
set.
9
Bhaskar Reddy Page 10 12/7/2021
?
TBD
BACKUP AUXILIARY ....
In the first RMAN places datafiles 3 through 7 into one backup set and datafiles 8 and 9 into another. In the second all datafiles
go into a single backup set.
BACKUP AS BACKUPSET BACKUP AS BACKUPSET (DATAFILE 3, 4, 5, 6, 7) (DATAFILE 8, 9);
DEVICE TYPE
<device_identifier> BACKUP AS BACKUPSET DATAFILE 3, 4, 5, 6, 7, 8, 9;
COPIES <integer>
DATABASE FORMAT
'<location_and_format>' .
...
10
Bhaskar Reddy Page 11 12/7/2021
?
TBD
BACKUP BLOCKS ....
Manually allocate a channel, in order to specify that the backup run by this channel should go to both pools first_copy and
second_copy.
SET MAXCORRUPT indicates that no more than 1 corruption should be tolerated in each datafile. Because the CHECK LOGICAL
option is specified on the BACKUP command, RMAN checks for both physical and logical corruption.
BACKUP CHECK RUN {
[LOGICAL] SET MAXCORRUPT FOR DATAFILE 5,6,7,8 TO 1;
11
Bhaskar Reddy Page 12 12/7/2021
BACKUP TBD
CONTROLFILECOPY ....
?
TBD
BACKUP COPY ....
BACKUP TBD
CUMMULATIVE ....
Backup Database
12
Bhaskar Reddy Page 13 12/7/2021
RUN {
ALLOCATE CHANNEL d1
RUN {
DEVICE TYPE DISK;
ALLOCATE CHANNEL d1 DEVICE TYPE DISK;
BACKUP DATABASE;
BACKUP DATABASE PLUS ARCHIVELOG;
}
}
Backup Database Plus
Archivelog
BACKUP DATAFILE
BACKUP TBD
DATAFILECOPY ....
?
BACKUP TBD
DB_FILE_NAME_CONVERT
....
?
BACKUP TBD
DB_RECOVERY_FILE_DES
T ....
13
Bhaskar Reddy Page 14 12/7/2021
RMAN locates all datafile copies with the tag LATESTCOPY, backs them up to tape, and names the backups by means of
substitution variables. After the datafile copies are on tape, the example deletes all image copies with the tag LATESTCOPY.
BACKUP DEVICE TYPE RMAN> {
<DISK | SBT> .... BACKUP DEVICE TYPE sbt
DATAFILECOPY FROM TAG 'LATESTCOPY' FORMAT 'Datafile%f_Database%d';
Populate each backup set with datafiles from the specified number of disks. To disable set to 0.
RMAN> BACKUP
DISKRATIO 0; -- disable
RMAN> BACKUP
DISKRATIO 5; --
enableBACKUP
DURATION
Backup will stop if it is not completed in the specified duration
BACKUP DURATION RMAN> BACKUP DURATION 3:30 DATABASE;
<HH:MI>
<backup_specification>
[MINIMIZE <LOAD |
TIME>]
BACKUP DURATION
<HH:MI>
<backup_specification>
PARTIAL
?
TBD
BACKUP FILE ....
14
Bhaskar Reddy Page 15 12/7/2021
?
TBD
BACKUP FILESPERSET ....
This command will give me a level 1 backup to be used to recover level 0 backup to the latest level
RMAN > BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG 'incr_upd' DATABASE
FORMAT '/oradata/rman/161932/inc_%d_%T_%t_%s_%p';
15
Bhaskar Reddy Page 16 12/7/2021
?
TBD
BACKUP KEEP ....
?
TBD
BACKUP MAXSETSIZE ....
?
BACKUP NOCHECKSUM .... TBD
16
Bhaskar Reddy Page 17 12/7/2021
?
TBD
BACKUP NOEXCLUDE ....
?
TBD
BACKUP NOKEEP ....
?
TBD
BACKUP NOT ....
?
TBD
BACKUP PROXY ....
?
TBD
BACKUP POOL ....
?
TBD
BACKUP RECOVERY ....
?
TBD
BACKUP REUSE ....
17
Bhaskar Reddy Page 18 12/7/2021
TBD
BACKUP SECTION ....
?
TBD
BACKUP SETSIZE ....
?
TBD
BACKUP TABLESPACE ....
?
TBD
BACKUP TO ....
?
TBD
BACKUP VALIDATE ....
18
Bhaskar Reddy Page 19 12/7/2021
BLOCKRECOVER
Block media recovery recovers an individual data block or set of data blocks within a datafile. This type of recovery is useful if
the data loss or corruption applies to a small number of blocks rather than to an entire datafile.
Typically, block corruption is reported in error messages in trace files. Block-level data loss usually results from:
I/O errors causing minor data loss
Memory corruptions that get flushed to disk
BLOCKRECOVER ALLOW
?
BLOCKRECOVER TBD
ALLOW ....
BLOCKRECOVER TBD
ARCHIVELOG ....
BLOCKRECOVER TBD
AUXILIARY ....
BLOCKRECOVER TBD
CHECK ....
BLOCKRECOVER TBD
CLEAR ....
?
BLOCKRECOVER COPY .... TBD
19
Bhaskar Reddy Page 20 12/7/2021
BLOCKRECOVER TBD
CORRUPTION ....
BLOCKRECOVER TBD
DATABASE ....
BLOCKRECOVER TBD
DATAFILECOPY ....
BLOCKRECOVER TBD
DELETE ....
20
Bhaskar Reddy Page 21 12/7/2021
BLOCKRECOVER TBD
DEVICE ....
?
TBD
BLOCKRECOVER FROM ....
BLOCKRECOVER TBD
NOFILEUPDATE ....
BLOCKRECOVER TBD
NOPARALLEL ....
BLOCKRECOVER TBD
NOREDO ....
?
BLOCKRECOVER PREVIEW TBD
21
Bhaskar Reddy Page 22 12/7/2021
....
?
?
TBD
BLOCKRECOVER SAVE ....
?
TBD
BLOCKRECOVER SAVE ....
BLOCKRECOVER TABLESPACE SYSTEM DBA 4194404, 4194405 RESTORE UNTIL TIME 'SYSDATE-2';
BLOCKRECOVER CORRUPTION LIST
BACKUP VALIDATE DATABASE;
BLOCKRECOVER CORRUPTION LIST;
22
Bhaskar Reddy Page 23 12/7/2021
TBD
BLOCKRECOVER TEST ....
?
TBD
BLOCKRECOVER UNDO ....
BLOCKRECOVER TBD
VALIDATE ....
CATALOG
Adds information about file copies and user-managed backups to the repository
CATALOG ARCHIVELOG
Back the named archive log
23
Bhaskar Reddy Page 24 12/7/2021
?
TBD
CATALOG CLONE ...
Specifies that the datafile copy should be recorded as a level 0 incremental backup (0 is the only valid value of LEVEL)
RMAN> CATALOG DATAFILECOPY '/stage/users01.dbf';
DATAFILECOPY RMAN> CATALOG DATAFILECOPY '/u02/backup/users01.bak' LEVEL 0;
<file_name_list> LEVEL RMAN> LIST COPY;
<integer>
Catalog the Backup Pieces held in the location set by DB_RECOVERY_FILE_DEST
CATALOG RMAN> CATALOG DB_RECOVERY_FILE_DEST;
DB_RECOVERY_FILE_DES
T
?
TBD
CATALOG DEVICE ...
24
Bhaskar Reddy Page 25 12/7/2021
<path_name>
[NOPROMPT]
CHANGE
To make the following changes:
To change the status of backups, copies, and archived logs in the repository to AVAILABLE or UNAVAILABLE. This
feature is useful when a previously unavailable file is made available again, or you do not want a specific backup or copy to be
eligible to be restored but also do not want to delete it.
To alter the repository status of usable backups and copies from prior incarnations.
To remove catalog records for backups and copies, and update the corresponding records in the target control file to
status DELETED. This feature is useful when you remove a file by using an operating system command rather than the RMAN
CHANGE command, and want to remove its repository record as well.
To specify that a backup or copy should either abide by the currently configured retention policy or be exempt from it.
CHANGE ARCHIVELOG
Move all archived logs to a new directory, uncatalog them, and then recatalog them in the new location
CHANGE ARCHIVELOG ... HOST 'mv $ORACLE_HOME/oradata/trgt/arch/* /fs2/arch';
CHANGE ARCHIVELOG ALL UNCATALOG;
CATALOG START WITH '/fs2/arch';
Change the status of all backups of server parameter files created more than a day ago to UNAVAILABLE
CHANGE BACKUP ... CHANGE BACKUP OF SPFILE COMPLETED BEFORE 'SYSDATE-1' UNAVAILABLE;
25
Bhaskar Reddy Page 26 12/7/2021
CHANGE TBD
CHANGEFAILURE ...
CHANGE TBD
CONTROLFILECOPY ...
?
TBD
CHANGE COPY ...
CHANGE TBD
DATAFILECOPY ...
?
CHANGE TBD
DB_UNIQUE_NAME_FROM
...
CONFIGURE
To configure persistent settings affecting RMAN backup, restore, duplication, and maintenance jobs. These configurations are in
effect for any RMAN session until the configuration is cleared or changed.
Configuration Defaults
$ rman
26
Bhaskar Reddy Page 27 12/7/2021
RMAN> CONFIGURE
ARCHIVELOG BACKUP
COPIES FOR DEVICE TYPE
DISK TO 1;
RMAN> CONFIGURE
ARCHIVELOG DELETION
POLICY TO NONE;
RMAN> CONFIGURE
BACKUP OPTIMIZATION
OFF;
RMAN> CONFIGURE
CONTROLFILE
AUTOBACKUP OFF;
RMAN> CONFIGURE
CONTROLFILE
AUTOBACKUP FORMAT
FOR DEVICE TYPE DISK
TO '%F';
RMAN> CONFIGURE
DATAFILE BACKUP COPIES
FOR DEVICE TYPE DISK
TO 1;
RMAN> CONFIGURE
DEFAULT DEVICE TYPE TO
DISK;
RMAN> CONFIGURE
DEVICE TYPE DISK
PARALLELISM 1 BACKUP
TYPE TO BACKUPSET;
RMAN> CONFIGURE
ENCRYPTION FOR
DATABASE OFF;
27
Bhaskar Reddy Page 28 12/7/2021
RMAN> CONFIGURE
ENCRYPTION ALGORITHM
'AES128';
RMAN> CONFIGURE
MAXSETSIZE TO 2 G;
RMAN> CONFIGURE
RETENTION POLICY TO
REDUNDANCY 1;
RMAN> CONFIGURE
SNAPSHOT CONTROLFILE
NAME TO
'/app/oracle/product/flash
_recovery_area/snapshot.
ctl';CONFIGURE
AUXILIARY
?
CONFIGURE AUXILIARY RMAN> CONFIGURE AUXILARY
CHANNEL <DEVICE,
INTEGER> ....
28
Bhaskar Reddy Page 29 12/7/2021
INTEGER> <configuration
RMAN> CONFIGURE CLONENAME
Enable autobackup and configure the default autobackup format for a DISK device
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE
AUTOBACKUP CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u02/%F';
?
CONFIGURE TBD
DB_UNIQUE_NAME
'<db_unique_name>'
<CLEAR | CONNECT CONFIGURE ENCRYPTION ALGORITHM <CLEAR | encryption_algorithm>
IDENTIFIER
'<quoted_string>'>
SQL> col algorithm_name format a20
29
Bhaskar Reddy Page 30 12/7/2021
CONNECT
Creates a connection between RMAN and a target, auxiliary, or recovery catalog database
Auxiliary
CONNECT AUXILIARY $ rman auxiliary oracle/oracle1@prodb
<user_id>/<password>@
<instance> CONNECT
$ rman
RMAN> connect catalog repoomega/oracle1@repos
CONNECT TARGET <user_id>/<password>@<instance>
$ rman target /
30
Bhaskar Reddy Page 31 12/7/2021
$ rman>
RMAN> connect target / catalog repoomega/oracle1@repos
CONNECT
$ rman target / catalog repoomega/oracle1@repos
$ rman>
RMAN> connect target / catalog repoomega/oracle1@repos
CONNECT
$ rman
CONVERT
Converts a datafile, tablespace or database to the format of a destination platform, in preparation for transport across different
platforms
CONVERT DATABASE
Uses CONVERT DATABASE NEW DATABASE to convert datafiles and generate a transport script
CONVERT DATABASE NEW CONVERT DATABASE
DATABASE '<db_name>' NEW DATABASE 'prodb'
TRANSPORT SCRIPT TRANSPORT SCRIPT '/tmp/convertdb/transportscript'
'<script_location>' TO PLATFORM 'Linux IA (64-bit)'
TO PLATFORM DB_FILE_NAME_CONVERT '/u01/oradata', '/stage/dbfiles';
'<platform_name>'
DB_FILE_NAME_CONVERT
'<source_location>
<destination_location>'
31
Bhaskar Reddy Page 32 12/7/2021
Converts the datafiles to be transported to the destination host format and deposits the results in /u02/oradata
CONVERT DATAFILE CONVERT DATAFILE
<datafile_name_list> '/tmp/transport_from_aix/u01/uwdata01.dbf',
DB_FILE_NAME_CONVERT '/tmp/transport_from_aix/u01/uwdata02.dbf',
'<source_location> '/tmp/transport_from_aix/u03/users01.dbf',
<destination_location>' '/tmp/transport_from_aix/u03/users02.dbf'
FROM PLATFORM DB_FILE_NAME_CONVERT
<original_platform_name '/app/oracle/product/oradata','/stage/oradata',
> '/tmp/transport_from_solaris/hr','/stage/oradata'
FROM PLATFORM 'Linux IA (64-bit)';
COPY
?
COPY ARCHIVELOG ... RMAN> COPY ARCHIVELOG
(level, nochecksum,
nokeep, reuse, tag) COPY BACKUP ...
32
Bhaskar Reddy Page 33 12/7/2021
CREATE
CREATE CATALOG
33
Bhaskar Reddy Page 34 12/7/2021
Creates a stored script called backup_whole that backs up the database and archived redo logs
CREATE [GLOBAL] SCRIPT CREATE SCRIPT backup_whole
'<script_name>' COMMENT "backup whole database and logs"
COMMENT '<comment>' {
{RMAN_command_list} BACKUP INCREMENTAL LEVEL 0 TAG b_whole_l0
FROM FILE '<file_name>' DATABASE PLUS ARCHIVELOG;
}
CREATE GLOBAL SCRIPT global_backup_db
COMMENT "backup any database from the recovery catalog, with logs"
{
BACKUP DATABASE PLUS ARCHIVELOG;
}
CROSSCHECK
Verify the status of backups and copies recorded in the RMAN repository against media such as disk or tape. The CROSSCHECK
command only processes files created on the same device type as the channels running the crosscheck.
Status Description
The Object is available for use by RMAN. For a backup set to be AVAILABLE, all set backup pieces must be
AVAILABLE
AVAILABLE.
Object is not found either in file system (for DISK) or in the media manager (for sbt). Note that for a backup
EXPIRED set to be EXPIRED, all backup pieces in the set must be EXPIRED. EXPIRED does not mean the same as
OBSOLETE.
UNAVAILABLE Object is not available for use by RMAN. For a backup set to be UNAVAILABLE, all backup pieces must be
34
Bhaskar Reddy Page 35 12/7/2021
UNAVAILABLE.
The following objects can be crosschecked:
ARCHIVELOG BACKUP BACKUPPIECE BACKUPSET CONTROLFILECOPY COPY DATAFILECOPY PROXY
CROSSCHECK ARCHIVELOG
Allocate a channel, crosscheck backups in a date range and release the channel after use
CROSSCHECK BACKUP .... RMAN> RUN {
ALLOCATE CHANNEL d1 FOR MAINTENANCE DEVICE TYPE DISK;
CROSSCHECK BACKUP DEVICE TYPE DISK COMPLETED BETWEEN '01-JUL-08' AND '30-SEP-08';
RELEASE CHANNEL;
}
35
Bhaskar Reddy Page 36 12/7/2021
Checks for the physical existence of archivelog files and will change the V$ARCHIVED_LOG.STATUS of affected archivelogs
from "A" for AVAILABLE to "X" for EXPIRED. Once the archivelog file has a status of X, RMAN will no longer attempt to backup
this archivelog file.
RMAN> CROSSCHECK COPY OF ARCHIVELOG ALL;
CROSSCHECK COPY ...
DEBUG
Commands for the RMAN debugger
DEBUG <AFFINITY | ALL | *RMAN> DEBUG ALL;
DUPLICATE | IO | KRB | *RMAN> DEBUG OFF;
36
Bhaskar Reddy Page 37 12/7/2021
37
Bhaskar Reddy Page 38 12/7/2021
RMAN> DELETE NOPROMPT EXPIRED BACKUPSET OF TABLESPACE uwdata DEVICE TYPE disk
COMPLETED BEFORE SYSDATE-15;
Delete Obsolete
DELETE [FORCE | RMAN> DELETE FORCE OBSOLETE;
NOPROMPT] OBSOLETE
[obsOperandList]
[device_type]
[device_specifier];
Deletes a stored script b_whole_10 from the recovery catalog
rman TARGET / CATALOG rman/cat@catdb
DELETE [GLOBAL] SCRIPT RMAN> DELETE SCRIPT b_whole_10;
'<script_name>' RMAN> DELETE GLOBAL SCRIPT b_whole_10;
Drop
DROP CATALOG
Drop the RMAN catalog
*See CREATE CATALOG Demo Above
DROP CATALOG;
38
Bhaskar Reddy Page 39 12/7/2021
DUPLICATE
EXIT
or
39
Bhaskar Reddy Page 40 12/7/2021
RMAN> HOST;
*$ EXIT;
RMAN>
FLASHBACK DATABASE
Returns the database to its state at a previous time or SCN
GRANT
Grant privileges to a recovery catalog user
*RMAN> GRANT CATALOG FOR DATABASE orabase TO repoomega;
GRANT <privilege> TO *RMAN> GRANT REGISTER DATABASE TO repoomega;
<schema_name>
HOST
Shell out of RMAN to the operating system for command execution
*See EXIT Demo Above
HOST
IMPORT
IMPORT CATALOG
Imports the metadata from one recovery catalog into a different recovery catalog
?
?
40
Bhaskar Reddy Page 41 12/7/2021
?
?
LIST
PRINT SCRIPT
Display a stored script
PURGE
?
See "CREATE SCRIPT" Demos Above
PURGE
QUIT
Exit the RMAN executable
*RMAN> QUIT;
QUIT
41
Bhaskar Reddy Page 42 12/7/2021
RECOVER
Apply redo logs and incremental backups to datafiles or data blocks restored from backup or datafile copies, in order to update
them to a specified time
TBD
RECOVER
REGISTER DATABASE
Register a Target in the Database
Recovery Catalog
*RMAN> REGISTER DATABASE;
REGISTER DATABASE
RELEASE CHANNEL
Release a channel that was allocated with an ALLOCATE CHANNEL command or ALLOCATE CHANNEL FOR MAINTENANCE
command
See ? Demo Above
RELEASE CHANNEL
REPAIR FAILURE
Repair one or more failures recorded in the automated diagnostic repository
REPAIR FAILURE [<NO | *See Advise Failure Demo Above
NOPROMPT | PREVIEW |
USING>
REPLACE SCRIPT
Replace an existing script stored in the recovery catalog. If the script does not exist, then REPLACE SCRIPT creates it
TBD
REPLACE SCRIPT
REPORT
42
Bhaskar Reddy Page 43 12/7/2021
RESET DATABASE
Reset the incarnation of the target database in the RMAN repository to a previous database incarnation
RESET DATABASE TO $ rman target / nocatalog
INCARNATION RMAN> STARTUP NOMOUNT;
<incarnation_identifier>; RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;
RMAN> ALTER DATABASE MOUNT;
RMAN> LIST INCARNATION OF DATABASE orabase;
RMAN> RESET DATABASE TO INCARNATION 1;
RMAN> RESTORE DATABASE UNTIL SCN 4208974;
RMAN> RECOVER DATABASE UNTIL SCN 4208974;
RMAN> ALTER DATABASE OPEN RESETLOGS;
RMAN> LIST INCARNATION OF DATABASE orabase;
RESTORE
Restore files from backup sets or from disk copies to the default or a new location
RESTORE RMAN> target / catalog rman/rman@rman
43
Bhaskar Reddy Page 44 12/7/2021
SQL> COMMIT;
RESYNC
Perform a full resynchronization, which creates a snapshot control file and then copies any new or changed information from
that snapshot control file to the recovery catalog.
This example performs a full resynchronization of the target database after archiving all unarchived redo logs
RESYNC CATALOG FROM
CONTROLFILECOPY
'<file_name>'
RESYNC FROM
DB_UNIQUE_NAME ALL
$ rman target /
RESYNC FROM RMAN> STARTUP FORCE MOUNT;
DB_UNIQUE_NAME RMAN> RESYNC CATALOG FROM CONTROLFILECOPY '/u01/cfile.dbf';
'<db_unique_name>'Mou RMAN> ALTER DATABASE OPEN;
nt the target database,
update the repository in
the current control file
with metadata from a
backup control file, then
open the database
After adding a datafile to *RMAN> RESYNC CATALOG;
an existing tablespace
Revoke
Revoke privileges from a recovery catalog user
44
Bhaskar Reddy Page 45 12/7/2021
TBD
REVOKE
Run
Execute a script of RMAN commands
RUN { See "Allocate A Single Backup Channel" Demo Above
<script commands>
}
Send
Send a vendor-specific quoted string to one or more specific channels
SEND CHANNEL
Specify commands by CHANNEL
SEND CHANNEL TBD
'<channel_id>'
'<command_string>'
PARMS
'<channel_params>'
Specify a tape drive for a backup of the users tablespace to Oracle Secure Backup
SEND DEVICE_TYPE RUN
'<device_specifier>' {
'<command_string>' ALLOCATE CHANNEL c1 DEVICE TYPE sbt;
PARMS SEND 'OB_DEVICE stape1';
'<channel_params>' BACKUP TABLESPACE users;
}
Set
Set the value of various attributes that affect RMAN behavior for the duration of a RUN block or a session
45
Bhaskar Reddy Page 46 12/7/2021
?
SET <OFF | ON> [FOR ALL TBD
TABLESPACES]
SET ARCHIVELOG DESTINATION TO '<
SET BACKUP COPIES <integer>
SET COMPRESSION ALGORITHM '<compression_algorithm_name>'
SET DECRYPTION IDENTIFIED BY <password>
SET ECHO <ON | OFF>
SET ENCRYPTION ALGORITHM '<algorithm_name>'
SET IDENTIFIED BY <password> [ONLY]
SET MAXCORRUPT FOR DATAFILE <dataFileSpec> TO <integer>
SET NEWNAME FOR DATAFILE <dataFileSpec> TO '<file_name>'
SET NEWNAME FOR DATAFILE <dataFileSpec> TO NEW
SET NEWNAME FOR TEMPFILE <tempFileSpec> TO '<quoted_string>'
SET NEWNAME FOR TEMPFILE <tempFileSpec> TO NEW
SET TO RESTORE POINT <restore_point_name>
SET UNTIL <TIME | SCN>
CONFIGURE ARCHIVELOG COPIES FOR DEVICE TYPE sbt TO 3;
CONFIGURE DATAFILE COPIES FOR DEVICE TYPE sbt TO 3;
RMAN> run {
ALLOCATE CHANNEL dev1 DEVICE TYPE sbt
PARMS 'ENV=(OB_DEVICE_1=stape1,OB_DEVICE_2=stape2)';
* SET BACKUP COPIES 2;
BACKUP DATABASE PLUS ARCHIVELOG;
}
RMAN> run {
SET UNTIL TIME = "TO_DATE('03/15/08 10:42:07','MM/DD/RR HH24:MI:SS')";
RESTORE DATABASE;
RECOVER DATABASE;
}
SET AUXILIARY INSTANCE PARAMETER FILE TO '<file_name>
46
Bhaskar Reddy Page 47 12/7/2021
RMAN> RUN {
ALLOCATE CHANNEL t1 DEVICE TYPE sbt;
RESTORE SPFILE FROM AUTOBACKUP;
}
RMAN> RUN {
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u02/cf_%F.bak';
RESTORE CONTROLFILE FROM AUTOBACKUP MAXSEQ 100;
}
47
Bhaskar Reddy Page 48 12/7/2021
Show
All
$ rman target / catalog repoomega1/oracle1@repos
ALL RMAN> show all;
AUXNAME
$ rman target / catalog repoomega1/oracle1@repos
RMAN> show auxname;
{DATAFILE | ARCHIVELOG} BACKUP COPIES
$ rman target / catalog repoomega1/oracle1@repos
RMAN> show datafile backup copies;
RMAN> show archivelog backup copies;
BACKUP OPTIMIZATION
$ rman target / catalog repoomega1/oracle1@repos
RMAN> show backup optimization;
[AUXILIARY] CHANNEL [FOR DEVICE TYPE <deviceSpecifier>]
$ rman target / catalog repoomega1/oracle1@repos
RMAN> show channel;
CONTROLFILE AUTOBACKUP [FORMAT]
$ rman target / catalog repoomega1/oracle1@repos
RMAN> show controfile autobackup;
CONTROLFILE AUTOBACKUP FORMAT <format mask>
$ rman target / catalog repoomega1/oracle1@repos
48
Bhaskar Reddy Page 49 12/7/2021
Shutdown
Shutdown the target database
49
Bhaskar Reddy Page 50 12/7/2021
SQL
Startup
Startup a Database
STARTUP <DBA | FORCE | $ rman TARGET / CATALOG repoomega/oracle1@repos
MOUNT | NOMOUNT>
RMAN> STARTUP MOUNT;
STARTUP PFILE
'<file_name>'
50
Bhaskar Reddy Page 51 12/7/2021
Switch
Specify that a datafile copy is now the current datafile, that is, the datafile pointed to by the control file. This command is
equivalent to the SQL statement ALTER DATABASE RENAME FILE as it applies to datafiles
Switch the controlfile to point to an ImageCopy of the data file
51
Bhaskar Reddy Page 52 12/7/2021
TBD
SWITCH TEMPFILE ALL
TBD
Transport Tablespace
Create transportable tablespace sets from backup for one or more tablespaces
TBD
TRANSPORT TABLESPACE
Unregister
Upgrade Catalog
Upgrade the recovery catalog schema from an older version to the version required by RMAN
RMAN> UPGRADE CATALOG;
UPGRADE CATALOG
Validate
Examine a backup set and report whether its data is intact. RMAN scans all of the backup pieces in the specified backup sets
and looks at the checksums to verify that the contents can be successfully restored
52
Bhaskar Reddy Page 53 12/7/2021
Validate archivelogs
VALIDATE ARCHIVELOG RMAN> VALIDATE ARCHIVELOG ALL;
ALL
VALIDATE ARCHIVELOG
LIKE '<string_pattern>'
VALIDATE ARCHIVELOG
FROM SCN <integer>
VALIDATE ARCHIVELOG
BETWEEN SCN <integer>
AND SCN <integer>
VALIDATE ARCHIVELOG
UNTIL SCN <integer>
VALIDATE ARCHIVELOG
FROM SEQUENCE
<integer> [THREAD
<integer>]
VALIDATE ARCHIVELOG VALIDATE BACKUPSET <primaryKey>
SEQUENCE <integer>
[THREAD <integer>]
VALIDATE ARCHIVELOG
SEQUENCE BETWEEN
<integer> AND <integer>
VALIDATE ARCHIVELOG
UNTIL SEQUENCE
<integer> [THREAD
<integer>]
TIME BETWEEN
'<date_string>' AND
'<date_string>'
UNTIL TIME
'<date_string>'
TBD
VALIDATE CONTROLFILECOPY ALL
53
Bhaskar Reddy Page 54 12/7/2021
54
Bhaskar Reddy Page 55 12/7/2021
RMAN Demos
55
Bhaskar Reddy Page 56 12/7/2021
COMPRESSED
BACKUPSET; # default
RMAN> CONFIGURE
DATAFILE BACKUP COPIES
FOR DEVICE TYPE DISK
TO 1;
RMAN> CONFIGURE
ARCHIVELOG BACKUP
COPIES FOR DEVICE TYPE
DISK TO 1;
RMAN> CONFIGURE
MAXSETSIZE TO 2 G;
RMAN> CONFIGURE
ARCHIVELOG DELETION
POLICY TO NONE;
RMAN> CONFIGURE
SNAPSHOT CONTROLFILE
NAME TO
'/u01/app/oracle/product/
10.1.0.3/dbs/snapcf_pnbd
b.f';
Incremental Level 0
Backup
#!/bin/sh
Incremental #####################################################
# script to take a rman full backup
# this script must be run
# as the trusted user 'oracle10g' 'oracle9i' etc
#####################################################
# create output logs with that number and the current date in the ./rman/logs directory age out in
14-30 days
# get env IMPORTANT, if multiple Oracle SID's the env var ORACLE_SID must be set
56
Bhaskar Reddy Page 57 12/7/2021
. /etc/bashrc
export ORACLE_BASE=/u01/app/oracle;
export ORACLE_HOME=$ORACLE_BASE/product/10.1.0.3;
export ORACLE_SID=pnbdb;
export LD_LIBRARY_PATH=/u01/app/oracle/product/10.1.0.3/lib:/lib:/usr/lib;
# set relative head of directory (work disk is u03, oracle disk is u01)
HEAD=/u03
WORK=$HEAD/backup/scripts
cd $WORK
# unique logfile
DATE=`date +"%Y%m%d-%H%M%S"`
LOGFILE='/u03/backup/rman/logs/rman_full_backup_'${DATE}'.log'
echo "log: "${LOGFILE} > $LOGFILE
echo "Started " >> $LOGFILE
date >> $LOGFILE
echo instance $ORACLE_SID >> $LOGFILE
#############################################################
#############
${ORACLE_HOME}/bin/rman @${WORK}/rman_full.rcv >> $LOGFILE
returncode=$?
echo $returncode return code >> $LOGFILE
df >> $LOGFILE
echo "Ended " >> $LOGFILE
date >> $LOGFILE
57
Bhaskar Reddy Page 58 12/7/2021
RAC Demo
Crosschecking on Multiple Nodes of an Oracle Real Application Clusters Configuration: Example In this example, you perform a
crosscheck of backups on two nodes of an Oracle Real Application Clusters configuration, where each node has access to a
subset of backups. It is assumed here that all backups are accessible by at least one of the two nodes used in the crosscheck.
Any backups not accessible from at least one of the nodes are marked EXPIRED after the crosscheck.
?
SELECT
recovery_estimated_ios,
actual_redo_blks,
target_redo_blks,
target_mttr,
estimated_mttr
FROM
gv$instance_recovery;
SELECT * FROM
v_$recovery_file_dest;
58
Bhaskar Reddy Page 59 12/7/2021
cd
/app/oracle/product/Oracl
eHomes/oradata/orcl
ls -la
cd
/app/oracle/product/Oracl
eHomes/admin/orcl/bdum
p
tail alert_orcl.log
rm control02.ctl
ls -la
tail alert_orcl.log
-- no one knows anything
bad has happened
59
Bhaskar Reddy Page 60 12/7/2021
RUN {
STARTUP FORCE
60
Bhaskar Reddy Page 61 12/7/2021
NOMOUNT;
RESTORE CONTROLFILE;
ALTER DATABASE
MOUNT;
RESTORE DATABASE;
RECOVER DATABASE;
}
rman done
-- look at
/app/oracle/OracleHomes/
oradata/orcl
conn / as sysdba
shutdown immediate;
61
Bhaskar Reddy Page 62 12/7/2021
startup
tail alert_orcl.log
-- next dumped
controlfiles 1 and 3
shutdown immediate fails
shutdown abort
connect to RMAN
Backup and Recovery Practices Best Practices
Metalink Note: 388422.1
1. Turn on block
62
Bhaskar Reddy Page 63 12/7/2021
checking
REASON: The aim is to
detect, very early the
presence of corrupt blocks
in the database. This has
a slight performance
overhead, but Checksums
allow Oracle to detect
early corruption caused by
underlying disk, storage
system, or I/O system
problems.
2. Turn on block
tracking when using
RMAN backups (if
running 10g or above)
REASON: This will allow
RMAN to backup only
those blocks that have
changed since the last full
backup, which will reduce
the time taken to back up,
as less blocks will be
backed up.
63
Bhaskar Reddy Page 64 12/7/2021
e_tracking.f’;
3. Duplex log groups
and members and have
more than one archive
log dest
REASON: If an archivelog
is corrupted or lost, by
having multiple copies in
multiple locations, the
other logs will still be
available and could be
used.
64
Bhaskar Reddy Page 65 12/7/2021
head/tail checksumming.
This is the best way to
ensure that you will get a
good backup.
65
Bhaskar Reddy Page 66 12/7/2021
66
Bhaskar Reddy Page 67 12/7/2021
REASON: crosschecking
will check that the
catalog/controlfile
matches the physical
backups. If a backup is
missing, it will set the
piece to 'EXPIRED' so
when a restore is started,
that it will not be eligible,
and an earlier backup will
be used. To remove the
expired backups from the
catalog/controlfile use the
delete expired command.
RMAN> crosscheck
backup;
RMAN> delete expired
backup;
8. Prepare for loss of
controlfiles set
autobackup on
REASON: This will ensure
that you always have an
up to date controlfile
available that has been
67
Bhaskar Reddy Page 68 12/7/2021
RMAN> configure
controlfile autobackup on;
68
Bhaskar Reddy Page 69 12/7/2021
69