windows环境下的oracle数据库的备份方案
(1) 备份目的
为防止系统出现操作失误或系统故障导致数据丢失以及介质损坏导致的问题,所以需要对数据库进行备份
(2) 备份方式:
1.物理备份(使用rman对数据库进行备份)
2.逻辑备份(使用expdp对数据库进行备份)
(3) 备份策略:
物理备份策略每周的周日凌晨3:00对数据库进行全量备份,周二,周四,周六的凌晨3:00对数据库进行一级增量备份
逻辑备份策略每1月对数据库进行一次逻辑导出备份,每个月的1号凌晨1:00
注:
备份保留30天,30天前的删除,设置如下:
SQL> alter system setcontrol_file_record_keep_time=60;
系统已更改。
SQL> show parametercontrol_file_record_keep_time;
NAME TYPE VALUE
control_file_record_keep_time integer 60
RMAN> configure retentionpolicy to recovery window of 30 days;
新的 RMAN 配置参数:
CONFIGURE RETENTION POLICY TORECOVERY WINDOW OF 30 DAYS;
已成功存储新的RMAN 配置参数
RMAN> show all;
db_unique_name 为 ORA 的数据库的 RMAN配置参数为:
CONFIGURE RETENTION POLICY TORECOVERY WINDOW OF 30 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF;# default
备份说明:
(4) 物理备份
规划备份文件存放目录,并建立相应的目录,如备份目录
0级备份脚本:rmanbklevel_0.sql
run{
allocate channel cha1 type disk;
crosscheck archivelog all;
delete noprompt expired archivelog all;
crosscheck backup;
delete noprompt expired backup;
sql 'alter system archive log current';
backup
incremental level 0
database format'D:\archiveoracle\backup\incremental_level0_%d_%T_%s_%p'
plus archivelog format'D:\archiveoracle\backup\arch_%d_%T_%s_%p' delete all input;
backup current controlfile format 'D:\archiveoracle\backup\ctrl_%d_%I_%T_%s_%p';
report obsolete;
delete noprompt obsolete;
release channel cha1;
}
批处理脚本:rmanbklevel_0.bat
rman target /cmdfile='D:\archiveoracle\rmanbklevel_0.sql'log='D:\archiveoracle\rmanbklevel_0.log' append
1级备份脚本:rmanbklevel_1.sql
run{
allocate channel cha1 type disk;
backup
incremental level 1 database
format'D:\archiveoracle\backup\level1\incremental_level1_%u_%T' plus archivelog
format'D:\archiveoracle\backup\level1\arch_%d_%T_%s_%p' delete all input;
backup current controlfile format'D:\archiveoracle\backup\level1\ctrl_%d_%I_%T_%s_%p';
release channel cha1;
}
批处理脚本:rmanbklevel_1.bat
rman target /cmdfile='D:\archiveoracle\rmanbklevel_1.sql'log='D:\archiveoracle\rmanbklevel_1.log' append
说明:
在rman备份前,请检查数据库是否开启归档,如果没有开启归档,请开启如下:
sql> startup mout
sql> alter database archivelog;
sql> alter database open;
设置归档目录
alter system setlog_archive_dest_1='location=D:\archiveoracle\';
(5) 逻辑备份
逻辑备份使用数据泵进行备份首先要创建目录
create directory dmp_dir as 'D:\expdpdump' (目录根据实际情况进行修改)
逻辑导出脚本:expdp.bat
@echo off
rem setbackupfile=f_database_%date:~0,4%-%date:~5,2%-%date:~8,2%.dmp
rem setlogfile=f_database_%date:~0,4%-%date:~5,2%-%date:~8,2%.log
rem delete 30days files
forfiles /p "D:\expdpdump" /d-30 /c "cmd /c echo deleting @file... && del /f @path"
rem backup schemas
setbackupfile=expdp_%date:~0,4%-%date:~5,2%-%date:~8,2%.dmp
setlogfile=expdp_%date:~0,4%-%date:~5,2%-%date:~8,2%.log
expdp.exe \"sys/oracle as sysdba\"directory=dmp_dir dumpfile=%backupfile% logfile=%logfile%schemas=scott parallel=4
注意:里面的目录和要备份的schema根据实际情况修改
(6) 备份部署:
把备份的批处理文件添加的windows的定时任务中去
如下添加步骤(以0级备份为例)
1. 点击开始按钮,依次选择打开“所有程序—附件—系统工具”,找到“任务计划程序”
。。。。。。。。