RMAN相关操作命令
1、查看哪些文件需要进行RMAN 备份?
RMAN> report need backup; RMAN retention policy will be applied to the command RMAN retention policy is set to redundancy 1 Report of files with less than 1 redundant backups File #bkps Name ---- ----- ----------------------------------------------------- 1 0 +DATA/racdb/datafile/system.262.818420641 2 0 +DATA/racdb/datafile/sysaux.263.818420665 3 0 +DATA/racdb/datafile/undotbs1.264.818420681 4 0 +DATA/racdb/datafile/undotbs2.266.818420707 5 0 +DATA/racdb/datafile/users.267.818420715
2、查看当前归档日志详细信息
RMAN> list archivelog all; List of Archived Log Copies for database with db_unique_name RACDB ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 1 1 63 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_63.273.818423169 4 1 64 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_64.276.818423215 8 1 65 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_65.280.818425501 9 1 66 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_66.281.818425651 10 1 67 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_67.282.818425655 11 1 68 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_68.283.818426127 13 1 69 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_69.285.818429629 15 1 70 A 19-JUN-13 Name: +DATA/racdb/archivelog/2013_06_19/thread_1_seq_70.288.818527563 16 1 71 A 19-JUN-13 Name: +DATA/racdb/archivelog/2013_06_19/thread_1_seq_71.289.818534069 19 1 72 A 19-JUN-13 Name: +DATA/racdb/archivelog/2013_06_19/thread_1_seq_72.291.818536665 20 1 73 A 19-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_1_seq_73.292.818698081 21 1 74 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_1_seq_74.293.818698099 23 1 75 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_1_seq_75.295.818701975 24 1 76 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_1_seq_76.296.818701977 2 2 1 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_1.274.818423203 3 2 2 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_2.275.818423213 5 2 3 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_3.277.818423215 6 2 4 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_4.278.818424079 7 2 5 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_5.279.818425497 12 2 6 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_6.284.818426129 14 2 7 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_7.286.818429635 17 2 8 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_19/thread_2_seq_8.290.818534077 18 2 9 A 19-JUN-13 Name: +DATA/racdb/archivelog/2013_06_19/thread_2_seq_9.287.818536663 22 2 10 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_2_seq_10.294.818701301 25 2 11 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_2_seq_11.297.818705057 26 2 12 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_2_seq_12.298.818705061
3、删除归档日志信息
RMAN> delete archivelog all; released channel: ORA_DISK_1 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=153 instance=racdb1 device type=DISK List of Archived Log Copies for database with db_unique_name RACDB ===================================================================== Key Thrd Seq S Low Time ------- ---- ------- - --------- 1 1 63 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_63.273.818423169 4 1 64 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_64.276.818423215 8 1 65 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_65.280.818425501 9 1 66 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_66.281.818425651 10 1 67 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_67.282.818425655 11 1 68 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_68.283.818426127 13 1 69 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_1_seq_69.285.818429629 15 1 70 A 19-JUN-13 Name: +DATA/racdb/archivelog/2013_06_19/thread_1_seq_70.288.818527563 16 1 71 A 19-JUN-13 Name: +DATA/racdb/archivelog/2013_06_19/thread_1_seq_71.289.818534069 19 1 72 A 19-JUN-13 Name: +DATA/racdb/archivelog/2013_06_19/thread_1_seq_72.291.818536665 20 1 73 A 19-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_1_seq_73.292.818698081 21 1 74 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_1_seq_74.293.818698099 23 1 75 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_1_seq_75.295.818701975 24 1 76 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_1_seq_76.296.818701977 2 2 1 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_1.274.818423203 3 2 2 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_2.275.818423213 5 2 3 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_3.277.818423215 6 2 4 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_4.278.818424079 7 2 5 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_5.279.818425497 12 2 6 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_6.284.818426129 14 2 7 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_18/thread_2_seq_7.286.818429635 17 2 8 A 18-JUN-13 Name: +DATA/racdb/archivelog/2013_06_19/thread_2_seq_8.290.818534077 18 2 9 A 19-JUN-13 Name: +DATA/racdb/archivelog/2013_06_19/thread_2_seq_9.287.818536663 22 2 10 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_2_seq_10.294.818701301 25 2 11 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_2_seq_11.297.818705057 26 2 12 A 21-JUN-13 Name: +DATA/racdb/archivelog/2013_06_21/thread_2_seq_12.298.818705061 Do you really want to delete the above objects (enter YES or NO)? yes deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_1_seq_63.273.818423169 RECID=1 STAMP=818423169 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_1_seq_64.276.818423215 RECID=4 STAMP=818423215 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_1_seq_65.280.818425501 RECID=8 STAMP=818425503 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_1_seq_66.281.818425651 RECID=9 STAMP=818425651 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_1_seq_67.282.818425655 RECID=10 STAMP=818425655 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_1_seq_68.283.818426127 RECID=11 STAMP=818426128 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_1_seq_69.285.818429629 RECID=13 STAMP=818429633 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_19/thread_1_seq_70.288.818527563 RECID=15 STAMP=818527569 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_19/thread_1_seq_71.289.818534069 RECID=16 STAMP=818534077 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_19/thread_1_seq_72.291.818536665 RECID=19 STAMP=818536664 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_21/thread_1_seq_73.292.818698081 RECID=20 STAMP=818698081 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_21/thread_1_seq_74.293.818698099 RECID=21 STAMP=818698099 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_21/thread_1_seq_75.295.818701975 RECID=23 STAMP=818701975 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_21/thread_1_seq_76.296.818701977 RECID=24 STAMP=818701977 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_2_seq_1.274.818423203 RECID=2 STAMP=818423204 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_2_seq_2.275.818423213 RECID=3 STAMP=818423214 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_2_seq_3.277.818423215 RECID=5 STAMP=818423215 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_2_seq_4.278.818424079 RECID=6 STAMP=818424087 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_2_seq_5.279.818425497 RECID=7 STAMP=818425496 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_2_seq_6.284.818426129 RECID=12 STAMP=818426129 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_18/thread_2_seq_7.286.818429635 RECID=14 STAMP=818429635 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_19/thread_2_seq_8.290.818534077 RECID=17 STAMP=818534080 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_19/thread_2_seq_9.287.818536663 RECID=18 STAMP=818536663 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_21/thread_2_seq_10.294.818701301 RECID=22 STAMP=818701302 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_21/thread_2_seq_11.297.818705057 RECID=25 STAMP=818705059 deleted archived log archived log file name=+DATA/racdb/archivelog/2013_06_21/thread_2_seq_12.298.818705061 RECID=26 STAMP=818705060 Deleted 26 objects
4、删除备份信息
RMAN> delete backup; allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=153 instance=racdb1 device type=DISK specification does not match any backup in the repository
5、切换归档日志
SQL> alter system switch logfile; System altered.
6、使用RMAN备份数据库
RMAN> run{ 2> allocate channel c1 type disk; 3> allocate channel c2 type disk; 4> allocate channel c3 type disk; 5> allocate channel c4 type disk; 6> backup database format '/home/oracle/backup/Full_%U.bak'; 7> release channel c1; 8> release channel c2; 9> release channel c3; 10> release channel c4; 11> } released channel: ORA_DISK_1 allocated channel: c1 channel c1: SID=153 instance=racdb1 device type=DISK allocated channel: c2 channel c2: SID=157 instance=racdb1 device type=DISK allocated channel: c3 channel c3: SID=29 instance=racdb1 device type=DISK allocated channel: c4 channel c4: SID=158 instance=racdb1 device type=DISK Starting backup at 21-JUN-13 channel c1: starting full datafile backup set channel c1: specifying datafile(s) in backup set input datafile file number=00001 name=+DATA/racdb/datafile/system.262.818420641 input datafile file number=00004 name=+DATA/racdb/datafile/undotbs2.266.818420707 channel c1: starting piece 1 at 21-JUN-13 channel c2: starting full datafile backup set channel c2: specifying datafile(s) in backup set input datafile file number=00003 name=+DATA/racdb/datafile/undotbs1.264.818420681 channel c2: starting piece 1 at 21-JUN-13 channel c3: starting full datafile backup set channel c3: specifying datafile(s) in backup set input datafile file number=00002 name=+DATA/racdb/datafile/sysaux.263.818420665 input datafile file number=00005 name=+DATA/racdb/datafile/users.267.818420715 channel c3: starting piece 1 at 21-JUN-13 channel c4: starting full datafile backup set channel c4: specifying datafile(s) in backup set including current control file in backup set channel c4: starting piece 1 at 21-JUN-13 channel c2: finished piece 1 at 21-JUN-13 piece handle=/home/oracle/backup/Full_02ocovu1_1_1.bak tag=TAG20130621T190015 comment=NONE channel c2: backup set complete, elapsed time: 00:00:47 channel c2: starting full datafile backup set channel c2: specifying datafile(s) in backup set including current SPFILE in backup set channel c2: starting piece 1 at 21-JUN-13 channel c4: finished piece 1 at 21-JUN-13 piece handle=/home/oracle/backup/Full_04ocovu3_1_1.bak tag=TAG20130621T190015 comment=NONE channel c4: backup set complete, elapsed time: 00:00:19 channel c2: finished piece 1 at 21-JUN-13 piece handle=/home/oracle/backup/Full_05ocovvm_1_1.bak tag=TAG20130621T190015 comment=NONE channel c2: backup set complete, elapsed time: 00:00:18 channel c1: finished piece 1 at 21-JUN-13 piece handle=/home/oracle/backup/Full_01ocovu0_1_1.bak tag=TAG20130621T190015 comment=NONE channel c1: backup set complete, elapsed time: 00:02:35 channel c3: finished piece 1 at 21-JUN-13 piece handle=/home/oracle/backup/Full_03ocovu1_1_1.bak tag=TAG20130621T190015 comment=NONE channel c3: backup set complete, elapsed time: 00:02:33 Finished backup at 21-JUN-13 released channel: c1 released channel: c2 released channel: c3 released channel: c4
7、使用RMAN备份归档日志
RMAN> backup archivelog all format '/home/oracle/backup/ARCHIVE_LOG_%U.bak'; Starting backup at 21-JUN-13 current log archived allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=153 instance=racdb1 device type=DISK channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=77 RECID=27 STAMP=818708153 input archived log thread=2 sequence=13 RECID=30 STAMP=818709052 input archived log thread=1 sequence=78 RECID=28 STAMP=818708173 input archived log thread=1 sequence=79 RECID=29 STAMP=818709050 channel ORA_DISK_1: starting piece 1 at 21-JUN-13 channel ORA_DISK_1: finished piece 1 at 21-JUN-13 piece handle=/home/oracle/backup/ARCHIVE_LOG_06ocp0ht_1_1.bak tag=TAG20130621T191053 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 21-JUN-13
8、RAC主库执行创建物理备库控制文件
RMAN> backup device type disk format '/home/oracle/backup/standby_%U.ctl' current controlfile for standby; Starting backup at 21-JUN-13 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including standby control file in backup set channel ORA_DISK_1: starting piece 1 at 21-JUN-13 channel ORA_DISK_1: finished piece 1 at 21-JUN-13 piece handle=/home/oracle/backup/standby_07ocp0p2_1_1.ctl tag=TAG20130621T191442 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 21-JUN-13
9、RAC主库创建物理备库初始化参数文件
SQL> create pfile='/home/oracle/backup/initphydb.ora' from spfile; File created.