Rman Common Backup RESTORE command rollup

Source: Internet
Author: User

Rman command
1. Independent command
Rman>shutdown Immediate
Rman>startup
Rman>backup format ' D:\backup\%d_%s.bak ' tablespace users;
2. Job Order
Rman>run {backup format ' d:\backup\ $d _%s.bak ' tablespace users;}
3. Run SQL command
Rman>sql ' alter system switch logfile ';
4. Run the storage script
Rman>run {execute script s1;}
5. Running Operating system commands
Rman>run {host "dir d:\backup";}
6. Run the Rman command
C:\rman target Sys/[email protected] nocatalog @c:\bak_users.cmd log A.log
Bak_users.cmd Example:
Backup format ' D:\backup\%d_%s.bak tablespace users;
SQL ' alter system archive log current ';

Configuring the Rman Environment (slightly)

Set up a backup set
1. Full database backup set
1), consistent backup (for Noarchivelog and Archivelog modes)
C:\rman target Sys/[email protected] Nocatalog
Rman>shutdown Immediate
Rman>startup Mout
Rman>backup database; If you back up to a different directory, backup database format = ' d:\backup\%d_%s.dbf ';
Rman>sql ' alter system archive log current ';
2), non-conforming backup (in open state)
Rman>backup database; If you back up to a different directory, backup database format = ' d:\backup\%d_%s.dbf ';
Rman>sql ' alter system archive log current ';
3), Exempt table space
Rman>configure exclude for Tablespace user03;
Rman>backup database; If you back up to a different directory, backup database format = ' d:\backup\%d_%s.dbf ';
Rman>sql ' alter system archive log current ';
2. Table Space Backup set
Rman>backup tablespace users format= ' d:\backup\%N_%f_%s.dbf ';
3. Data file backup set
Rman>backup datafile 5 format= ' d:\backup\%N_%f_%s.dbf ';
4. Control file backup Set
Rman>backup current Controlfile format= ' D:\backup\%d_%s.ctl ';
5. SPFile Backup Set
Rman>backup spfile format= ' C:\%d_%s.par ';
6. Archive log backup set (archive logs generated over the past day)
Rman>backup format= ' C:\%d_%s.arc ' archivelog from time= ' sysdate-1 ' until time= ' sysdate ';
7. Parallel Backup Set
Rman>configure Device type disk parallelism 3;
Rman>backup database format= ' c:\%d_%s.dbf ';
Rman>configure device type disk clear;
8. Build multiple backups
Rman>backup copied 3 tablespace users format= ' c:\1\%N_%s.dbf ', ' c:\2\%N_%s.dbf ', ' c:\3\%N_%s.dbf ';
9. Backup Backup Set
Rman>backup backupset format= ' C:\%d_%s.bak ';
10. Build multiple backup slices
Rman>configure Channel Device type SBT maxpiecesize 4G;
Rman>backup device Type SBT format '%d_%s_%p.dbf ' database;
11. Set up a compressed backup set
Rman>backup as compressed backupset tablespace users format= ' c:\%d_%s.dbf ';
12. Backing up data files and archive logs
Rman>backup format ' C:\%d_%s.bak ' tablespace users plus archivelog;
13. Specify the backup set tag
Rman>backup format= ' C:\%d_%s.bak ' tablespace users tag= ' users ';

Make an image copy
1. Create a copy of the data file image
Rman>backup as copy format= ' c:\df_5.dbf ' datafile 5; Or
Rman>copy datafile 5 to ' c:\df_5.dbf ';
2. Establish a copy of the control file image
Rman>backup as copy format= ' C:\demo.ctl ' current controlfile; Or
Rman>copy controlfile to ' c:\demo.ctl ';
3. Create a copy of the archived log image
Rman>backup as copy format= ' C:\arc10.log ' archivelog sequence 10; Or
Rman>copy archivelog ' c:\demo\archive\arc00020_012345.001 ' to ' c:\arc20.log ';
4. Create a copy of the image in parallel
Rman>configure Device type disk parallelism 3;
Rman>backup as Copy format = ' c:\df_%f.dbf ' datafile 5,6,7;
Rman>configure device type disk clear;
5. Specify the image copy token
Rman>backup as copy format= ' c:\df_%f.dbf ' datafile 5 tag=df_5; Or
Rman>copy datafile 5 to ' c:\df_%f.dbf ' tag=df_5;

