oracle备份之备份测试脚本的方法(冷备、热备、rman)
1、数据库环境
数据库DBID及打开模式
SQL>selectdbid,open_modefromv$database; DBIDOPEN_MODE -------------------- 4106451204READWRITE
数据文件:
SQL>selectfile#,status,enabled,namefromv$datafile; FILE#STATUSENABLEDNAME ----------------------------------------------------------------------------------------------------------- 1SYSTEMREADWRITE/u01/app/oracle/oradata/ocmdb/dfile/system01.dbf 2ONLINEREADWRITE/u01/app/oracle/oradata/ocmdb/undotbs01.dbf 3ONLINEREADWRITE/u01/app/oracle/oradata/ocmdb/dfile/sysaux01.dbf 4ONLINEREADWRITE/u01/app/oracle/oradata/ocmdb/dfile/tbs_1.dbf 5ONLINEREADWRITE/u01/app/oracle/oradata/ocmdb/dfile/tbs3.dbf 6ONLINEREADWRITE/u01/app/oracle/oradata/ocmdb/dfile/tbs_big01.dbf 7ONLINEREADWRITE/u01/app/oracle/oradata/ocmdb/dfile/rman.dbf
控制文件:
SQL>selectstatus,namefromv$controlfile; STATUSNAME --------------------------------------------------------------------------------------- /u01/app/oracle/ocmdb/cfile/ora_control1 /u01/app/oracle/ocmdb/cfile/ora_control2 /u01/app/oracle/ocmdb/cfile/control3
联机日志:
SQL>selectgroup#,status,type,memberfromv$logfile; GROUP#STATUSTYPEMEMBER -------------------------------------------------------------------------------------------------------- 1ONLINE/u01/app/oracle/oradata/ocmdb/lfile/redo01.log 1ONLINE/u01/app/oracle/oradata/ocmdb/lfile/redo11.log 3ONLINE/u01/app/oracle/oradata/ocmdb/lfile/redo03.log 2ONLINE/u01/app/oracle/oradata/ocmdb/lfile/redo02.log 5ONLINE/u01/app/oracle/oradata/ocmdb/lfile/redo05.log 5ONLINE/u01/app/oracle/oradata/ocmdb/lfile/redo55.log 4ONLINE/u01/app/oracle/oradata/ocmdb/lfile/redo04.log 4ONLINE/u01/app/oracle/oradata/ocmdb/lfile/redo44.log
2、数据库备份脚本
冷备份脚本
#remscript:coldbak.sh #remcreater:chon #remdate:2011 #remdesc:offlinefullbackupdatabase #--connectdatabase sqlplus/assysdba<说明:
1、以上脚本在数据库关闭状态下备份数据库所有的数据文件,联机日志,控制文件,归档日志(在一个目录下),如果成功备份,所有文件是一致的。
2、没有备份参数文件,参数文件可以另外备份,没有必要每次都备份,只需要在改变设置后备份一次。
3、如果以上命令没有成功依次执行,那么备份将是无效的,如连接数据库不成功,那么肯定关闭数据库也不成功,那么备份则无效
4、冷备份建议下人工干预下执行。--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
OS热备份
查看表空间和数据文件对应关系SQL>selectfile_id,tablespace_name,file_namefromdba_data_files; FILE_IDTABLESPACE_NAMEFILE_NAME ------------------------------------------------------------------------------------------------------------------------ 7RMAN_TS/u01/app/oracle/oradata/ocmdb/dfile/rman.dbf 6BIG_TBS/u01/app/oracle/oradata/ocmdb/dfile/tbs_big01.dbf 5TBS3/u01/app/oracle/oradata/ocmdb/dfile/tbs3.dbf 4TBS_1/u01/app/oracle/oradata/ocmdb/dfile/tbs_1.dbf 3SYSAUX/u01/app/oracle/oradata/ocmdb/dfile/sysaux01.dbf 2UNDOTBS/u01/app/oracle/oradata/ocmdb/undotbs01.dbf 1SYSTEM/u01/app/oracle/oradata/ocmdb/dfile/system01.dbf数据库OS热全备份脚本
#remscript:hotbak.sh #remcreater:chon #remdate:2011 #remdesc:backupalldatabasedatafileinarchive #--connectdatabase sqlplus/assysdba<说明:
1、热备份必须在数据库归档方式下才可以运行
2、以上脚本可以在数据库运行状态下备份数据库所有的数据文件(除了临时数据文件),没有必要备份联机日志。
3、归档日志至少需要一次完整备份之后的所有日志。
4、如果以上命令没有成功依次执行,那么备份也是无效的,如连接数据库不成功,那么备份则无效---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
RMAN备份脚本
--本地创建文件夹
mkdir/home/oracle/backup mkdir/home/oracle/backup/script mkdir/home/oracle/backup/log mkdir/home/oracle/backup/export--备份目的地
mkdir/home/oracle/rman_backup创建备份表空间
createtablespacerman_tbsdatafile'/oradata/luke/rman_tbs01.dbf'size1024M;创建备份用户
createuserrmanidentifiedbyrmandefaulttablespacerman_tbstemporarytablespacetemp;grantconnect,resource,recovery_catalog_ownertorman; rmancatalogrman/rman createcatalogtablespacerman_tbs; connecttargetsys/lukewhx@luke registerdatabase; reportschema; configureretentionpolicytoredundancy2; configureretentionpolicytorecoverywindowof7days; --倒出RMAN用户数据脚本exp_rman.par(即备份catalog库) userid=rman/rman file=/home/oracle/backup/export/rman.dmp log=/home/oracle/backup/log/rman.log --倒出RMAN数据SHELL脚本exp_rman.sh #!/bin/bash cd$HOME ..bash_profile cd$HOME/backup/script expparfile=exp_rman.par --零级备份RMAN脚本level0_backup.rcv connectcatalogrman/rman connecttargetsys/unumall@unu2 run{ CONFIGURERETENTIONPOLICYTORECOVERYWINDOWOF14DAYS; CONFIGURECONTROLFILEAUTOBACKUPON; allocatechanneld1typedisk; allocatechanneld2typedisk; backupincrementallevel0databaseformat'/home/oracle/rman_backup/level0_%d_%s_%p_%u.bak' tag='level0'includecurrentcontrolfile; sql'altersystemarchivelogcurrent'; backuparchivelogallformat'/home/oracle/rman_backup/log_%d_%s_%p_%u.bak'deleteallinput; releasechanneld2; releasechanneld1; } crosscheckbackup; deletenopromptexpiredbackup; deletenopromptobsolete; resynccatalog; --零级备份SHELL脚本的level0_backup.sh #!/bin/bash cd$HOME ..bash_profile cd$HOME/backup/script rmancmdfile=level0_backup.rcvmsglog=$HOME/backup/log/level0_backup.log ./home/oracle/backup/script/exp_rman.sh --一级差异增量备份RMAN脚本level1_backup.rcv connectcatalogrman/rman connecttargetsys/luke@luke run{ allocatechanneld1typedisk; backupincrementallevel1format'/home/oracle/rman_backup/level1_%d_%s_%p_%u.bak'tag='level1'database; sql'altersystemarchivelogcurrent'; backuparchivelogallformat'/home/oracle/rman_backup/log_%d_%s_%p_%u.bak'deleteallinput; releasechanneld1; } crosscheckbackup; deletenopromptexpiredbackup; deletenopromptobsolete; resynccatalog; --一级差异增量备份SHELL脚本level1_backup.sh #!/bin/bash cd$HOME ..bash_profile cd/home/oracle/backup/script rmancmdfile=level1_backup.rcvmsglog=$HOME/backup/log/level1.log ./home/oracle/backup/script/exp_rman.sh --二级差异增量备份RMAN脚本level2_backup.rcv connectcatalogrman/rman connecttargetsys/luke@luke run{ allocatechanneld1typedisk; backupincrementallevel2format'/home/oracle/rman_backup/level2_%d_%s_%p_%u.bak'tag='level2'database; sql'altersystemarchivelogcurrent'; backuparchivelogallformat'/home/oracle/rman_backup/log_%d_%s_%p_%u.bak'deleteallinput; releasechanneld1; } crosscheckbackup; deletenopromptexpiredbackup; deletenopromptobsolete; resynccatalog;--二级差异增量备份SHELL脚本level2_backup.sh
#!/bin/bash cd$HOME ..bash_profile cd/home/oracle/backup/script rmancmdfile=level2_backup.rcvmsglog=$HOME/backup/log/level2.log ./home/oracle/backup/script/exp_rman.sh提高RMAN增量备份性能
alterdatabaseenableblockchangetrackingusingfile '/u01/app/oracle/admin/devdb/bdump/luke.log'; descv$block_change_tracking;linux下定时执行备份脚本
crontab-e-uoracle SHELL=/bin/bash--以下脚本在bash下执行 MAILTO=oracle--执行日志以邮件形式邮给oracle用户,可以/var/spool/mail/oracle下查收 101**0/home/oracle/backup/script/level0_backup.sh 101**1/home/oracle/backup/script/level2_backup.sh 101**2/home/oracle/backup/script/level2_backup.sh 101**3/home/oracle/backup/script/level1_backup.sh 101**4/home/oracle/backup/script/level2_backup.sh 101**5/home/oracle/backup/script/level2_backup.sh 101**6/home/oracle/backup/script/level2_backup.sh一周差异备份策略:
备份目标库和catalog库
周日0级全备,周一周二为2级,周三为1级,周四周五周六为2级。
每天凌晨1点10分开始备份零级备份
backupincrementallevel0database;
一级差异增量差异增量是默认增量备份方式
backupincrementallevel1database;一级累计增量
backupincrementallevel1cumulativedatabase;总结
到此这篇关于oracle备份之备份测试脚本的方法(冷备、热备、rman)的文章就介绍到这了,更多相关oracle备份测试脚本内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。