zoukankan      html  css  js  c++  java
  • Oracle 学习笔记: RMAN常用命令

    1 . set database to archivelog mode

    Sql代码 复制代码
    1. SQL> shutdown immediate;   
    2. Database closed.   
    3. Database dismounted.   
    4. ORACLE instance shut down.   
    5.   
    6. SQL> startup mount;   
    7. ORACLE instance started.   
    8.   
    9. Total System Global Area  251658240 bytes   
    10. Fixed Size                  1248356 bytes   
    11. Variable Size              83887004 bytes   
    12. Database Buffers          159383552 bytes   
    13. Redo Buffers                7139328 bytes   
    14. Database mounted.   
    15.   
    16. SQL> alter database archivelog;   
    17. Database altered.   
    18.   
    19. SQL> alter database open;   
    20. Database altered.   
    21.   
    22. SQL> archive log list;   
    23. Database log mode              Archive Mode   
    24. Automatic archival             Enabled   
    25. Archive destination            USE_DB_RECOVERY_FILE_DEST   
    26. Oldest online log sequence     1319   
    27. Next log sequence to archive   1321   
    28. Current log sequence           1321  
    SQL> shutdown immediate;
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    
    SQL> startup mount;
    ORACLE instance started.
    
    Total System Global Area  251658240 bytes
    Fixed Size                  1248356 bytes
    Variable Size              83887004 bytes
    Database Buffers          159383552 bytes
    Redo Buffers                7139328 bytes
    Database mounted.
    
    SQL> alter database archivelog;
    Database altered.
    
    SQL> alter database open;
    Database altered.
    
    SQL> archive log list;
    Database log mode              Archive Mode
    Automatic archival             Enabled
    Archive destination            USE_DB_RECOVERY_FILE_DEST
    Oldest online log sequence     1319
    Next log sequence to archive   1321
    Current log sequence           1321
    

    2 . define flash recovery area

    Sql代码 复制代码
    1. SQL> alter system set db_recovery_file_dest='D:/oracle/flash_recovery_area' scope=both;   
    2. System altered.   
    3. SQL> alter system set db_recovery_file_dest_size=15G scope=both;   
    4. System altered.  
    SQL> alter system set db_recovery_file_dest='D:/oracle/flash_recovery_area' scope=both;
    System altered.
    SQL> alter system set db_recovery_file_dest_size=15G scope=both;
    System altered.

    Oracle will use Oracle Managed File (OMF) for the flash recovery area. The free space in recovery area can be checked using OEM: All Metrics -> Recovery Area, or query vflash_recovery_area_usage view. To get more free space, you can use the following command to backup and then delete all the archived log files.

    Sql代码 复制代码
    1. RMAN> backup archivelog all delete all input;   
    RMAN> backup archivelog all delete all input; 

    3 . define multiple archived log destinations

    Sql代码 复制代码
    1. SQL> alter system set log_archive_dest_1='location=use_db_recovery_file_dest' scope=both;   
    2. System altered.   
    3. SQL> alter system set log_archive_dest_2='location=D:/oracle/archivelog_area1' scope=both;   
    4. System altered.  
    SQL> alter system set log_archive_dest_1='location=use_db_recovery_file_dest' scope=both;
    System altered.
    SQL> alter system set log_archive_dest_2='location=D:/oracle/archivelog_area1' scope=both;
    System altered.

    4 . CONTROL_FILE_RECORD_KEEP_TIME

    This parameter specify the minimum days the RMAN information is stored in the control file before overwritten. The default value is 7 days. When using catalog, a smaller value should be chosen.

    5 . starting RMAN

    Sql代码 复制代码
    1. rman target /   
    2. rman target / nocatalog   
    3. rman target sys/change_on_install@orcl   
    4. rman target sys/change_on_install@orcl catalog rman/rman@catdb   
    5. rman target sys/change_on_install log=xxx.log append   
    6. rman target sys/change_on_install cmdfile=xxx.rcv  
    rman target /
    rman target / nocatalog
    rman target sys/change_on_install@orcl
    rman target sys/change_on_install@orcl catalog rman/rman@catdb
    rman target sys/change_on_install log=xxx.log append
    rman target sys/change_on_install cmdfile=xxx.rcv

    6 . RMAN persistent settings

    6.1 display settings

    Sql代码 复制代码
    1. RMAN> show all;   
    2. RMAN> show controlfile autobackup;   
    3. RMAN> show retention policy;  
    RMAN> show all;
    RMAN> show controlfile autobackup;
    RMAN> show retention policy;

    6.2 configure settings

    Sql代码 复制代码
    1. RMAN> configure retention policy to recovery window of 7 days;   
    2. RMAN> configure backup optimization on;   
    3. RMAN> configure default device type to disk;   
    4. RMAN> configure controlfile autobackup on;   
    5. RMAN> configure controlfile autobackup format for device type disk to '%F';   
    6. RMAN> configure device type disk backup type to compressed backupset parallelism 1;   
    7. RMAN> configure datafile backup copies for device type disk to 1;   
    8. RMAN> configure archivelog backup copies for device type disk to 1;   
    9. RMAN> configure channel device type disk maxpiecesize 1 G;   
    10. RMAN> configure maxsetsize to unlimited;   
    11. RMAN> configure encryption for database off;   
    12. RMAN> configure encryption algorithm 'AES128';   
    13. RMAN> configure archivelog deletion policy to none;   
    14. RMAN> configure snapshot controlfile name to 'D:/oracle/flash_recovery_area/sncfepcit.ora';  
    RMAN> configure retention policy to recovery window of 7 days;
    RMAN> configure backup optimization on;
    RMAN> configure default device type to disk;
    RMAN> configure controlfile autobackup on;
    RMAN> configure controlfile autobackup format for device type disk to '%F';
    RMAN> configure device type disk backup type to compressed backupset parallelism 1;
    RMAN> configure datafile backup copies for device type disk to 1;
    RMAN> configure archivelog backup copies for device type disk to 1;
    RMAN> configure channel device type disk maxpiecesize 1 G;
    RMAN> configure maxsetsize to unlimited;
    RMAN> configure encryption for database off;
    RMAN> configure encryption algorithm 'AES128';
    RMAN> configure archivelog deletion policy to none;
    RMAN> configure snapshot controlfile name to 'D:/oracle/flash_recovery_area/sncfepcit.ora';

    If the control file autobackup is enabled, then RMAN automatically backs up the control file and spfile in one of two circumstances:
    - A successful backup is recorded in the RMAN repository
    - A structural change to the database affects the contents of the control file

    Control file autobackups are stored in the flash recovery area, unless otherwise specified.

    6.3 reset settings to default value

    Sql代码 复制代码
    1. RMAN> configure controlfile autobackup clear;   
    2. RMAN> configure retention policy clear;  
    RMAN> configure controlfile autobackup clear;
    RMAN> configure retention policy clear;

    7. RMAN commands

    7.1 backup commands

    Sql代码 复制代码
    1. RMAN> backup database;   
    2. RMAN> backup copy of database;   
    3. RMAN> backup as compressed backupset database;   
    4. RMAN> backup as backupset format ''/BACKUP/df_%d_%s_%p.bus' tablespace users;   
    5. RMAN> backup database plus archivelog delete all input;   
    6. RMAN> backup archivelog from sequence=234 delete input;   
    7. RMAN> backup tag='month_full_backup' datafile 1, 2, 3, 4;   
    8. RMAN> backup incremental level 0 database;   
    9. RMAN> backup incremental level 1 database;   
    10. RMAN> backup incremental level 1 cumulative database;   
    11.   
    12. RMAN> run {   
    13. 2> allocate channel c1 device type sbt;   
    14. 3> allocate channel c2 device type sbt;   
    15. 4> allocate channel c3 device type sbt;   
    16. 5> backup incremental level = 0   
    17. 6> format '/disk1/backup/df_%d_%s_%p.bak'  
    18. 7> (datafile 1,4,5 channel c1)   
    19. 8> (datafile 2,3,9 channel c2)   
    20. 9> (datafile 6,7,8 channel c3);   
    21. 10> alter system archive log current;   
    22. 11> }  
    RMAN> backup database;
    RMAN> backup copy of database;
    RMAN> backup as compressed backupset database;
    RMAN> backup as backupset format ''/BACKUP/df_%d_%s_%p.bus' tablespace users;
    RMAN> backup database plus archivelog delete all input;
    RMAN> backup archivelog from sequence=234 delete input;
    RMAN> backup tag='month_full_backup' datafile 1, 2, 3, 4;
    RMAN> backup incremental level 0 database;
    RMAN> backup incremental level 1 database;
    RMAN> backup incremental level 1 cumulative database;
    
    RMAN> run {
    2> allocate channel c1 device type sbt;
    3> allocate channel c2 device type sbt;
    4> allocate channel c3 device type sbt;
    5> backup incremental level = 0
    6> format '/disk1/backup/df_%d_%s_%p.bak'
    7> (datafile 1,4,5 channel c1)
    8> (datafile 2,3,9 channel c2)
    9> (datafile 6,7,8 channel c3);
    10> alter system archive log current;
    11> }
    

    7.2 block change tracking

    Sql代码 复制代码
    1. SQL> alter database enable block change tracking using file ''/mydir/rman_change_track.f' reuse;   
    2. SQL> alter database disable block change tracking;  
    SQL> alter database enable block change tracking using file ''/mydir/rman_change_track.f' reuse;
    SQL> alter database disable block change tracking;

    7.3 incrementally updating backups

    Sql代码 复制代码
    1. RMAN> backup as copy incremental level 0 datafile 1 tag 'basecopy';   
    2. RMAN> backup incremental level 1 for recover of copy with tag 'basecopy' datafile 1;   
    3. RMAN> recover copy of datafile 1 with tag 'basecopy';  
    RMAN> backup as copy incremental level 0 datafile 1 tag 'basecopy';
    RMAN> backup incremental level 1 for recover of copy with tag 'basecopy' datafile 1;
    RMAN> recover copy of datafile 1 with tag 'basecopy';

    7.4 list commands

    Sql代码 复制代码
    1. RMAN> list backup of database summary;   
    2. RMAN> list backup of tablespace system summary;   
    3. RMAN> list backup of datafile {n|'file_name'} summary;   
    4. RMAN> list backup of database by {file|backup};   
    5. RMAN> list copy of database;  
    RMAN> list backup of database summary;
    RMAN> list backup of tablespace system summary;
    RMAN> list backup of datafile {n|'file_name'} summary;
    RMAN> list backup of database by {file|backup};
    RMAN> list copy of database;
    

    7.5 report commands

    Sql代码 复制代码
    1. RMAN> report schema;   
    2. RMAN> report need backup incremental 0 database;   
    3. RMAN> report need backup days 3;   
    4. RMAN> report need backup redundancy 2;   
    5. RMAN> report need backup recovery window of 3 days;   
    6. RMAN> report obsolete redundancy 2;   
    7. RMAN> report obsolete recovery window of 3 days;  
    RMAN> report schema;
    RMAN> report need backup incremental 0 database;
    RMAN> report need backup days 3;
    RMAN> report need backup redundancy 2;
    RMAN> report need backup recovery window of 3 days;
    RMAN> report obsolete redundancy 2;
    RMAN> report obsolete recovery window of 3 days;

    7.6 delete commands

    Java代码 复制代码
    1. RMAN> delete noprompt expired copy;   
    2. RMAN> delete noprompt expired backup;   
    3. RMAN> delete noprompt obsolete;   
    4. RMAN> delete obsolete redundancy 2;   
    5. RMAN> delete obsolete recovery window of 3 days;   
    6. RMAN> delete backupset 4;  
    RMAN> delete noprompt expired copy;
    RMAN> delete noprompt expired backup;
    RMAN> delete noprompt obsolete;
    RMAN> delete obsolete redundancy 2;
    RMAN> delete obsolete recovery window of 3 days;
    RMAN> delete backupset 4;

    8. RMAN v$ views

    Java代码 复制代码
    1. V$ARCHIVED_LOG   
    2. V$BACKUP_CORRUPTION   
    3. V$BACKUP_DEVICE   
    4. V$BACKUP_FILES   
    5. V$BACKUP_PIECE   
    6. V$BACKUP_REDOLOG   
    7. V$BACKUP_SET   
    8. V$BACKUP_SPFILE   
    9. V$COPY_CORRUPTION   
    10. V$RMAN_CONFIGURATION  
  • 相关阅读:
    12306.cn网站自动登录器源代码
    从IL看C#
    CanvasRenderingContext2Dhtml5的关键
    慎用Response.Write()
    JPanel 的getGraphics
    怎么用swing绘图
    Win7 双硬盘启动出错处理
    paint repaint实现动画
    多线程一例
    画图,橡皮
  • 原文地址:https://www.cnblogs.com/sopost/p/2190155.html
Copyright © 2011-2022 走看看