rman命令

启动rman

rman target /

rman target sys/oracle@trgt nocatalog

rman target / catalog rman/cat@catdb

退出rman

RMAN> exit

在使用rman之前,设置NLS_DATE_FORMAT和NLS_LANG变量对于rman命令中的时间格式有帮助,下面是一个典型的设置。

NLS_LANG=american
NLS_DATE_FORMAT='Mon DD YYYY HH24:MI:SS'

在rman中使用命令文件,假如你的命令放在一个叫cmdfile的文件中,在rman中可以使用下面的方法来调用

RMAN>@cmdfile

检查rman命令的语法

有的时候想要先检查下命令是否有语法错误,使用checksyntax连接rman,这样命令不会真正的执行,只是去检查语法而已。

rman checksyntax

使用rman启动,停止数据库

% rman TARGET /
RMAN> SHUTDOWN IMMEDIATE # closes database consistently
RMAN> STARTUP MOUNT

改变数据库的状态

RMAN> SQL 'ALTER DATABASE OPEN';

重置rman命令回到默认值

configure .. clear  例如

RMAN> CONFIGURE BACKUP OPTIMIZATION CLEAR;
RMAN> CONFIGURE RETENTION POLICY CLEAR;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK CLEAR;

为磁盘备份配置备份类型,一个是镜像备份,一个是备份集备份

RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY; # image copies
RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET; # uncompressed
备份集压缩备份
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET;
配置通道,下面的命令备份到/backup目录下面
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/backup/ora_df%t_s%s_s%p';
配置控制文件和参数文件自动备份
下面这段话很重要

Because the filename for the autobackup uses a well-known format, RMAN can search for it without access to a repository, and then restore the server parameter file. After you have started the instance with the restored server parameter file, RMAN can restore the control file from an autobackup. After you mount the control file, the RMAN repository is available and RMAN can restore the datafiles and find the archived redo log.

启用及禁用自动备份控制文件

CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE CONTROLFILE AUTOBACKUP OFF;

指定控制文件自动备份的名字,名字中必须要有%F

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '?/oradata/cf_%F';

清除控制文件自动备份的设备

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK CLEAR;

配置时间闪回策略

RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

配置冗余的策略

CONFIGURE RETENTION POLICY TO REDUNDANCY 3;

禁用保留策略,这样备份就没有无效的了

CONFIGURE RETENTION POLICY TO NONE;

rman可以备份的文件

数据文件,控制文件和spfile

归档日志文件

rman的备份

以镜像的方式备份数据库

backup as copy device type disk database;

输出备份到指定目录

backup database formate="/tmp/backup_%U";

压缩备份集

backup as compressed backupset datafile 1,2,4;

备份整个数据库

backup database;

sql 'alter system archive log current';switches logs and archives all logs

通过咋备份整个库后,马上备份日志,确保备份中有在备份的时候生成的日志信息。这样可以完全恢复到备份时间点。

备份表空间

backup device type sbt maxsetsizxe=10M tablespace users,tools;

备份数据文件,下面备份了1,2,3,4数据文件,并且本分了数据文件的拷贝

backup device type sbt datafile 1,2,3,4 datafilecopy '/tmp/system01.dbf';

备份控制文件,要是控制文件没有设置成自动备份,需要手工备份如下:

1使用backup current controlfile

2使用backup命令的include current controlfile选项

BACKUP DEVICE TYPE sbt TABLESPACE users INCLUDE CURRENT CONTROLFILE;

3如果备份了数据文件1,会自动备份控制文件。

BACKUP DEVICE TYPE sbt SPFILE;

备份归档日志文件

BACKUP ARCHIVELOG ALL;

BACKUP ARCHIVELOG FROM TIME 'SYSDATE-30' UNTIL TIME 'SYSDATE-7';

delete input与 delete all input的区别

