Home >Database >Mysql Tutorial >Linux下使用crontab进行RMAN备份实验

Linux下使用crontab进行RMAN备份实验

WBOY
WBOYOriginal
2016-06-07 17:32:06953browse

要定义环境变量,即使是使用的ORACLE用户crontab -e编辑的。source /home/oracle/.bash_profile或者直接将/home/oracle/.bash_pr

之前写了脚本(见  ),手动执行可以,使用crontab总是无法运行成功,今天下午花了两个小时实验,完成如下:
注意事项:脚本完成首先手动执行,确定可以正常执行。

在crontab中使用,要注意以下几点:
1.要定义环境变量,即使是使用的Oracle用户crontab -e编辑的。source /home/oracle/.bash_profile或者直接将/home/oracle/.bash_profile内容放在备份脚本最前面。

2.然后注意脚本中调用RMAN时要用绝对路径,,不然使用crontab无法运行成功。

如:/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman 

下面是备份脚本及LINUX中设置crontab

一、备份脚本格式如下:只用了一个备份归档日志的脚本,比全备速度快方便实验。更多脚本参考上一篇博客。
[oracle@oel-01 ~]$ cat archback.sh
#!/bin/sh
#su - oracle
source /home/oracle/.bash_profile
#########back arch test 0704
/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman  log /home/oracle/rman-arch`date +%Y%m%d-%H%M`.log connect target /;
run{
backup archivelog all delete input
format '/backup/archlog/arch_%d_%T_%s';
}
exit


二、在LINUX中设置crontab定时任务。在7月4号16点53分执行。
[oracle@oel-01 ~]$ crontab -e
53 16 4 7 * /home/oracle/archback.sh
按SHIFT+ZZ保存和在VI里一样哈哈。这里设置的是7月4号的16点53执行。
[oracle@oel-01 ~]$ crontab -l
53 16 4 7 * /home/oracle/archback.sh
[oracle@oel-01 ~]$
这样就可以了。

三、使用archback.sh 脚本生成的日志:
[oracle@oel-01 ~]$ ls -al rman-arch20130704-1653.log
-rw-r--r-- 1 oracle oinstall 1246 Jul  4 16:53 rman-arch20130704-1653.log
[oracle@oel-01 ~]$ cat rman-arch20130704-1653.log

Recovery Manager: Release 11.2.0.1.0 - Production on Thu Jul 4 16:53:01 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

RMAN>
connected to target database: BYS001 (DBID=2041679290)

RMAN> 2> 3> 4>
Starting backup at 04-JUL-13
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=41 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=19 RECID=111 STAMP=819910382
channel ORA_DISK_1: starting piece 1 at 04-JUL-13
channel ORA_DISK_1: finished piece 1 at 04-JUL-13
piece handle=/backup/archlog/arch_BYS001_20130704_119 tag=TAG20130704T165302 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/archbys001/arch_19_1_818895125.arc RECID=111 STAMP=819910382
Finished backup at 04-JUL-13

Starting Control File and SPFILE Autobackup at 04-JUL-13
piece handle=/backup/ctl_c-2041679290-20130704-04 comment=NONE
Finished Control File and SPFILE Autobackup at 04-JUL-13

RMAN>

Recovery Manager complete.

推荐阅读:

Oracle基础教程之通过RMAN复制数据库

RMAN备份策略制定参考内容

RMAN备份学习笔记

Oracle数据库备份加密 RMAN加密

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn