第二组命令总结来了,rman的命令那么多,实用的很多,不常用的也很多,不如先来个鸡肋。比如检查语法
[oracle@hdp _08_11]$ rman CHECKSYNTAX @rman.sh
Recovery Manager: Release .. - Production on Fri Aug ::
Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
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> allocate channel c5 type disk;
7> allocate channel c6 type disk;
8> backup as compressed backupset database plus archivelog;
9> release channel c1;
10> release channel c2;
11> release channel c3;
12> release channel c4;
13> release channel c5;
14> release channel c6;
15> }
16>
**The cmdfile has no syntax errors**
Recovery Manager complete.
[oracle@hdp _08_11]$
故意让其报错
13> release channel c5;
14> release channe
RMAN-: ===========================================================
RMAN-: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-: ===========================================================
RMAN-: error encountered while parsing input commands
RMAN-: syntax error: found "identifier": expecting one of: "channel"
RMAN-: the bad identifier was: channe
RMAN-: at line column file: rman.sh
就连rman的登录,也可以有好几种玩法:
[[email protected] _08_11]$ rman target/
Recovery Manager: Release - Production on Fri Aug ::
Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=)
RMAN> exit
Recovery Manager complete.
[[email protected] _08_11]$ rman
Recovery Manager: Release - Production on Fri Aug ::
Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
RMAN> connect target/
connected to target database: ORCL (DBID=)
[[email protected] _08_11]$ rman target sys/
Recovery Manager: Release - Production on Fri Aug ::
Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
target database Password:
connected to target database: ORCL (DBID=)
RMAN>
好了 就这么多,oralce做事情也是够开放的,能够提供接口的就一定会提供给DBA。这样好的 开放性,也保证了数据库在出问题的时候,不会让用户抓瞎。就像sqlserver那样。(我这样黑人家是不对的!!!)
什么?鸡肋不好吃,那上硬菜呗,洒家这里有平时用的rman 每日全备份的脚本,也是我平时工作中用到的,也是真正的好用不贵。
#!/bin/sh
export ORACLE_HOME=/u01/app/oracle/product/./db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH
export BKDIR="/u01/backup/rmanbackup"
export LOGDIR="/u01/backup/scripts/rmanlogs"
export DATE=`date +%Y%m%d`
mkdir -p ${BKDIR}/${DATE}
export JOB_BEGIN=`date +"%Y%m%d_%H%M"`
LOGFILE=${LOGDIR}/${JOB_BEGIN}_rman_level0.log
RMANLOGFILE=${LOGDIR}/${JOB_BEGIN}_rman_level0.log
echo "${JOB_BEGIN} Rman Backup Start" >> $LOGFILE
echo "" >> $LOGFILE
$ORACLE_HOME/bin/rman target / nocatalog msglog=${RMANLOGFILE} <<EOF
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
allocate channel d5 type disk;
allocate channel d6 type disk;
backup as compressed backupset incremental level database format '${BKDIR}/${DATE}/PROD_db_full_%d_%T_%s_%U';
sql 'alter system archive log current';
backup as compressed backupset format '${BKDIR}/${DATE}/PROD_arch_%d_%T_%s_%U' archivelog all delete input;
backup as copy current controlfile format '${BKDIR}/${DATE}/PROD_ctl_%d_%T_%s_%U';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
release channel d5;
release channel d6;
}
exit
EOF
echo " Done @`date +%Y%m%d_%H%M`" >> $LOGFILE
echo " " >> $LOGFILE
每日都会生成数据库的level0 级别的备份哦!
其实上面备份脚本的意思,也大致是这样吧:
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM BACKUP TYPE TO BACKUPSET
> ;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored
released channel: ORA_DISK_1
RMAN> backup as compressed backupset incremental level database;
当然可能要加上:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
oracle很友好的为我建好了如下目录:
/u02/backup/ORCL/autobackup/_08_11
前提是我修改了一个参数的值:
SQL> show parameter db_recovery
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
db_recovery_file_dest string /u02/backup
db_recovery_file_dest_size big integer M
SQL>
因为db_recovery_file_dest 最好还是不要放在dbs目录下。我不想再查看alert.log日志时看到一堆备份文件。何况还有那么多转存文件
备份归档日志:
RMAN> backup archivelog all delete input;
删除原有日子,只保留归档。
或者单纯的备份归档日志
RMAN> backup archivelog all
不过我们在工作中,不可能这么随意,而且给予备份各种标记,本座一般这样玩:
RMAN> backup archivelog all format'/u02/backup/ORCL/backupset/2017_08_11/hdp_arch_%d_%T_%s_%U.ctl';
检查备份的文件名称:
/u02/backup/ORCL/backupset/2017_08_11/hdp_arch_ORCL_20170811_45_1dsbkf9k_1_1.ctl
hdp_arch_%d_%T_%s_%U.ctl';
%d database name
%T date
%s 备份集的号
%U 这是唯一的文件号
这里为大家列举一下常用的格式字符串
%c 备份片的拷贝数
%d 数据库名称
%D 位于该月中的第几天 (DD)
%M 位于该年中的第几月 (MM)
%F 一个基于DBID唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII为该数据库的DBID,YYYYMMDD为日期,QQ是一个1-256的序列
%n 数据库名称,向右填补到最大八个字符
%u 一个八个字符的名称代表备份集与创建时间
%p 该备份集中的备份片号,从1开始到创建的文件数
%U 一个唯一的文件名,代表%u_%p_%c
%s 备份集的号
%t 备份集时间戳
%T 年月日格式(YYYYMMDD)