You can specify the DELETE INPUT or DELETE ALL INPUT clauses for the BACKUP ARCHIVELOG command to delete archived logs after they are backed up, eliminating the separate step of manually deleting the archived redo logs. With DELETE INPUT, RMAN only deletes the specific copy of the archived redo log chosen for the backup set. With DELETE ALL INPUT, RMAN will delete each backed-up archived redo log file from all log archiving destinations.

For example, assume that you archive to /arc_dest1, /arc_dest2, and /arc_dest3, and you run the following command:

BACKUP DEVICE TYPE sbt 
  ARCHIVELOG ALL 
  DELETE ALL INPUT;

In this case RMAN backs up only one copy of each log sequence number in these directories, and then deletes all copies of any log that it backed up from the archiving destinations. If you had specified DELETE INPUT rather than DELETE ALL INPUT, then RMAN would only delete the specific archived redo log files that it backed up (for example, it would delete the archived redo log files in /arc_dest1 if those were the files used as the source of the backup, but it would leave the contents of the /arc_dest2 and /arc_dest3 intact) .

在使用backup....plus archivelog的时候,rman做了下面的事

1运行alter system archiv log current

2运行backup archivelog all.

3备份backup命令中指定的文件

4运行alter system archive log current

5备份在备份期间产生的归档日志。

例如下面的命令备份了数据库和所有的归档日志

BACKUP DEVICE TYPE sbt DATABASE PLUS ARCHIVELOG;

增量备份中的1级备份

