ORACLE服务器定时备份怎么做

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ORACLE服务器定时备份怎么做相关的知识,希望对你有一定的参考价值。

    编写备份数据库脚本。新建文本文档,粘贴如下内容:

    echo 开始备份数据库

    if not exist F:\\db_bak\\files md F:\\db_bak\\files

    if not exist F:\\db_bak\\logs md F:\\db_bak\\logs

     

    set var=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%

    exp ora_user/ora_pwd@ora_conn file=F:\\db_bak\\files\\xxxx_%var%.dmp log=F:\\db_bak\\logs\\xxxx_%var%.log owner=(user1,user2)

     

    echo 删除过久的备份记录

    forfiles /p "F:\\db_bak" /s /m  *.dmp /d -60 /c "cmd /c del @path"

    forfiles /p "F:\\db_bak" /s /m  *.log /d -60 /c "cmd /c del @path"

    exit

    把文本文档后缀名修改成.bat。

    bat文件在windows下为可执行文件。

    找到windows系统下的“任务计划程序”。

    在WIN7下的位置是:开始--所有程序--附件--系统工具--任务计划程序

    使用任务计划程序“创建基本任务”。,下一步:

    选择任务何时开始执行,(选择每天),下一步:

    设置任务开始执行的具体时间,(设置成零晨3点),下一步:

    选择任务执行的具体操作,(启动程序),下一步:

    选择程序或脚本,通过“浏览”按钮把我们在第1、2步骤编写好的bat文件指定好。,下一步:

    任务创建好了。点击完成即可。至此,定时备份oracle数据库的操作已经完成

参考技术A 新建一个TXT文件,里面内容:
connect target /;
crosscheck archivelog all;
crosscheck backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
delete expired copy;
delete noprompt expired backup;
run
backup as compressed backupset database format 'G:\rman\rmanbak\full_%d_%T_%t_%s' tag='fullbak';
backup as compressed backupset archivelog all delete all input skip inaccessible format 'G:\rman\rmanbak\ARCH\ARC_%U';
backup current controlfile format G:\rman\rmanbak\control\control_bak_%T';


再新建一个bat文件,里面内容:
rman cmdfile=''D:/oracle/backup/full_rman.txt' msglog='D:/oracle/backup/log/full_rmanlog%date:~4,10%.log'

计划任务里面添加,每日定时运行这个bat文件!本回答被提问者和网友采纳

[原创]Oracle 12c的备份和恢复策略

Oracle 12c的备份和恢复策略(RMAN备份[开启归档/控制文件/数据文件/归档日志]):
备份策略:
	* 每半年做一个数据库的全备份(包括所有的数据和只读表空间) 
	* 每周做一次零级备份
	* 每天做一次一级备份 
*备份前设置rman的参数:configure controlfile autobackup on;(RMAN> show all;查看参数)
--crontab定时任务:
0 1 1 1,7 * oracle /bin/bash /data/oracle/backup/rman_bak_full.sh >>/tmp/rman_backup.log 2>&1
0 1 * * 0 oracle /bin/bash /data/oracle/backup/rman_bak_0.sh >>/tmp/rman_backup.log 2>&1
0 1 * * 1-6 oracle /bin/bash /data/oracle/backup/rman_bak_1.sh >>/tmp/rman_backup.log 2>&1
================================================================================================================
一、备份:
1)数据库全备份的脚本:
#cat /data/oracle/backup/rman_bak_full.sh
#!/bin/bash

export ORACLE_SID=bieeocrl
export ORACLE_BASE=/data/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_DATE_FORMAT=‘YYYY-MM-DD HH24:MI:SS‘

curr_t=`date +%Y%m%d%H%M%S`
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘Start FULL Backup at ‘`date +%Y-%m-%d:%H:%M:%S` | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log

rman target / nocatalog log /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log append<<EOF_RMAN
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup full tag ‘dbfull‘ format ‘/data/oracle/backup/bieeocrl/full_bak_%U_%s_%T‘ as compressed backupset database include current controlfile;
sql ‘alter system archive log current‘;
backup archivelog all delete input tag=‘arch_bak‘ format ‘/data/oracle/backup/bieeocrl/arch_%U_%s_%T‘;
backup current controlfile tag=‘ctl_bak‘format ‘/data/oracle/backup/bieeocrl/full_control_%U_%s_%T‘;
backup spfile tag=‘spfile_bak‘ format ‘/data/oracle/backup/bieeocrl/spfile_%U_%s_%T‘;#参数文件备份可选
release channel c1;
release channel c2;
release channel c3;
}
EOF_RMAN
2)零级备份的脚本:
#cat /data/oracle/backup/rman_bak_0.sh
#!/bin/bash

