Rman recovery, like user-managed Backup recovery, is divided into full recovery and Incomplete recovery, all of which need to work in archivelog mode. After rman10g, only level 0 and Level 1 backups are retained. Level 1 backups can be divided into two modes: cumulative (Accumulative incremental) and differential (differential incremental, if no keyword is added, Incremental backup is Incremental backup by default: backup
Rman recovery, like user-managed Backup recovery, is divided into full recovery and Incomplete recovery, all of which need to work in archivelog mode. After rman10g, only level 0 and Level 1 backups are retained. Level 1 backups can be divided into two modes: cumulative (Accumulative incremental) and differential (differential incremental, if no keyword is added, Incremental backup is Incremental backup by default: backup
Rman recovery, like user-managed Backup recovery, is divided into full recovery and Incomplete recovery, all of which need to work in archivelog mode.
After rman10g, only level 0 and Level 1 backups are retained. Level 1 backups can be divided into two modes: cumulative (Accumulative incremental) and differential (differential incremental, if no keyword is added, incremental differential backup is used by default:
Backup incremental level 1 cumulative database (Accumulative incremental)
Backup incremental level 1 database (incremental differential)
Connection:
Rman
Connect target/
@/Mydir/lyg.txt
Or:
Rman @/mydir/lyg.txt
1. rman dump command:
When you use rman to restore the media, you must first run the restore command to dump the backup file. When you run the restore command, rman automatically dump the latest backup file.
Restore database: dump all data files in the database. When all data files in the database fail to be restored or incomplete recovery is executed, the restore database command should be used to dump all data files, this command can only be used in the mount status.
Restore tablespace: a data file used to dump a specific tablespace. If all the data files in a tablespace fail to be in the media and the database is in the open stage, the restore tablespace command should be used. This command can only be used in the open state.
Restore datafile: dump a specific data file. This command can be used either in the mount or open state.
Restore controlfile: this command is used to dump control files. When you execute Incomplete recovery based on control files or restore the database to the previous copy status, you must dump the control file, the restore controlfile command can only be used in nomount state.
Restore archivelog: dumping archived logs. Archive logs must be applied when full recovery and Incomplete recovery are performed. If the media fails to be archived or the image copy of the archive log does not exist, use the restore archivelog command to dump the archive log. Note that this command can be used in the mount status, it can also be used in the open state.
Restore spfile: The parameter file of the dump server. If a media failure occurs in the server parameter file, you can use the restore spfile command to dump the file. This command can only be used in nomount state.
2. rman recovery command:
When the restoration of media is performed, after the backup of the data file is dumped, archive logs must be applied to restore the data file. The restoration of the data file is completed using the recover command. When the restoration command is executed,Rman automatically applies all archived logs since the latest backup.
Recover database: Used to restore all data files in the database. When the restore database command is used to dump all data file backups, you should use the recover database command to execute recovery, note that this command can only be used in the mount status.
Recover tablespace: restore the data file of a specific tablespace. First, run the restore tablespace command to dump the data file, and then run the recover tablespace command to restore the data file. Note: This command can only be in the open state.
Recover datafile: This command can be used either in the mount or open state.
Restore database:
Query the dynamic performance ViewV $ recover_fileYou can determine the data file to be restored:
SQL> startup -- An error occurred while displaying mounted but open in Database
SQL> select file #, error from v $ recover_file; -- query the file to be restored and the cause of the error
Example 1:All data files are deleted by mistake: because all data files are deleted by mistake, you can use the restore database command to dump all data files and use the recover database command to restore the database, finally, execute alter database open to open the database:
C: \> rman target sys/liu123 @ mynewdb nocatalog
RMAN> startup force mount
RMAN> run {restore database;
Recover database;
SQL 'alter database open ';
}
Example 2:The disk where the data file is located has a hardware fault:
Note that the data file cannot be dumped to its original location. to recover the database, you must dump the data file to another disk. Before executing the restore database command, you can run the set newname command to specify a new location for the data file. After executing the restore database command, you can run the switch datafile command to change the location and name of the data file recorded in the control file. You can run the recover database command to apply archive logs. Finally, open the database with SQL statements. Example:
RMAN> run {
Startup force mount;
Set newname for datafile 1 to 'C: \ demo \ system01.dbf ';
Set newname for datafile 2 to 'C: \ demo \ undotas01.dbf ';
Set newname for datafile 3 to 'C: \ demo \ sysaux01.dbf ';
Set newname for datafile 4 to 'C: \ demo \ users01.dbf ';
Set newname for datafile 5 to 'C: \ demo \ user01.dbf ';
Set newname for datafile 6 to 'C: \ demo \ user02.dbf ';
Restore database;
Switch databse;
SQL 'alter database open'
}
After the database is restored and opened, run the report schema command to view the new physical solution of the database.
RMAN> report schema;
Restore the data file of the system tablespace:
Because the database cannot be opened when a media failure occurs in the system tablespace, the data file must be restored in the mount state.
Example 1:The data file of the system tablespace is deleted by mistake. After the database is loaded, run the restore datafile command to dump the data file corresponding to the tablespace and use the recover datafile command to apply archive logs. Open the database. Command:
RMAN> run {
Startup force mount;
Restore datafile 1;
Recover datafile 1;
SQL 'alter database open'
}
Example 2:The disk where the system tablespace data file is located is faulty and cannot be dumped to the original location. Before restore datafile, run set newname to specify a new location for the data file. After the restore datafile is executed, you can use switch datafile to apply archive logs and open the database. Example:
RMAN> run {
Startup force mount;
Set newname for datafile 1 to 'd: \ demo \ system01.dbf ';
Restore datafile 1;
Switch datafle 1;
Recover datafile 1;
SQL 'alter database open ';
}
Restore the accidentally lost data file after closing in the open state:
Except for the data files in the system tablespace, other data files can be restored using this method:
Example 1:Accidental deletion of data files: After the database is loaded, use the SQL statement alter database datafile first... Offline data files are lost offline, and then alter database open opens the database ., Use the restore datafile command to dump data files and use the recover datafile command to apply archive logs ., And then alter database datafile .. Online recovery, for example:
RMAN> run {
Startup force mount;
SQL 'alter database datafile 4 offline ';
SQL 'alter database open ';
Restore datafile 4;
Recover dtafile 4;
SQL 'alter database datafile 4 online ';
}
Example 2:The disk where the data file is located is damaged:
Obviously, the data file cannot be dumped to the original location. Load the database first, and then alter database datafile .. Offline. Then alter database open. Before restore datafile, run the set newname command to create a new location for the data file. After the restore datafile command is executed, the switch datafile command can be used to change the location and name of the data file recorded in the control file, and archive logs can be applied through the recover datafile command. Alter database datafile .. Online. Sample Code:
RMAN> run {
Startup force mount;
SQL 'alter databse datafile 4 offline ';
SQL 'alter database open ';
Set newname for datafile 4 to 'd: \ demouser01.dbf ';
Restore datafile 4;
Switch datafile 4;
Recover datafile 4;
SQL 'alter database datafile 4 onlune ';
}
Restore accidentally lost data files when opening in the open state:
In this case, only the data files that failed the media cannot be accessed without affecting other data files. Assume that the media fails at users01 and. dbf in the open state.
Example 1:Accidental deletion of data files: alter database datafile in open state .. Offline: Use the restore datafile command to dump data files, then recovert datafile to apply archive logs, and finally alter database datafile .. Online:
RMAN> run {
SQL 'alter database datafile 4 offline ';
Restore datafile 4;
Recover datafile 4;
SQL 'alter database datafile 4 online ';
}
Example 2:The disk where the data file is located has a fault: you cannot tell the data file to its original location. First, alter database datafile .. Offline. Then the set newname for command specifies a new location for the data file. Restore datafile and switch datafile to change the name and location of the data file in the control file. Use recover datafile to apply archive logs. Alter database datafile .. Online. Example:
RMAN> run {
SQL 'alter database datafile 4 offline ';
Set newname for datafile 4 to 'd: \ demo \ users01.dbf ';
Restore datafile 4;
Switch datafile 4;
Recover datafile 4;
SQL 'alter database datafile 4 online ';
}
Restore unbacked data files in the open state:
Example 1:The data file is deleted by mistake:
Note that the data file is not backed up at this time. Starting from 10 Gb, if the data file backup does not exist, the data file will be automatically created when the data file is dumped. After the data file is created, you can run logs based on the archived logs until the time point when the files are deleted. Example:
RMAN> run {
Starup force mount;
SQL 'alter database datafile 7 offline ';
SQL 'alter database open ';
Restore datafile 7;
Recover datafile 7;
SQL 'alter database datafile 7 online ';
}
Example 2:The disk where the data file is located is damaged.
RMAN> run {
Startup force mount;
SQL 'alter database datafile 7 offline ';
SQL 'alter database open ';
Set newname for datafile 7 to 'C: \ demo \ user04.dbf ';
Restore datafile 7;
Switch datafile 7;
Recover datafile 7;
SQL 'alter database datafile 7 online ';
}
Restore tablespace:
Example 1:When the database is in the open state, if all data files in a tablespace have a media fault, you must first use alter tablespace .. Offline for recover. Use restore tablespace .. Revover tablespace applies archive logs and alter tablespace .. Online. Example:
RMAN> run {
SQL 'alter tablespace users offline for recover ';
Restore tablespace users;
Recover tablespace users;
SQL 'alter tablespace users online ';
}
Example 2:Disk fault where the tablespace data file is located:
RMAN> run {
SQL 'alter tablespace users offline for recover ';
Set newname for datafile 4 to 'd: \ demo \ users01.dbf ';
Restore tablespace user;
Switch datafile all;
Recover tablespace users;
SQL 'alter tablespace users online ';
}
Data Block Media recovery:
An error is reported only when these bad blocks are accessed. If an error is reported:
Ora-01578: oracle data block upted (file #5, block #21)
Ora-01110: data file 5: 'd: \ demo \ uyser01, dbf'
Run the following command: RMAN> blockrecover device type disk datafile 5 blocks 21, 48,128;
RMAN Incomplete recovery:
Incomplete recovery of rman can be completed in the mount state.
1. Time-based recovery: When rman executes Incomplete recovery based on time points, you must first set the environment variable NLS_DATE_FORMAT on the command line. After entering rman, first mount the database, and then run the set until time command to restore to the TIME point. Example:
C: \> set nls_date_format = yyyy-mm-dd hh24: mi: ss
C: \> rman target sys/oracle @ demo nocatalog
RMAN> run {
Startup force mount;
Set until time = '2017-05-08 17:00:28 ';
Restore database;
Recover database;
SQL 'alter database open resetlogs ';
}
When the resetlogs option is used to open the database, the log serial number is reset and a new database copy is generated. After 10 Gb, the database must be backed up again after not completely restored. After 10 Gb, oracle provides a security mechanism to ensure that archive logs are not overwritten, so that backup of earlier database copies can be used for database recovery. However, after Incomplete recovery, we recommend that you delete all the earlier backups and back up the database again. Example:
RMAN> run {
Delete noprompt backup;
Delete noprompt copy;
Backup database format = 'd: backup \ % d _ % s. bakj ';
SQL 'alter system archive log current ';
}
SCN-based recovery:
First, query the current scn number: SQL> select current_scn from v $ databse;
Delete A Table scott. emp.
Example: RMAN> run {
Startup force mount;
Set until scn = 511416;
Restore database;
Recover database;
SQL 'alter database open resetlogs ';
}
When the resetlogs option is used to open the database, the log serial number is reset and a new database copy is generated. After 10 Gb, the database must be backed up again after not completely restored. After 10 Gb, oracle provides a security mechanism to ensure that archive logs are not overwritten, so that backup of earlier database copies can be used for database recovery. However, after Incomplete recovery, we recommend that you delete all the earlier backups and back up the database again. Example:
RMAN> run {
Delete noprompt backup;
Delete noprompt copy;
Backup database format = 'd: backup \ % d _ % s. bakj ';
SQL 'alter system archive log current ';
}
Log serial number recovery:
Assume that the following error occurs when the full Backup Recovery fails.
In this case, dba can be used to perform Incomplete recovery based on the log serial number: Example:
RMAN> run {
Startup force mount;
Set until sequence = 6;
Restore database;
Recover database;
SQL 'alter database open resetlogs ';
}
When the resetlogs option is used to open the database, the log serial number is reset and a new database copy is generated. After 10 Gb, the database must be backed up again after not completely restored. After 10 Gb, oracle provides a security mechanism to ensure that archive logs are not overwritten, so that backup of earlier database copies can be used for database recovery. However, after Incomplete recovery, we recommend that you delete all the earlier backups and back up the database again. Example:
RMAN> run {
Delete noprompt backup;
Delete noprompt copy;
Backup database format = 'd: backup \ % d _ % s. bakj ';
SQL 'alter system archive log current ';
}
Backup control file recovery:
It refers to the process of restoring the database using backup control files. This method can be used when the tablespace is accidentally deleted or all the control files in the database are damaged. The following example illustrates how to restore the users tablespace Based on the backup control file;
SQL> drop tablespace user01 including contents;
You can query the alert file to determine the misoperation time. The alert file is located in the directory corresponding to background_dump_dest. When the file name format is alert_mynewdb.log, you should check the alert file at the end of the file, you can see the specific time for deleting the table, which is about 22:13:34 on. You only need to restore it to this time point. Note: When rman Based on the backup control file is not completely restored, the recovery directory must be used to periodically write the rman metadata in the control file to the recovery directory. If the recovery directory is not used, the automatic backup function of the control file must be activated, otherwise, the backup of the control file cannot be dumped. Before dumping the control file, you need to use the set dbid command to set the database id and load the database after dumping the control file, then execute the time-point-based rman Incomplete recovery. Example:
C: \> set nls_date_format = yyyy-mm-dd hh24: mi: ss
C: \> rman target sys/oracle @ demo nocatalog
RMAN> startup force nomount
RMAN> set dbid = 3282656886;
RMAN> restore controlfile from autobackup maxseq 6;
RMAN> alter database mount
RMAN> run {
Set until time = '2017-05-08 22:13:34 ';
Restore database;
Recover database;
SQL 'alter database open resetlogs ';
}
When the resetlogs option is used to open the database, the log serial number is reset and a new database copy is generated. After 10 Gb, the database must be backed up again after not completely restored. After 10 Gb, oracle provides a security mechanism to ensure that archive logs are not overwritten, so that backup of earlier database copies can be used for database recovery. However, after Incomplete recovery, we recommend that you delete all the earlier backups and back up the database again. Example:
RMAN> run {
Delete noprompt backup;
Delete noprompt copy;
Backup database format = 'd: backup \ % d _ % s. bakj ';
SQL 'alter system archive log current ';
}