Establish incremental and cumulative backups
Incremental backups can reduce backup time, and cumulative backups can reduce recovery time.
Example of incremental backup: Sunday level 0, Monday, Tuesday, Thursday, Friday, Saturday level 2, Wednesday level 1
Rman>backup Incremental Level 0 format= ' c:\backup\%d_%s.dbf ' tablespace users; Sunday
Rman>backup Incremental Level 2 format= ' c:\backup\%d_%s.dbf ' tablespace users; Monday
Rman>backup Incremental Level 2 format= ' c:\backup\%d_%s.dbf ' tablespace users; Tuesday
Rman>backup Incremental Level 1 format= ' c:\backup\%d_%s.dbf ' tablespace users; Wednesday
Rman>backup Incremental Level 2 format= ' c:\backup\%d_%s.dbf ' tablespace users; Thursday
Rman>backup Incremental Level 2 format= ' c:\backup\%d_%s.dbf ' tablespace users; Friday
Rman>backup Incremental Level 2 format= ' c:\backup\%d_%s.dbf ' tablespace users; Saturday
Rman Full Recovery
1. Restore the database
1), all data files are deleted
C:\rman target Sys/[email protected] Nocatalog
Rman>startup Force Mount
Rman> Run {
Restore databse;

Recover database;
SQL ' ALTER DATABASE open ';
}
2) hardware failure on the disk where the data file resides
Rman> Run {
Startup force Mount;
Set newname for datafile 1 to ' c:\demo\system01.dbf ';
Set newname for datafile 2 to ' c:\demo\dundotbs01.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\example01.dbf ';
Set newname for datafile 6 to ' c:\demo\test0.dbf ';
Restore database;
Switch datafile all;
Recover database;
SQL ' ALTER DATABASE open ';
}
2. Recover the data files of the system table space
1), the system Tablespace data file was mistakenly deleted
Rman>run {
Startup force Mount;
Restore DataFile 1;
Recover datafile 1;
SQL ' ALTER DATABASE open ';
}
2), the disk on which the system Tablespace data file is located fails
Rman> Run {
Startup force Mount;
Set newname for datafile 1 to ' c:\demo\system01.dbf ';
Restore DataFile 1;
Switch DataFile 1;
Recover datafile 1;
SQL ' ALTER DATABASE open ';
}
3. Accidental loss of data file after resuming shutdown in open state
1), data files are deleted
Rman>run {
Startup force Mount;
SQL ' ALTER DATABASE datafile 4 offline ';
SQL ' ALTER DATABASE open ';
Restore DataFile 4;
Recover DataFile 4;
SQL ' ALTER DATABASE datafile 4 online ';
}
2), the disk where the data file is damaged
Rman>run {
Startup force Mount;
SQL ' ALTER DATABASE datafile 4 offline ';
SQL ' ALTER DATABASE open ';
Set newname for datafile 4 to ' c:\demo\user01.dbf ';
Restore DataFile 4;
Switch DataFile 4;
Recover DataFile 4;
SQL ' ALTER DATABASE datafile 4 online ';
}
4. Accidental loss of data file in open state
1), data files were mistakenly deleted
Rman>run {
SQL ' ALTER DATABASE datafile 4 offline ';
Restore DataFile 4;
Recover DataFile 4;
SQL ' ALTER DATABASE datafile 4 online ';
}
2), the disk where the data file is faulted
Rman>run {
SQL ' ALTER DATABASE datafile 4 offline ';
Set newname for datafile 4 to ' c:\demo\user01.dbf ';
Restore DataFile 4;
Switch DataFile 4;
Recover DataFile 4;
SQL ' ALTER DATABASE datafile 4 online ';
}
5. Restore the data files that were not backed up in open state (no backup was made after creating the new data file)
1), data files are mistakenly
Rman>run {
Startup force Mount;
SQL ' ALTER DATABASE datafile 7 offline ';
SQL ' ALTER DATABASE open ';
Restore DataFile 7;
Recover DataFile 7;
SQL ' ALTER DATABASE datafile 7 online ';
}
2), the disk where the data file is faulted
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 ';
}

