首页 > 代码库 > RMAN连接及简单操作
RMAN连接及简单操作
一、RMAN的进入与退出
1、启动RMAN并连接到本地目标数据库
C:\Users\Administrator>set oracle_sid=orcl(如果只有一个实例,则不需要指定,RMAN会自动连接到默认实例)C:\Users\Administrator>rman target/恢复管理器: Release 11.2.0.1.0 - Production on 星期二 10月 7 11:42:57 2014Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.连接到目标数据库: ORCL (DBID=1385990360)RMAN>
2、可以先启动RMAN,再通过CONNECT创建连接
C:\Users\Administrator>RMAN恢复管理器: Release 11.2.0.1.0 - Production on 星期二 10月 7 11:51:53 2014Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.RMAN> CONNECT TARGET/连接到目标数据库: ORCL (DBID=1385990360)RMAN>
3、连接到远程数据库
C:\Users\Administrator>rman target sys/rusking@orcl;恢复管理器: Release 11.2.0.1.0 - Production on 星期二 10月 7 12:01:56 2014Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.连接到目标数据库: ORCL (DBID=1385990360)RMAN>
4、记录RMAN日志
C:\Users\Administrator>rman target/ log d:\rman_logs.txtRMAN>
5、退出RMAN
通过执行host命令暂时退出rman的命令提示符而进入到操作系统的命令环境
C:\Users\Administrator>rman target/恢复管理器: Release 11.2.0.1.0 - Production on 星期二 10月 7 12:10:45 2014Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.连接到目标数据库: ORCL (DBID=1385990360)RMAN> host;Microsoft Windows [版本 6.1.7600]版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Users\Administrator>sqlplus / as sysdba;SQL*Plus: Release 11.2.0.1.0 Production on 星期二 10月 7 12:10:58 2014Copyright (c) 1982, 2010, Oracle. All rights reserved.连接到:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> exit从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options 断开C:\Users\Administrator>exit主机命令完成RMAN>
二、RMAN简单命令
1、在RMAN下启动和关闭数据库(跟SQL环境一样)
RMAN> shutdown immediate;使用目标数据库控制文件替代恢复目录数据库已关闭数据库已卸装Oracle 实例已关闭RMAN> startup已连接到目标数据库 (未启动)Oracle 实例已启动数据库已装载数据库已打开系统全局区域总计 855982080 字节Fixed Size 2180544 字节Variable Size 654314048 字节Database Buffers 192937984 字节Redo Buffers 6549504 字节RMAN>
也可以执行startup mount,然后再利用alter database open命令打开数据库以及shutdown normal,shutdown abort等。
2、RMAN下执行SQL语句
rman中的sql环境不能执行SELECT语句。
RMAN> SQL ‘ALTER SYSTEM ARCHIVE LOG ALL‘;RMAN> SQL ‘select 1+2 from dual‘;sql 语句: select 1+2 from dualRMAN> SQL ‘select * from scott.emp‘;sql 语句: select * from scott.emp
3、查看及修改RMAN配置
RMAN> show all;db_unique_name 为 ORCL 的数据库的 RMAN 配置参数为:CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # defaultCONFIGURE BACKUP OPTIMIZATION ON;CONFIGURE DEFAULT DEVICE TYPE TO DISK;CONFIGURE CONTROLFILE AUTOBACKUP ON;CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘%F‘; # defaultCONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # defaultCONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # defaultCONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # defaultCONFIGURE CHANNEL DEVICE TYPE DISK FORMAT ‘D:\oracle_bak_test\%U‘;CONFIGURE MAXSETSIZE TO UNLIMITED; # defaultCONFIGURE ENCRYPTION FOR DATABASE OFF; # defaultCONFIGURE ENCRYPTION ALGORITHM ‘AES128‘; # defaultCONFIGURE COMPRESSION ALGORITHM ‘BASIC‘ AS OF RELEASE ‘DEFAULT‘ OPTIMIZE FOR LOAD TRUE ; # defaultCONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # defaultCONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘D:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_1\DATABASE\SNCFORCL.ORA‘; # defaultRMAN> CONFIGURE BACKUP OPTIMIZATION OFF;旧的 RMAN 配置参数:CONFIGURE BACKUP OPTIMIZATION ON;新的 RMAN 配置参数:CONFIGURE BACKUP OPTIMIZATION OFF;已成功存储新的 RMAN 配置参数RMAN> show channel;db_unique_name 为 ORCL 的数据库的 RMAN 配置参数为:CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT ‘D:\oracle_bak_test\%U‘;RMAN> show device type;db_unique_name 为 ORCL 的数据库的 RMAN 配置参数为:CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # defaultRMAN> show default device type;db_unique_name 为 ORCL 的数据库的 RMAN 配置参数为:CONFIGURE DEFAULT DEVICE TYPE TO DISK;RMAN>
4、列出备份信息
列出数据库中所有文件的备份信息:RMAN>LIST BACKUP OF DATABASE;列出指定表空间的备份信息:RMAN>LIST COPY OF TABLESPACE ‘SYSTEM‘;列出指定数据文件的备份信息:RMAN>LIST BACKUP OF DATAFILE ‘D:\RUSKY\RUSKY_DATA01,DBF‘;
5、删除备份
用于删除RMAN备份记录及相应的物理文件。当使用RMAN执行备份操作时,会在RMAN资料库中生成RMAN备份记录,并且RMAN备份记录被存放在目标数据库的控制文件中,如果配置了恢复目录,那么该备份记录也会被存放到恢复目录中。
5.1、删除陈旧备份
当使用RMAN执行备份操作时,RMAN会根据备份冗余策略确定陈旧备份。
RMAN> delete obsolete;
5.2、删除EXPIRED备份
执行crosscheck命令核对备份集,那么会将该备份集标记为EXPIRED状态。为了删除相应的备份记录,可以执行delete expired backup命令。
RMAN> delete expired backup;
5.3、删除EXPIRED副本
RMAN> delete expired copy;
5.4、删除特定备份集
RMAN> delete backupset 22;
5.5、删除特定备份片
RMAN> delete backuppiece ‘d:\backup\rusky.bak‘;
5.6、删除所有备份集
RMAN> delete backup;
5.7、删除特定映像副本
RMAN> delete datafilecopy ‘d:\backup\rusky.bak‘;
5.8、删除所有映像副本
RMAN> delete copy;
5.9、在备份后删除输入对象
RMAN> delete archivelog all delete input;
RMAN> delete backupset 22 format = ‘‘d:\backup\%u.bak‘‘ delete input;
RMAN连接及简单操作