rman是oracle的一个强大的工具,工作经验积累,直奔主题,如何使用rman工具进行脚本全库备份。
1.建立rman表空间
SQL> create tablespace rman
2 logging datafile '/opt/oracle/oradata/rman/rman.dbf' size 1024M
3 extent management local segment space management auto;
2.创建rman备份账号
SQL> create user rman identified by rman default tablespace rman;
SQL> grant connect,resource to rman;
SQL> grant recovery_catalog_owner to rman;
SQL> grant unlimited tablespace to rman;
SQL> grant sysdba to rman;
3.查看日志是否归档
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 14
Next log sequence to archive 16
Current log sequence 16
4.建立catalog数据库及注册数据库
oracle@linux-nao:~> rman catalog rman/rman
Recovery Manager: Release 11.1.0.6.0 - Production on 星期三3月21 16:10:49 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to recovery catalog database RMAN> create catalog tablespace "RMAN"; recovery catalog created RMAN> exitoracle@linux-nao:~> rman target sys/oracle@orcl catalog rman/rman@orcl
Recovery Manager: Release 11.1.0.6.0 - Production on 星期三3月21 16:20:34 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1305015629)
connected to recovery catalog database
RMAN> register database; database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
5.rman环境设置
1) 设置保留30天的备份信息,
RMAN> configure retention policy to recovery window of 30 days;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
2) 启用控制文件自动备份及备份存放位置配置
RMAN> configure controlfile autobackup on;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
6.查看配置信息
RMAN> show all;
7.备份策略
每周日00:00进行一次全库备份
系统自动清除30天以前的备份信息
8.创建备份必要目录(以oracle身份创建)
mkdir backup
cd backup
mkdir controlfileback 存放备份的控制文件
mkdir dbback 存放备份的数据文件
mkdir log 存放备份生成的日志,坚持该日志查看备份是否成功
mkdir logback 存放归档日志文件
9.全库备份脚本dbback.sh
10.crontab自动执行 1)以root身份编辑cron.allow文件,手动添加oracle用户允许使用cron服务。 启动cron服务 /etc/init.d/cron start
- #!/bin/bash
- #this is rman auto full backup script
- #Copyright by 21og
- #date 2012-03-21
- export ORACLE_SID=orcl
- export ORACLE_HOME=/opt/oracle/product/10.2/db_1
- export ORACLE_BASE=/opt/oracle
- export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
- backtime=`date +"20%y%m%d%H%M%S"`
- cd $ORACLE_HOME/bin
- rman target / catalog rman/rman log=/opt/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 '/opt/oracle/backup/dbback/db_%d_%T_%U';
- sql 'alter system archive log current';
- backup archivelog all format '/opt/oracle/backup/logback/arc_%t_%s' delete all input;
- backup current controlfile format '/opt/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!"
2)以oracle身份执行crontab -e
0 0 * * 0 /opt/oracle/backup/script/dbback.sh 2>&1 >/dev/null
OK,所有操作完毕,好累~~~
本文出自 “我就是我非此非彼” 博客,请务必保留此出处http://wukui127.blog.51cto.com/2866802/812761