A differential backup, which backs up all blocks changed after the most recent incremental backup at level 1 or 0

  • A cumulative backup, which backs up all blocks changed after the most recent incremental backup at level 0

  • 下面的命令执行1级差异备份

  • BACKUP INCREMENTAL LEVEL 1 DATABASE;

    下面的备份是1级累计增量备份

    BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE; # blocks changed since level 0

    0级备份

    BACKUP INCREMENTAL LEVEL 0 DATABASE;

    对users表空间做1级增量备份

    BACKUP INCREMENTAL LEVEL = 1 CUMULATIVE TABLESPACE users;

    使用rman验证数据文件

    BACKUP VALIDATE DATABASE ARCHIVELOG ALL;

    要是发现了坏块,rman会更新v$database_block_corruption视图。

    list主要是用来列出哪个备份可用

    list backup;

    list backupset;

    list copy;

    list expired backup;

    list backup by file;

    list copy by file;

    list expired backup by file;

    list backup summary;

    LIST BACKUP OF DATABASE;
    LIST COPY OF DATAFILE 'ora_home/oradata/trgt/system01.dbf';
    LIST BACKUPSET 213;
    LIST DATAFILECOPY '/tmp/tools01.dbf';
    LIST INCARNATION;

    LIST INCARNATION OF DATABASE prod3;

    LIST INCARNATION OF DATABASE;

    report need backup 报告需要备份的文件

    REPORT NEED BACKUP RECOVERY WINDOW OFn DAYS

    REPORT NEED BACKUP REDUNDANCYn

    REPORT NEED BACKUP DAYS = n

    Displays files that require more than n days' worth of archived redo log files for recovery.

    RMAN> REPORT NEED BACKUP RECOVERY WINDOW OF 2 DAYS DATABASE SKIP TABLESPACE TBS_2; RMAN> REPORT NEED BACKUP REDUNDANCY 2 DATAFILE 1; RMAN> REPORT NEED BACKUP TABLESPACE TBS_3; # uses configured retention policy RMAN> REPORT NEED BACKUP INCREMENTAL 2; # checks entire database

    report unrecoverable

    When a datafile has been changed by an unrecoverable operation, such as a direct load insert, normal media recovery cannot be used to recover the file, because an unrecoverable operation does not generate redo. You must perform either a full or incremental backup of affected datafiles after such operations

    报告无效的备份

    REPORT OBSOLETE;

    报告数据文件信息

    REPORT SCHEMA;

    查看备份是否可用

    RESTORE DATABASE PREVIEW; RESTORE TABLESPACE users PREVIEW; RESTORE DATAFILE 3 PREVIEW; RESTORE ARCHIVELOG FROM LOGSEQ 200 PREVIEW; RESTORE ARCHIVELOG FROM TIME 'SYSDATE-7' PREVIEW; RESTORE ARCHIVELOG FROM SCN 234546 PREVIEW;

    验证备份

    RESTORE CONTROLFILE VALIDATE; RESTORE TABLESPACE SYSTEM VALIDATE; RESTORE ARCHIVELOG ALL VALIDATE; RESTORE DATAFILE 4,5,6 VALIDATE;

    crosscheck backup;

    crosscheck copy;

    crosscheck backupset;

    CROSSCHECK COPY OF DATABASE; CROSSCHECK BACKUPSET 1338, 1339, 1340; CROSSCHECK BACKUPPIECE TAG = 'nightly_backup'; CROSSCHECK CONTROLFILECOPY '/tmp/control01.ctl'; CROSSCHECK DATAFILECOPY 113, 114, 115; CROSSCHECK PROXY 789;

    CROSSCHECK BACKUP OF DATAFILE "?/oradata/trgt/system01.dbf" COMPLETED AFTER 'SYSDATE-14'; CROSSCHECK BACKUP OF ARCHIVELOG ALL SPFILE; CROSSCHECK BACKUP OF ARCHIVELOG ALL SPFILE;

    CROSSCHECK BACKUP OF DATAFILE 4 COMPLETED AFTER 'SYSDATE-14';

    DELETE BACKUPPIECE 101;
    DELETE CONTROLFILECOPY '/tmp/control01.ctl';
    DELETE NOPROMPT ARCHIVELOG UNTIL SEQUENCE = 300;
    DELETE BACKUP OF TABLESPACE users DEVICE TYPE sbt; # delete only from tape
    DELETE COPY OF CONTROLFILE LIKE '/tmp/%';  #
    DELETE ARCHIVELOG ALL BACKED UP 3 TIMES TO sbt;
    DELETE NOPROMPT ARCHIVELOG ALL;
    If you have not performed a crosscheck recently, then issue a CROSSCHECK command. For example, issue:
    1. CROSSCHECK BACKUP; # checks backup sets and copies on configured channels
      
      
    2. Delete the expired backups. For example, issue:

      DELETE EXPIRED BACKUP;
    
    DELETE FORCE NOPROMPT BACKUPSET TAG 'weekly_bkup';
    DELETE OBSOLETE;
    DELETE OBSOLETE REDUNDANCY = 3;
    
    DELETE OBSOLETE RECOVERY WINDOW OF 7 DAYS;
    改变备份文件的状态
    CHANGE DATAFILECOPY '/tmp/control01.ctl' UNAVAILABLE;
    CHANGE COPY OF ARCHIVELOG SEQUENCE BETWEEN 1000 AND 1012 UNAVAILABLE;
    CHANGE BACKUPSET 12 UNAVAILABLE;
    CHANGE BACKUP OF SPFILE TAG "TAG20020208T154556" UNAVAILABLE;
    CHANGE DATAFILECOPY '/tmp/system01.dbf' AVAILABLE;
    CHANGE BACKUPSET 12 AVAILABLE;
    CHANGE BACKUP OF SPFILE TAG "TAG20020208T154556" AVAILABLE;
    cataloging用户管理的数据文件备份
     catalog datafilecopy 'D:\oracle\product\10.2.0\arch2\users01.dbf';
    cataloging备份片
    CATALOG BACKUPPIECE '/disk2/09dtq55d_1_2', '/disk2/0bdtqdou_1_1';
    catalog一个磁盘位置下的所有文件
    CATALOG START WITH '/fs1/datafiles/'; 
    catalog闪回区
    CATALOG RECOVERY AREA;
     
      
    
    
    

    你可能感兴趣的:(命令,rman)