6. Restore table Space
1), table space is deleted
Rman>run {
SQL ' alter TABLESPACE users offline for recover ';
Restore tablespace users;
Recover tablespace users;
SQL ' alter tablespace users online ';
}
2), the disk where the tablespace data file is faulted
Rman>run {
SQL ' alter TABLESPACE users offline for recover ';
Set newname for datafile 4 to ' c:\demo\user01.dbf ';
Restore tablespace users;
Switch tablespace users;
Recover tablespace users;
SQL ' alter tablespace users online ';
}
7. Data Block Media recovery
Rman>blockrecover Device Type disk datafile 5 block 20,21,100;

Rman not fully recovered
1. Basic Time Recovery
C:\set nls_date_format=yyyy-dd-mm Hh24:mi:ss
C:\rman target Sys/[email protected] Nocatalog
Rman>run {
Startup force Mount;
Set until Time= ' 2010-08-22 12:00:08 ';
Restore database;
Recover database;
SQL ' ALTER DATABASE open resetlogs;
}
2, based on SCN recovery
Rman>run {
Startup force Mount;
Set until scn=123456;
Restore database;
Recover database;
SQL ' ALTER DATABASE open resetlogs ';
}
3, based on the log serial number recovery
Rman>run {
Startup force Mount;
Set until seqence=10;
Restore database;
Recover database;
SQL ' ALTER DATABASE open resetlogs ';
}
4, backup-based control file recovery
C:\set nls_date_format=yyyy-dd-mm Hh24:mi:ss
C:\rman target Sys/[email protected] Nocatalog
Rman>startup Force Nomount;
Rman>set dbid=1113606269;
Rman>restore Controlfile from Autobackup maxseq 6;
Rman>alter database Mount;
Rman>run {
Set until Time= ' 2010-08-22 12:00:08 ';
Restore database;
Recover database;
SQL ' ALTER DATABASE open resetlogs;
}
After performing the above 4 incomplete recoveries, it is recommended that you delete all earlier backups and back up the database
Rman>run {
Delete noprompt backup;
Delete noprompt copy;
Backup Database format= ' C:\backup\%d_%s.bak ';
SQL ' alter system archive log current ';
}

Rman Maintenance Commands
Report
1. Reporting the physical structure of the target database
Rman>report schema;
2. Report data files that need to be backed up
1), report an incremental backup that requires a dump that exceeds a specific number of data files
Rman> report need backup incremental 3;
2), report data files that are not backed up for a specific number of days
Rman>report need backup days 3 tablespace users;
3), report data files that are less than the number of specific backups
Rman> report need backup redundancy 2 database;
4), report data files that are not backed up in the recovery time window
Rman> report need backup recovery windows of 3 days;
3. Reporting Stale backups
Rman>report obsolete redundancy 2;
4. Report Unrecoverable data files
Rman>report unrecoverable;
LIST
1. list data file backup sets
Rman>list Backup of database;
Rman>list Backup of tablespace users;
Rman>list Backup of datafile 4;
2. List control file backup sets
Rman>list Backup of Controlfile;

3. List archived log backup sets
Rman>list backup of Archivelog all;
4. List SPFile backup sets
Rman>list Backup of SPFile;
5. list data file image copy
rman>list copy of database;
Rman>list copy of tablespace users;
Rman>list copy of DataFile 4;
6. List control file image copy
Rman>list copy of Controlfile;
7. List archived Log image copies
Rman>list copy of Archivelog all;
8. List database copies
Rman>list incarnation of database;
Note that a new database copy is generated each time the database is opened with the Resetlogs option.
9. List information for backup set files
Rman>list Backupset 100;
Crosscheck
1. Check all backup Sets
Rman>crosscheck backup;
2, check the backup set of all data files
Rman>crosscheck Backup of database;
3, check the specific table space of the preparation
Rman>crosscheck backup of tablespace system;
4. Check backup sets for specific data files
Rman>crosscheck Backup of datafile 1;
5, check the backup set of the control file
Rman>crosscheck Backup of Controlfile;
6, check the backup set of SPFile
Rman> crosscheck Backup of SPFile;
7. Check the backup set of the archive log
Rman> crosscheck Backup of Archivelog sequence 40;
8. Check all image copies
rman> crosscheck copy;
9. Verify the image copy of all data files
rman> crosscheck copy of database;
10. Check the image copy of a specific tablespace
rman> crosscheck copy of tablespace users;
11. Check the image copy of the specific data file
rman> crosscheck copy of datafile 1;
12, check the image copy of the control file
rman> crosscheck copy of Controlfile;
13. Check the image copy of the archived log
rman> crosscheck copy of Archivelog sequence 44;

