返回顶部

欢迎来到菜鸟大明儿哥的博客

我们一起交流学习,不断提升自我

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_sh目录下:

(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:00全库,周一二四六晚20:00归档日志

crontab -e
 
00 20 * * 0,3,5 sh /backup_sh/run_rman_ecology_all.sh >> /backup/rman_crontab_all.log 2>&1
00 20 * * 1,2,4,6 sh /backup_sh/run_rman_ecology_arc.sh >> /backup/rman_crontab_arc.log 2>&1

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

9、重启计划任务:

service cron restart

 

posted @ 2021-12-02 10:51  菜鸟大明儿哥  阅读(257)  评论(0编辑  收藏  举报