Directory
1 database modified to Automatic archive mode
2 Modifying Rman parameters
3 Rman Automatic backup script
4 Set up system automatic backup parameters
5 Rman Restore
Restore the entire database
Recover a single table space
1 database modified to Automatic archive mode.
Why is it set to Automatic archive mode? The main reason is that if you do not set it to Automatic archive mode, you need to modify the database to the Mount state instead of the open state when using Rman. The automatic archive mode is available for hot standby in open use. Here are the steps to modify the automatic archive mode:
1 Sqlplus/as sysdba into the database (local)
2 Archive Log list (see whether it is an automatic archive mode.) )
The non-archive mode shown below
sql> archive log list;
Database log mode No Archive mode
Automatic Archival Disabled
Archive Destination Use_db_recovery_file_dest
Oldest online log sequence 25
Current log Sequence 27
3 shutdown immediate; Close database
4 startup mount to mount status
5 ALTER DATABASE Archivelog; modified to archive mode
6 ALTER DATABASE open;
7 Archive Log list production to see if it starts successfully
The following are displayed after successful startup
sql> archive log list;
Database Log Mode Archive mode
Automatic Archival Enabled
Archive Destination Use_db_recovery_file_dest
Oldest online log sequence 25
Next Log sequence to archive 27
Current log Sequence 27
2 Modifying Rman parameters
Landing Rman
Rman Target Rman/rman
Configuration in Oracle 9i
Use Rman>show all;
The Rman configuration parameters can be displayed as follows:
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 ' c:oracle. Sncftest. ORA '; #default
The following is the definition of each parameter
1. Configure retention Policy to redundancy 1:
is used to determine that the backup is no longer needed, it has a total of three options, respectively
CONFIGURE RETENTION POLICY to RECOVERY windows of 7 days;
CONFIGURE RETENTION POLICY to redundancy 5;
CONFIGURE RETENTION POLICY to NONE;
The first recover window is to maintain all sufficient backups to restore the database system to any time in the last seven days. Any database backup that exceeds the last seven days will be marked as obsolete.
The second type of redundancy is to maintain the latest 5 database backups that can be recovered, and any backups exceeding the latest 5 will be marked as redundancy. Its default value is 1 copies.
The third does not need to maintain the policy, clear will revert back to the default retention policy.
The safest way to do this is to use the second retention strategy.
2. CONFIGURE BACKUP Optimization off
The default is off, and if opened, Rman will perform an optimized algorithm for the backed-up data files and files.
3. Configure default device type to disk:
Is the device type that specifies all I/O operations is a hard disk or a tape, and the default is a hard disk
The setting of the tape is configure DEFAULT DEVICE TYPE to SBT;
4. CONFIGURE Controlfile autobackup off
Force the database to automatically back up files after backing up files or executing commands that alter the structure of the database, and the default value is off. This prevents the control files from being recovered after the control files and catalog are lost.
5. CONFIGURE controlfile autobackup FORMAT for DEVICE TYPE DISK to '%F '
is the backup path and backup format of the configuration control file
6. CONFIGURE DEVICE TYPE DISK PARALLELISM 1;
is the degree of parallelism that configures the database device type.
7. CONFIGURE datafile BACKUP copies for DEVICE TYPE DISK to 1;
is to configure the copy quantity of each backup of the database, and each backup of Oracle can have multiple copies of the exact same copy.
8. CONFIGURE Archivelog BACKUP copies for DEVICE TYPE DISK to 1
is the type of storage device that sets up the archive log for the database
9. CONFIGURE SNAPSHOT controlfile NAME to ' c:oracle ... Sncftest. ORA '
is the location and file name of the snapshot file for the configuration control file, which was generated during the backup to control the read consistency of the file.
10. CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT ' c:...%d_db_%u_%s_%p ';
is to configure backup paths and backup formats for backup files
CONFIGURE CHANNEL DEVICE TYPE DISK Clear; Used to clear the channel configuration above
CONFIGURE EXCLUDE for tablespace <tablespace> [clear]; Use this command to not back up the specified tablespace to a backup set, which is useful for read-only tablespace.
1. Store the backup file to the specified path, such as E:\BACKUPB
Configure channel device type disk format ' e:\backupb\%d_db_%u ';
The%d_db_%u behind is the storage format
2. We can also specify that control file be stored in another path: such as E:\backupcontrol
Configure Controlfile autobackup format for device type disk to ' E:\backupcontrol\%F ';
The%f behind is the storage format
================
Common Configure command in Rman 2007-06-21 15:37
1 displaying the current configuration information
===========================
1.01 rman> Show All;
1.02 query Rman Set the non-default value:
Sql> select Name,value from V$rman_configure;
2. Commonly used Configure options
===========================
2.01 Save policy (retention policy)
Configure retention policy to recovery windows of 3 days;
Configure retention policy to redundancy 3;
Configure retention policy clear;
2.02 Backup optimization Optimization backup
Configure backup optimization on;
Configure backup optimization off;
Configure backup optimization clear;
2.03 Default Device device type
Configure default device type to disk;
Configure default device type to STB;
Configure default device type clear;
2.04 Control File Controlfile
Configure Controlfile autobackup on;
Configure Controlfile autobackup format for device type disk to '/cfs01/backup/conf/conf_%f ';
Configure Controlfile Autobackup clear;
Configrue controlfile autobackup format for device type disk clear;
Configrue snapshot controlfile name to '/CFS01/BACKUP/SNAPCF/SCONTROFILE.SNP ';
Configrue snapshot controlfile name clear;
2.05 parallel number (channel number) device type DISK|STB pallelism n;
Configure device type DISK|STB parallelism 2;
Configure device type DISK|STB clear;
Configure channel device type disk format ' e/:rmanback_%u ';
Configure channel device type disk maxpiecesize 100m
Configure channel device type disk rate 1200K;
Configure Channel 1 device type disk format ' e/:rmanback_%u ';
Configure Channel 2 device type disk format ' e/:rmanback_%u ';
Configure Channel 1 device type disk maxpiecesize 100m
Configure Channel 1 device type Disk Clear
Configure Channel 2 device type disk clear;
2.06 build backup copy datafile|archivelog backup copies
Configure DataFile backup copies for device type DISK|STB to 3;
Configure Archivelog backup copies for device type DISK|STB to 3;
Configure Datafile|archivelog backup copies for device type DISK|STB clear
BACKUP DEVICE TYPE DISK DATABASE
FORMAT '/disk1/backup/%u ', '/disk2/backup/%u ', '/disk3/backup/%u ';
2.07 exclusion options Exclude
Configure exclude for tablespace ' users ';
Configrue exclude clear;
2.08 Backup set Size Maxsetsize
Configure Maxsetsize to 1g|1000m|1000000k|unlimited;
Configure Maxsetsize Clear;
2.09 Other Options Auxiliary
CONFIGURE Auxname for datafile 1 to '/oracle/auxfiles/aux_1.f ';
CONFIGURE Auxname for datafile 2 to '/oracle/auxfiles/aux_2.f ';
CONFIGURE Auxname for datafile 3 to '/oracle/auxfiles/aux_3.f ';
CONFIGURE Auxname for datafile 4 to '/oracle/auxfiles/aux_4.f ';
-
CONFIGURE Auxname for datafile 1 clear;
CONFIGURE Auxname for datafile 2 clear;
CONFIGURE Auxname for datafile 3 clear;
CONFIGURE Auxname for datafile 4 clear;
---------------------------
% in the format of Rman
Number of copies of%c backup slice
%d database name
%d The day ordinal of the month (DD)
%m in the month ordinal of the year (MM)
%F a unique name based on dbid, in the form of C-IIIIIIIIII-YYYYMMDD-QQ, where IIIIIIIIII is the DBID,YYYYMMDD for the database
Date, QQ is a sequence of 1-256
%n database name, fill to the maximum eight characters to the right
%u a eight-character name represents the backup set and the creation time
%p number of backup slices in this backup set, starting from 1 to the number of files created
%u a unique file name that represents%u_%p_%c
Number of the%s backup set
%t Backup set Timestamp
%T Month-day format (YYYYMMDD)
* The configuration situation of the Rman parameter:
Using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY to redundancy 7;
CONFIGURE BACKUP optimization on;
CONFIGURE DEFAULT DEVICE TYPE to DISK; # Default
CONFIGURE Controlfile autobackup on;
CONFIGURE controlfile autobackup FORMAT for DEVICE TYPE DISK to '/u01/app/oracle/backup/conf_%f ';
CONFIGURE DEVICE type DISK PARALLELISM 1 BACKUP type to backupset; # Default
CONFIGURE datafile BACKUP copies for DEVICE TYPE DISK to 1; # Default
CONFIGURE Archivelog BACKUP copies for DEVICE TYPE DISK to 1; # Default
CONFIGURE CHANNEL DEVICE TYPE DISK maxpiecesize M;
CONFIGURE maxsetsize to unlimited; # Default
CONFIGURE encryption for DATABASE off; # Default
CONFIGURE encryption algorithm ' AES128 '; # Default
CONFIGURE archivelog deletion POLICY to NONE; # Default
CONFIGURE SNAPSHOT Controlfile NAME to
'/u01/app/oracle/product/10.2.0/db_1/dbs/snapcf_ora10g.f '; # Default
It is recommended that these settings be cleared and returned to normal after removal.
CONFIGURE CHANNEL DEVICE TYPE ' sbt_tape ' clear;
3 Rman Automatic backup script
Full backup script
Rman Target/<<eof
run{
Allocate channel ' DEV1 ' type disk;
Backup full tag ' DBFULL_ORCL ' format '/u01/app/oracle/backup/fulldb_orcl%u_%p_%c ' database;
SQL ' alter system archive log current ';
Backup Filesperset 3 archivelog all delete input;
Release channel Dev1;
}
Incremental backups:
Level 0 Backup script:
#set porfile_env
Export oracle_sid=ora10g
# Rman Level0 Backup
Rman log= '/u01/app/oracle/rmandir/log/db1_rman.log ' append <<eof
Connect target/;
Run
{
Allocate channel C1 type disk;
Backup incremental level=0 database format '/u01/app/oracle/backup/db1_level0_%u ' tag= ' level0 ';
SQL ' alter system archive log current ';
Backup Archivelog all format '/u01/app/oracle/log/db1_arch_%u ' delete input;
Release channel C1;
}
Eof
Level 1 Backup Script
# set Porfile_env
Export oracle_sid=ora10g
# Rman Level0 Backup
Rman log= '/u01/app/oracle/rmandir/log/db1_rman.log ' append <<eof
Connect target/;
Run
{
Allocate channel C1 type disk;
Backup incremental level=1 database format '/u01/app/oracle/backup/db1_level1_%u ' tag= ' level1 ';
SQL ' alter system archive log current ';
Backup Archivelog all format '/u01/app/oracle/log/db1_arch_%u ' delete input;
Release channel C1;
}
Eof
Level 2 Backup script:
# set Porfile_env
Export oracle_sid=ora10g
# Rman Level0 Backup
Rman log= '/u01/app/oracle/rmandir/log/db1_rman.log ' append <<eof
Connect target/;
Run
{
Allocate channel C1 type disk;
Backup incremental level=2 database format '/u01/app/oracle/backup/db1_level2_%u ' tag= ' level2 ';
SQL ' alter system archive log current ';
Backup Archivelog all format '/u01/app/oracle/log/db1_arch_%u ' delete input;
Release channel C1;
}
Eof
Check script:
Export oracle_sid=ora10g
Rman log= '/u01/app//oracle/log/rmancheck.log ' append <<eof
Connect target/;
Run
{
# Check Database
Backup validate check logical database;
# Check Backup Set
Restore database validate check logical;
}
Eof
Delete Expired backup file script:
Export oracle_sid=ora10g
Rman log= '/u01/app/oracle/log/rmandelset.log ' append <<eof
Connect target/;
Run
{
Delete NoPrompt obsolete;
}
Eof
4 Set up system automatic backup parameters:
Man incremental backup plan, the use of the script posted, easy to find later.
Crontab automatic scheduling. Set up an automatic execution plan to turn on the automatic backup control file function inside the Rman initialization environment
#crontab-E
0 1 * * 0 su–oracle-c/xxx/rmanlevel0.sh
Perform level 0 backups every Sunday 1:00
0 1 * * 1-3,5-6 su–oracle-c/xxx/rmanlevel2.sh
Perform level 2 incremental backups from Monday to Wednesday, Friday to Saturday 1:00
0 1 * * 4 su–oracle-c/xxx/rmanlevel1.sh
1-level incremental backups performed every Thursday 1:00
0 * * * 6 su-oracle-c/xxx/rmancheck.sh
Perform inspection at 616 O ' Week
0 * * * 0 su–oracle–c/xxx/rman_delete.sh
Delete expired backup data every Sunday 18:00
5 Rman Restore
The entire recovery process for RMAN can be divided into restoration (restore) and recovery (recover), meaning that they are
Very different, one refers to the physical meaning of the restoration and copy of the file, one refers to the recovery of database consistency, so,
The correct understanding of these two concepts helps to restore the database correctly.
For Rman backups, the restore operation can only be done with an Rman or Rman package, for recovery operations
is very flexible, in addition to Rman, can also be completed in the Sqlplus. Restore and restore a database, you can
To complete with the following two simple commands
Rman>restore database;
Rman>recover database;
Restore the entire database
You must have the database in an installed state (Mount state) before you restore the entire database
Sql>startup Mount
Rman Target/<<eof
Run {
Allocate channel ' DEV1 ' type disk;
Allocate channel ' dev2 ' type disk;
Allocate channel ' dev3 ' type disk;
Restore database;
Recover database;
Release channel Dev1;
Release channel Dev2;
Release channel Dev3;
}
Recover a single table space
Leave the tablespace in the state of the table space before the tablespace is restored (offline state)
Svrmgrl>alter tablespace users offline;
Rman Target/<<eof
Run {
Allocate channel ' DEV1 ' type disk;
Allocate channel ' dev2 ' type disk;
Allocate channel ' dev3 ' type disk;
Restore tablespace users;
Recover tablespace users;
Release channel Dev1;
Release channel Dev2;
Release channel Dev3;
}
Restoring a table space, or recovering a data file, may take less time to recover than to restore the database.
Rman> SQL "ALTER tablespace tools OFFLINE IMMEDIATE";
Rman> RESTORE tablespace tools;
Rman> RECOVER tablespace tools;
Rman> SQL "ALTER tablespace tools ONLINE";
For databases and data files, you can restore from the specified tag
Rman>restore datafile 1 from tag= ' TAG name '
For incomplete restores, such as Point-in-time restores, there may be only a full restore of the database.
Rman> RUN {
2> ALLOCATE CHANNEL C1 TYPE DISK;
3> ALLOCATE CHANNEL C2 TYPE DISK;
4> SET UNTIL time = ' 2002-12-09:11:44:00 ';
5> RESTORE DATABASE;
6> RECOVER DATABASE;
7> ALTER DATABASE OPEN resetlogs; }
Incomplete recovery can also be used with log-based recovery in Rman
Rman> RUN {
2> SET UNTIL SEQUENCE) THREAD 1;
3> ALTER DATABASE MOUNT;
4> RESTORE DATABASE;
5> RECOVER DATABASE; # recovers through log 119
6> ALTER DATABASE OPEN resestlogs;
7>}
If possible, you can also restore the data files to a new location
SET NEWNAME for DataFile
'/u01/oradata/tools01.dbf ' to '/tmp/tools01.dbf ';
RESTORE datafile '/u01/oradata/tools01.dbf ';
SWITCH datafile All;
In addition to restoring the database and data files, we can also restore the control files, which need to be started under Nomount, with the following
The command can be
14
Restore controlfile from ' file name '
Restore Controlfile from Autobackup
Restore controlfile from tag= ' ... '
Under normal circumstances, the recovery process will automatically look for the required archive log without recovering the archive log, but we can also
To specify where to restore.
SET archivelog destination to '/u02/tmp_restore ';
RESTORE Archivelog All;
If you are using a server parameter file (spfile), RMAN can back up the parameter file, and if a file corruption occurs, you can
To recover the SPFile parameter file with Rman, and to use the temporary parameter file of Rman to set up without the parameter file
Move the database to Nomount, execute the following command
Restore Controlfile from Autobackup
Restore controlfile from ' file name '
# Find/-name Rman
$ echo $PATH
$ sqlplus/as sysdba
sql> startup Mount;
sql> ALTER DATABASE Archivelog;
Sql> quit
$ rman
rman> Connect target///connection
rman> list backupset;//view backup
rman> Backu P database;//Backup command
rman> backup incremental level=0 database;//0 backup
rman> Backup incremental Level 1 Databas E Level 1 backup
rman> list backupset;
Rman> Show all; //view command parameters
Rman> quit
$ ls/u01/app/oracle/flash_ recovery_area/orcl/backupset/2012_07_14/
$/U01/APP/ORACLE/ORADATA/ORCL
$ strings control01.ctl//binaries