数字图书馆数据自动备份的研究与实现_第1页
数字图书馆数据自动备份的研究与实现_第2页
数字图书馆数据自动备份的研究与实现_第3页
数字图书馆数据自动备份的研究与实现_第4页
数字图书馆数据自动备份的研究与实现_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、数字图书馆数据自动备份的研究与实现高孝梅 ( 衡阳师范学院图书馆 湖南衡阳 421008)【摘要】WindowsNTServer提供多种功能强大的服务(Service),例如FTP,WWW或远程登录服务,另外常用的数据库服务器也是以Service的形式存在于NTServer上的,如Sybase SQLServer For NT。Service一般在NT启动时自动启动,在NT关机时停止。但是有时用户可能想手工启动、暂停、停止某项Service,这就需要在控制面板中进行配置,对于不太熟悉NT的用户来说比较困难。上面两种情况都可以通过对Service的编程来解决。本文在此基础上研究线程的工作机制,结

2、合自己多年的图书管理经验,详细介绍了基于sql server2000的自动数据库备份的服务程序开发。【关键字】服务(Service)、线程、自动数据库备份、sql server2000Digital library data automatic backup research and realization abstract WindowsNTServer provides the many kinds of functions formidable service (Service), for example FTP, WWW or long-distance registers the s

3、ervice, moreover the commonly used database server also is exists by the Service form on NTServer, like Sybase SQLServer For NT. Service generally when NT start the automatic start, closes the machine-hour in NT to stop. But sometimes the user possibly wants manually to start, the suspension, to sto

4、p some item of Service, this needs to carry on the disposition in the control panel, said regarding the not too familiar NT user quite difficultly. Above two kind of situations all may through solve to the Service programming. This article studies the line regulation in this foundation the work mech

5、anism, unifies the oneself many year books managerial experience, in detail introduced based on the sql server2000 automatic database backup service routine development. Keywords serves (Service), the line regulation, the automatic database backup, sql server2000一、 引言:图书管理的数据经常需要备份,往往都是手动备份,有的时候经常忘记

6、备份,一旦系统崩溃,数据就难以恢复到最近时间的数据,如果能开发一自动备份程序,问题就解决了.二、 研究与实现:1、WindowsNTServer提供多种功能强大的服务(Service),例如FTP,WWW或远程登录服务,另外常用的数据库服务器也是以Service的形式存在于NTServer上的,如Sybase SQLServer For NT。在WindowsNT下,各种Service都存在service control manager database中,因此我们可以通过对service control manager database进行操作来实现对Service的编程。2、服务线程的实现

7、线程是进程内部的一个执行单元(如可以是一个函数或一个活跃的类对象等)。体积小,占用资源少,执行速度快,如果被嵌入到系统服务中,用户很难终止其运行。我们可以在服务线程中定时对数据库进行备份。在这里我们介绍利用delphi编程实现。首先我们分析一下delphi的TThread 类:Delphi 把有关线程的API 封装在TThread 这个Object Pascal 的对象中。虽然TThread 已经封装了几乎所有与线程有关的API。Tthread 类的属性属性类型作用Suspended布尔类型确定线程是否处于暂停状态Terminated布尔类型是否终止运行Priority整型设置线程的优先级Fr

8、eeOnTerminate布尔类型是否自动删除线程对象ReturnValue整数类型通过ReturnValue 属性参数向其他线程传递一个值ThreadID整数类型线程标识号TThread 类的方法方法类型作用Execute虚函数线程需要完成的任务代码Resume使线程恢复运行Suspend使线程对象暂停运行Terminate通知线程终止运行DoTerminate使线程对象产生OnTerminate 事件Synchronize线程同步我们可以编写一ini文件存储备份时间,通过delphi创建一服务程序对时间的读取,启动备份过程。3、具体实现核心代码:(一)线程代码unit pserthread

