日期:2014-05-16 浏览次数:20430 次
require 'net/http' require 'Win32API' class Getdatabasebackup def deleteoldfile() @savefilecount=8 #保留最后7份备份 @orcle_path="D:/oracle/product/10.2.0/db_1/BIN/exp.exe" @user="demo/demo" @backup_path="e:/swiage/test/" #@backup_path="\\\\192.168.10.65/share/" #备份到网络路径下 log=File.open("c:/log.txt","a") temp=0 minfilename="" mincreate=0 filecount=Dir.entries(@backup_path).length if(filecount>@savefilecount) Dir.foreach(@backup_path) do |f| if(f.size>2) create=File.ctime(@backup_path+f).to_i if(mincreate==0) mincreate=create minfilename=f end temp=create if(mincreate>temp) mincreate=temp minfilename=f end end end begin File.delete(@backup_path+minfilename) log<<Time.now.to_s+" delete file "+minfilename+"\n" rescue log<<Time.now.to_s+" delete file "+minfilename+" error!\n" end end result="error" while(result=="error") result=databasebackup(@orcle_path,@user,@backup_path) end log<<Time.now.to_s+" backup database file "+result+"\n" end def databasebackup(toolspath,database,filepath) system = Win32API.new("msvcrt","system",['p'],'i') @filepath=filepath @toolspath=toolspath @database=database filename="backup_"+Time.now.strftime("%Y_%m_%d_%H%M")+".dmp" stut =system.call(@toolspath+" "+@database+" GRANTS=Y file="+@filepath+ filename) system=nil if(stut==0) return filename else return "error" end end end Getdatabasebackup.new.deleteoldfile()
?
Oracle_backup.rb
数据库备份程序,用于自动备份完整的数据库
?
?
脚本执行需要Ruby编译内核的支持即需要安装Ruby开发包。