这个脚本比较简单:
周天对数据库进行全备,周一到周六进行归档日志备份。
[oracle@T10 ~]$ cat backup.sh
#!/bin/bash
#oracle backup script
btime=`date +%A`
export ORACLE_SID=snzo
export ORACLE_HOME=/u01/oracle/product/10g/db
if [ $btime = "Sunday" ] ; then
/u01/oracle/product/10g/db/bin/rman target / cmdfile=/home/oracle/datafile.sql log=/home/oracle`date +%Y-%m-%d`_dbf.log
else
/u01/oracle/product/10g/db/bin/rman target / cmdfile=/home/oracle/archive.sql log=/home/oracle/`date +%Y-%m-%d`_arc.log
fi
备份数据库的数据库脚本:
[oracle@T10 ~]$ cat datafile.sql
run
{
allocate channel ch1 type disk;
allocate channel ch2 type disk;
backup database format '/u01/oracle/backup/%U_%T.dbf';
backup archivelog all delete input format '/u01/oracle/backup/%U_%T.arc';
release channel ch1;
release channel ch2;
}
exit
备份归档日志的脚本:
[oracle@T10 ~]$ cat archive.sql
run
{
allocate channel ch1 type disk;
backup archivelog all delete input format '/u01/oracle/backup/%U_%T.arc';
release channel ch1;
}
exit
设置crontab:
[oracle@T10 ~]$ crontab -l
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/u01/orace/product/10g/db/bin
HOME=/home/oracle
*/5 * * * * /home/oracle/backup.sh
此处为测试,没5分钟进行一次备份。
最后查看备份结果:
[oracle@T10 ~]$ cat 2011-10-19_arc.log
Recovery Manager: Release 10.2.0.4.0 - Production on Wed Oct 19 16:55:01 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: SNZO (DBID=2088621957)
RMAN> run
2> {
3> allocate channel ch1 type disk;
4> backup archivelog all format '/u01/oracle/backup/%U_%T.arc';
5> release channel ch1;
6> }
7> exit
using target database control file instead of recovery catalog
allocated channel: ch1
channel ch1: sid=10 devtype=DISK
Starting backup at 19-OCT-11
current log archived
channel ch1: starting archive log backupset
channel ch1: specifying archive log(s) in backup set
input archive log thread=1 sequence=102 recid=14 stamp=764953366
input archive log thread=1 sequence=103 recid=15 stamp=764953435
input archive log thread=1 sequence=104 recid=16 stamp=764956491
input archive log thread=1 sequence=105 recid=17 stamp=764958304
input archive log thread=1 sequence=106 recid=18 stamp=764958604
input archive log thread=1 sequence=107 recid=19 stamp=764958903
input archive log thread=1 sequence=108 recid=20 stamp=764959203
input archive log thread=1 sequence=109 recid=21 stamp=764959503
input archive log thread=1 sequence=110 recid=22 stamp=764959803
input archive log thread=1 sequence=111 recid=23 stamp=764960103
channel ch1: starting piece 1 at 19-OCT-11
channel ch1: finished piece 1 at 19-OCT-11
piece handle=/u01/oracle/backup/1rmpgnb7_1_1_20111019.arc tag=TAG20111019T165503 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:02
Finished backup at 19-OCT-11
Starting Control File and SPFILE Autobackup at 19-OCT-11
piece handle=/u01/oracle/backup/c-2088621957-20111019-0d comment=NONE
Finished Control File and SPFILE Autobackup at 19-OCT-11
released channel: ch1
Recovery Manager complete.
阅读(3248) | 评论(0) | 转发(0) |