export ORACLE_SID=bieeocrl
export ORACLE_BASE=/data/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_DATE_FORMAT=‘YYYY-MM-DD HH24:MI:SS‘

curr_t=`date +%Y%m%d%H%M%S`
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘Start level 0 Backup at ‘`date +%Y-%m-%d:%H:%M:%S` | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log

rman target / nocatalog log "/data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log" append<<EOF_RMAN
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup incremental level 0 tag ‘db0‘ format ‘/data/oracle/backup/bieeocrl/db0_%U_%s_%T‘ as compressed backupset database;
sql ‘alter system archive log current‘;
backup archivelog all delete input tag=‘arch_bak‘ format ‘/data/oracle/backup/bieeocrl/arch0_%U_%s_%T‘;
backup current controlfile tag=‘ctl_bak‘format ‘/data/oracle/backup/bieeocrl/db0_control_%U_%s_%T‘;
backup spfile tag=‘spfile_bak‘ format ‘/data/oracle/backup/bieeocrl/spfile0_%U_%s_%T‘;#参数文件备份可选
release channel c1;
release channel c2;
release channel c3;
}
EOF_RMAN
3)一级备份的脚本:
#cat /data/oracle/backup/rman_bak_1.sh
#!/bin/bash

export ORACLE_SID=bieeocrl
export ORACLE_BASE=/data/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_DATE_FORMAT=‘YYYY-MM-DD HH24:MI:SS‘

curr_t=`date +%Y%m%d%H%M%S`
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘Start level 1 Backup at ‘`date +%Y-%m-%d:%H:%M:%S` | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log
echo ‘-------------------------------------------‘ | tee >> /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log

rman target / nocatalog log /data/oracle/backup/bieeocrl/rman_bak_${curr_t}.log append<<EOF_RMAN
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup incremental level 1 tag ‘db1‘ format ‘/data/oracle/backup/bieeocrl/db1_%U_%s_%T‘ as compressed backupset database;
sql ‘alter system archive log current‘;
backup archivelog all delete input tag=‘arch_bak‘ format ‘/data/oracle/backup/bieeocrl/arch1_%U_%s_%T‘;
backup current controlfile tag=‘ctl_bak‘format ‘/data/oracle/backup/bieeocrl/db1_control_%U_%s_%T‘;
backup spfile tag=‘spfile_bak‘ format ‘/data/oracle/backup/bieeocrl/spfile1_%U_%s_%T‘;#参数文件备份可选
release channel c1;
release channel c2;
release channel c3;
}
EOF_RMAN
如果按照以上oracle备份策略,则每天的所需要备份的数据量只有一天的改变量。而做恢复时最多要恢复一个零级备份+六个一级备份。
================================================================================================================
二、恢复数据库的过程:
1)rman target / nocatalog
2)RMAN> startup nomount;
3)RMAN> restore spfile from ‘/data/oracle/backup/bieeocrl/db0_%U_%s_%T‘;
4)RMAN> shutdown immediate;
5)RMAN> startup nomount;
6)RMAN> restore controlfile from ‘/data/oracle/backup/bieeocrl/db0_control_%U_%s_%T‘;
7)RMAN> alter database mount;
8)RMAN> catalog start with ‘/data/oracle/backup/bieeocrl/arch0_%U_%s_%T‘;
9)RMAN> run{
allocate channel ch1 type disk;
restore database;
recover database;
release channel ch1;
}
10)RMAN> alter database open resetlogs;
11)RMAN> shutdown immediate;
12)RMAN> startup;
================================================================================================================

  

以上是关于ORACLE服务器定时备份怎么做的主要内容,如果未能解决你的问题,请参考以下文章

备机怎样定时备份主机的Oracle数据库

oracle备份以及定时上传备份服务器

linux下怎么定时备份oracle数据库

Linux下Oracle定时自动备份方案

oracle定时备份,用expdp的跨服务器备份

设置oracle11g定时自动备份,为啥没有备份?请大神们帮我看看为啥!