RMAN详细教程(四):备份脚本实战操作

RMAN详细教程(一):基本命令代码
RMAN详细教程(二):备份、检查、维护、恢复
RMAN详细教程(三):备份脚本的组件和注释
RMAN详细教程(四):备份脚本实战操作
  

1、为了安全起见,先将数据库完全导出:

exp 用户名/密码@ORACLE file=/backup/ecology_$(date '+%Y%m%d').dmp full=y;
 

2、因为是数据库操作,所以应切换成Oracle用户:

su - oracle
 

3、检查数据库是否打开归档模式,如否,则打开SQLPLUS执行以下命令:

archive log list;
alter system set log_archive_dest_n='location=/u01/backupws ';
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;

 

4、将rman脚本文件放置到backup_set目录下:

(1)全库备份(一周三次)
rman_ecology_all.sh

run {
    allocate channel a1 device type disk format '/backup/ecology_all_%T_%u';
    allocate channel a2 device type disk format '/backup/ecology_all_%T_%u';
    backup database skip offline plus archivelog delete all input;
    backup current controlfile;
    release channel a1;
    release channel a2;
}
    allocate channel for maintenance device type disk;
    delete obsolete;
    crosscheck backupset;

 
(2)归档日志备份(一周四次)
rman_ecology_arc.sh

run {
    allocate channel b1 device type disk format '/backup/ecology_arc_%T_%u';
    allocate channel b2 device type disk format '/backup/ecology_arc_%T_%u';
    backup archivelog all;
    backup current controlfile;
    release channel b1;
    release channel b2;
}
    allocate channel for maintenance device type disk;
    crosscheck backupset;

 

5、编写RMAN脚本的运行脚本:

mkdir -p /backup/ # 创建目录(-p表示不存在则新建,若存在则忽略)
touch run_rman_ecology_all.sh # 创建all运行脚本
touch run_rman_ecology_arc.sh # 创建arc运行脚本

vi run_rman_ecology_all.sh

export ORACLE_HOME=/u01/app/oracle/product/10.2/db_1
export ORACLE_SID=ecology
/u01/app/oracle/product/10.2/db_1/bin/rman target / log=/backup/all_ecology_$(date +%F).log cmdfile=/backup_sh/rman_ecology_all.sh
vi run_rman_ecology_arc.sh

export ORACLE_HOME=/u01/app/oracle/product/10.2/db_1
export ORACLE_SID=ecology
/u01/app/oracle/product/10.2/db_1/bin/rman target / log=/backup/arc_ecology_$(date +%F).log cmdfile=/backup_sh/rman_ecology_arc.sh

 

6、添加执行权限:

chmod +x /backup_sh/run_rman_ecology_all.sh
chmod +x /backup_sh/run_rman_ecology_arc.sh
PS:
需使用root用户。
 

7、手动测试脚本,成功之后再下一步。

若报错,则直接打开/var/spool/mail/登陆用户名,查看日志并改正。
 

8、添加定时任务:

周二四六晚20:30全库,周一三五七晚20:30归档日志

crontab -e

30 20 * * 2,4,6 /backup_sh/run_rman_ecology_all.sh
30 20 * * 0,1,3,5 /backup_sh/run_rman_ecology_arc.sh

格式是“分 时 日 月 周 要执行的命令或脚本”。
 

9、重启计划任务:

service cron restart
 
 
啊!总算完成了~~~
本来只是因为网上Rman的教程不系统化,想自己写一篇造福人类而已。
写着写着发现一篇写不下,太杂乱了ψ(*`ー´)ψ
于是就变成了两篇...然后是三篇....最后扩展成了四篇......
历时一个月,也算完成一个系列笔记了吧(^_−)☆

你可能感兴趣的:(RMAN详细教程(四):备份脚本实战操作)