rman备份与脚本

1. 建立rman表空间

SQL> create tablespace rman

 logging datafile '/u01/app/oracle/oradata/TBDB/rman.dbf'  size 1024M

 extent management local segment space  management auto;

 


2.创建rman备份账号

create user rman identified by rman default  tablespace rman;

grant connect,resource to rman;

grant recovery_catalog_owner to rman;

grant unlimited tablespace to rman;

grant sysdba to rman;


3.建立catalog数据库及注册数据库

rman catalog rman/rman

RMAN> create catalog tablespace  "RMAN";

RMAN> exit

  

  注: 需启动连接器,node222 为客户端连接服务器的标识符

rman target sys/oracle@node222 catalog rman/rman@node222

connected to target database: NODE222 (DBID=3694045568)
connected to recovery catalog database

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete


4.rman环境设置

   1) 设置保留30天的备份信息

   2)启用控制文件自动备份及备份存放位置配置

RMAN> configure retention policy to  recovery window of 30 days;

RMAN> configure controlfile autobackup  on;


5.查看配置信息

RMAN>show all;


6.备份策略

  每日0000进行一次全库备份 系统自动清除30天以前的备份信息

 

7. 创建备份必要目录(oracle身份创建)

mkdir /u01/app/oracle/backup

cd /u01/app/oracle/backup

mkdir controlfileback 存放备份的控制文件

mkdir dbback        存放备份的数据文件

mkdir log           存放备份生成的日志,坚持该日志查看备份是否成功

mkdir logback       存放归档日志文件

 


8. 备份脚本 cat /u01/app/oracle/backup/script/dbback.sh

#!/bin/bash

#this is rman auto full backup script

# Copyright by terrytsang

 

ORACLE_HOME=/u01/app/oracle/product/11.2.0/db1

NLS_LANG=AMERICAN_AMERICA.AL32UTF8

LD_LIBRARY_PATH=$ORACLE_HOME/lib

ORACLE_BASE=/u01/app/oracle

ORACLE_SID=TBDB

export ORACLE_HOME  LD_LIBRARY_PATH NLS_LANG ORACLE_BASE  ORACLE_SID

 

 

backtime=`date +"20%y%m%d%H%M%S"` 

cd $ORACLE_HOME/bin

rman target / catalog rman/rman log=/u01/app/oracle/backup/log/backupall_$backtime.log  <<EOF

run{

   allocate channel c1 device type disk;

   allocate channel c2 device type disk;

   allocate channel c3 device type disk;

   allocate channel c4 device type disk;

   allocate channel c5 device type disk;

   crosscheck backup;

 

   sql 'alter system archive log current';

     backup database format '/u01/app/oracle/backup/dbback/db_%d_%T_%U';

   sql 'alter system archive log current';

     backup archivelog all format '/u01/app/oracle/backup/logback/arc_%t_%s'  delete all input; 

     backup current controlfile format '/u01/app/oracle/backup/controlfileback/cntrl_%s_%p_%s'; 

   crosscheck archivelog all;

 

  delete  noprompt expired backup;

  delete  noprompt obsolete;

  delete  noprompt backup of database completed before 'sysdate - 30';

  release  channel c1;

   release channel c2;

   release channel c3;

   release channel c4;

   release channel c5;

}

EOF

echo "backup complete!"


9. 定义备份时间间隔

crontab 0 0 * * * /u01/app/oracle/backup/script/dbback.sh  2>&1 >/dev/null

 

 

上一篇:使用组策略实现统一企业形象


下一篇:DDOS攻击类型以及iptables防范ddos脚本