DELETE
1. Delete Stale backups
Delete obsolete; #提示
Delete NoPrompt obsolete; #不提示
2. Delete Expired backup set
Delete noprompt expired backup;
3. Delete Expired Copy
Delete noprompt expired copy;
4. Delete a specific backup set
Delete NoPrompt backupset 19;
5. Delete specific backup slices
Delete noprompt backuppiece ' C:\test\demo1.bak ';
6. Delete all backup sets
Delete noprompt backup; Or
Delete NoPrompt backupset;
7. Delete a specific image copy
Delete noprompt datafilecopy ' C:\test\demo.bak '; Delete a data file
Delete noprompt controlfilecopy ' c:\test\controlfile_bak.ctl '; Delete a control file
Delete noprompt archivelog ' C:\test\arc.bak '; Delete Archive Log
8. Delete all image replicas
Delete noprompt copy;
9. Delete the input object after backup
Backup Archivelog all delete input;
Backup backupset format= ' c:\test\%u.bak ' delete input;
Change
1. Change Backup Set Status
Change backupset unavailable;
2. Change image Copy Status
Change Datafilecopy ' C:\demo.bak ' unavailable;
Change Controlfilecopy ' C:\demo.bak ' unavailable;
Change Archivelog ' C:\demo.bak ' unavailable;
3. Establish long-term backup
Change backupset keep forver logs; Keep Backup set 100 persistent
Change backupset Keep until time ' sysdate+60 ' logs; Keep backup set 100 for 60 days
Change Backupset 156 nokeep; Exemption from backup set 100 retention period

CATALOG
1. Registered Copy
Catalog datafilecopy ' C:\user01.bak ';
2. Register Backup Tablets
Catalog backuppiece ' c:\demo_10.dbf ';
3. Register all backup files for a specific directory
Catalog start with ' C:\bak ';
4. Log off Backup records
Change datafilecopy ' C:\user01.bak ' uncatalog;
Change controlfilecopy ' C:\demo.ctl ' uncatalog;
Change backuppiece ' C:\demo_10.bak ' uncatalog;
Recovering Directory Management
Create a recovery directory
1. Create a Recovery directory table space
sql> Create Tablespace Rman_ts
2 datafile ' D:\oracle\product\10.1.0\db_1\train\rman.dbf '
3 size 15m;
The tablespace has been created.
2. Establish Recovery directory owner
Sql> create user Rman identified by Rman
2 default tablespace rman_ts;

The user has created.
3. Grant the Restore directory owner role
Sql> Grant Connect,resource,recovery_catalog_owner to Rman;
Authorization is successful.
4. Create a recovery directory
C:\rman catalog Rman/[email protected]
Rman>create Catalog;
5. Register the target database
Rman>connect target Sys/[email protected]
Rman>register database;
Rman>report schema;

Using Storage scripts
1. Create a storage script
C:\>rman catalog Rman/[email protected] target Sys/[email protected]
Rman>create script Bak_database {
Backup format= ' C:\temp\%d_%s.bak '
Database include current Controlfile
Plus archivelog;
SQL ' alter system archive log current ';
}
2. Run the script
(1), run the storage script at the Rman prompt
Rman>run {Execute script bak_database;}
(2), run the storage script at the command line
C:\rman catalog Rman/[email protected] target Sys/[email protected] script Bak_database
3. Display the contents of the storage script
Rman>print script bak_database;
4. Replace the storage script
Rman>replace script Bak_database {
Backup Database format= ' C:\temp\%d_%s.bak ';
}
5. Delete Storage Scripts
Rman>delete script bak_database;
6. List all storage scripts
Rman>list script names;

Maintaining the recovery Catalog
1. Re-sync the recovery directory
rman> Resync Catalog;
2. Unregister the target database
Rman>unregister database;
When the target database is unregistered, the Rman repository records that are older than the Controlfile_record_keep_time setup time are lost.
3. Upgrade the Recovery directory
C:\>rman catalog Rman/[email protected] target Sys/[email protected]
rman> upgrade Catalog;
rman> upgrade Catalog;
4. Delete Recovery Directory
C:\>rman catalog Rman/[email protected] target Sys/[email protected]
rman> Drop Catalog;
rman> Drop Catalog;
5. Recovering a database to an earlier database copy

Rman Common Backup RESTORE command rollup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.