9、p;interfaceuses Classes,comm,SysUtils,ADODB,Dialogs,inifiles;type pserthread = class(TThread) private fadoco: TADOConnection; Private declarations protected procedure Execute; override; public procedure backup(); constructor Create(Suspended:Boolean;adoco1:TADOConnection);/inf:Tinifile);/dird:string

10、;dayp:string;timep:string); property adoco1: TADOConnection read Fadoco ; end;implementation pserthread constructor pserthread.Create(Suspended:Boolean;adoco1:TADOConnection);/inf:Tinifile);/dird:string;dayp:string;timep:string);begin inherited Create(suspended); Fadoco:=adoco1;end;procedure pserthr

11、ead.backup ;var ini:Tinifile; str:string;begin/ showmessage(数据库备份完成);ini:=TIniFile.Create(ExtractFilePath(Paramstr(0) + Config.Ini); str:=ini.readstring(system,bdir,c:) +yjyxxt.bak;/读取备份文件存放的目录 if (formatdatetime(dd,now) ini.readstring(system,day,00) and ( time strtotime(ini.readstring(system,btime,

12、00:00:00) then begin Fadoco.Execute(Format(backup database yjyxxt to disk=%s, str);/备份数据库 ini.writestring(system,day,formatdatetime(dd,now); ini.Free; showmessage(数据库备份完成); end; sleep(50000);end;procedure pserthread.Execute;begin While not Terminated do begin Synchronize(backup); end;end;end.(二)服务程序

13、代码unit servicepq;interfaceuses Windows, Messages, comm,servername,SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs, DB, ADODB, ExtCtrls,pserthreadp;type TXQServicep = class(TService) ADOCo: TADOConnection; procedure ServiceCreate(Sender: TObject); procedure ServiceStart(Sender: TService; var S

14、tarted: Boolean); procedure ServiceStop(Sender: TService; var Stopped: Boolean); procedure ServicePause(Sender: TService; var Paused: Boolean); procedure ServiceContinue(Sender: TService; var Continued: Boolean); private databaselstr:string; ppth:pserthread; Private declarations public function GetS

15、erviceController: TServiceController; override; Public declarations end;var XQServicep: TXQServicep;implementation$R *.DFMprocedure ServiceController(CtrlCode: DWord); stdcall;begin XQServicep.Controller(CtrlCode);/打开服务控制面板end;function TXQServicep.GetServiceController: TServiceController;begin Resul

16、t := ServiceController;/读取服务控制信息end;procedure TXQServicep.ServiceCreate(Sender: TObject);/创建服务var keynamestr:string; dl:integer; user,password:string;begin keynamestr:=GetSysOptions(system,servername,); if keynamestr = then begin with TFrmserverconfig.Create(application) do begin try ShowModal; if M

17、odalResult mrOK then begin keynamestr := ; halt; exit; end; finally Free; end; end; end; dl:=GetSysOptions(system,dl,-1); /读取登陆方式 user:=GetSysOptions(system,user,); /读取登陆数据库用户 password:=GetSysOptions(system,password,); /读取数据库登陆密码 if dl=0 thendatabaselstr:=Provider=SQLOLEDB.1;Integrated Security=SSPI

18、;Persist Security Info=False;Initial Catalog=master;Data Source=+keynamestr/生成数据库连接字符串并获得数据库管理员权限 else databaselstr:=Provider=SQLOLEDB;Password=+password+;Persist Security Info=True;User ID=+user+;Initial Catalog=master;Data Source=+keynamestr; ADOCo.ConnectionString :=databaselstr ; adoco.Connected

19、 :=true;end;procedure TXQServicep.ServiceStart(Sender: TService; var Started: Boolean);/启动服务begin ppth:=pserthread.Create(false,adoco); started:=true;end;procedure TXQServicep.ServiceStop(Sender: TService; var Stopped: Boolean);/终止服务begin ppth.Terminate ; Stopped := True;end;procedure TXQServicep.ServicePa

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论