如何编程对SQL Server 2000数据库进行备份?(100分)

  • 主题发起人 主题发起人 whxiaoxing
  • 开始时间 开始时间
W

whxiaoxing

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在局域网客户端对服务器中的SQL Server 2000 中的数据库进行编程备份???
万分感谢!!!
 
直接在程序中调用SQL语句即可
if not exists (select name from master.dbo.sysdevices where cntrltype=2 and name='bak')
EXEC sp_addumpdevice 'disk', 'bak', 'c:/bak.bak'
BACKUP DATABASE csjls to bak
 
我是指在Delphi中编程,而不是在SQL中,你写的语句在Delphi中是根本不行的
 
转抄:
PAS文件:
unit u_backup;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, shellapi,filectrl, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons, Db, DBTables, ComCtrls;

type
Tfrm_backup = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
GroupBox2: TGroupBox;
cb_sql: TComboBox;
bu_name: TEdit;
bu_dis: TEdit;
bu_file: TEdit;
OpenDialog1: TOpenDialog;
lb_disk: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
btn_file: TButton;
Query1: TQuery;
Query2: TQuery;
sbar1: TStatusBar;
Timer1: TTimer;
Memo1: TMemo;
rg1: TRadioGroup;
Bevel1: TBevel;
Bevel2: TBevel;
Bevel3: TBevel;
Image1: TImage;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Panel2: TPanel;
rb_full: TRadioButton;
procedure btn_fileClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure rg1Click(Sender: TObject);
procedure cb_sqlChange(Sender: TObject);
procedure OpenDialog1CanClose(Sender: TObject; var CanClose: Boolean);
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure bu_fileKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure backup();
procedure dfull();
procedure datafail();
procedure pccomputer;
private
{ Private declarations }
diskspace:integer;
full,local:boolean;
computer:string;
public
{ Public declarations }
end;

var
frm_backup: Tfrm_backup;
function getfreediskspace(const drive :string):longint;forward;
implementation
uses u_resysmenu;
{$R *.DFM}

procedure Tfrm_backup.btn_fileClick(Sender: TObject);
begin
messagedlg('选择的目录应为网络完全共享目录!',mtwarning,[mbok],0);
local:=false;
opendialog1.InitialDir:=bu_file.text;
if opendialog1.Execute then
begin
if local=false then
begin
bu_file.Clear;
bu_file.Text:=opendialog1.FileName;
end;
end;
end;

procedure Tfrm_backup.FormCreate(Sender: TObject);
var
i,sf_num:integer;
begin

bu_name.clear;
bu_dis.clear;
bu_file.Clear;
lb_disk.Caption:='未知';
query1.DatabaseName:='sfroad';
query1.close;
query1.sql.clear;
query1.sql.add('exec sp_helpdb');
try
query1.open
except
showmessage('Data Initialize error');
exit;
end;
query1.first;
i:=0;
while not query1.Eof do
begin
i:=i+1;
cb_sql.Items.Append(query1.fieldbyname('name').asstring);
if query1.fieldbyname('name').asstring='sfroad' then
sf_num:=i-1;
query1.next;
end;
cb_sql.ItemIndex:=sf_num;
rg1.ItemIndex:=0;
cb_sql.OnChange(self);
end;

procedure Tfrm_backup.rg1Click(Sender: TObject);
begin
case rg1.ItemIndex of
0:
begin
bu_name.Text:=cb_sql.Text+'_full';
memo1.Text:='完全备份是对数据库内所有对象做完整的备份。';
end;
1:
begin
bu_name.text:=cb_sql.text+'_diff';
memo1.text:='差异备份是对自上次数据库完全备份后数据库变动部分的备份。';
end;
2:
begin
bu_name.text:=cb_sql.text+'_translog';
memo1.text:='日志备份是对数据库的事务处理记录的备份。';
end;
end;
end;

procedure Tfrm_backup.cb_sqlChange(Sender: TObject);
begin
dfull();
if full=false then
begin
showmessage('数据库'+cb_sql.text+'先要做完全备份,才可以做差异或事务日志备份');
panel2.Visible:=true;
rb_full.Checked:=true;
memo1.Text:='完全备份是对数据库内所有对象做完整的备份。';
rg1.Visible:=false;
rg1.Enabled:=false;
end
else
begin
panel2.Visible:=false;
rb_full.Checked:=false;
rg1.Visible:=true;
rg1.Enabled:=true;
memo1.Clear;
rg1.ItemIndex:=0;
rg1.OnClick(self);
end;
bu_dis.Clear;
bu_file.Clear;
end;

function getfreediskspace(const drive :string):longint;
var
lprootpathname:pchar;
lpsectorspercluster:dword;
lpbytespersector:dword;
lpnumberoffreeclusters:dword;
lptotalnumberofclusters:dword;
begin
lprootpathname:=pchar(drive+':/');
if windows.GetDiskFreeSpace(lprootpathname,lpsectorspercluster,lpbytespersector,
lpnumberoffreeclusters,lptotalnumberofclusters) then
result:=lpnumberoffreeclusters*lpbytespersector*lpsectorspercluster
else
result:=-1;
end;

procedure Tfrm_backup.OpenDialog1CanClose(Sender: TObject;
var CanClose: Boolean);
var
i,j,k,result:integer;
s,s1,s2,s3,st:string;
userfreebytes,totalbytes,freebytes:int64;
begin
if opendialog1.FileName='' then
exit
else
begin
i:=0;
st:='';
st:=opendialog1.FileName;
while pos('/',st)>0 do
begin
i:=pos('/',st);
st:='%';
end;
s1:=copy(opendialog1.filename,1,i-1);
if copy(opendialog1.filename,1,2)='//' then
begin
i:=0;
j:=0;
k:=0;
st:='';
st:=opendialog1.FileName;
while pos('/',st)>0 do
begin
j:=pos('/',st);
st[j]:='%';
k:=k+1;
if k=4 then
break;
end;
i:=j;
end
else
begin
i:=0;
st:='';
st:=opendialog1.FileName;
while pos('/',st)>0 do
begin
i:=pos('/',st);
st:='%';
break;
end;
end;
s3:=copy(opendialog1.filename,1,i);
result:=GetDriveType(pchar(s3));
case result of
0:
begin
lb_disk.Caption:='未知磁盘';
exit;
end;
1:
begin
lb_disk.caption:='不存在的磁盘';
exit;
end;
2: s2:='移动磁盘';
3:
begin
s2:='本地磁盘';
pccomputer;
opendialog1.filename:='//'+computer+'/'+copy(opendialog1.filename,4,(length(opendialog1.filename)-3));
bu_file.text:='//'+computer+'/'+copy(opendialog1.filename,4,(length(opendialog1.filename)-3));
local:=true;
end;
4: s2:='网络共享磁盘';
5: s2:='光盘驱动器';
end;
if not getdiskfreespaceex(pchar(s1),userfreebytes,totalbytes,@freebytes) then
begin
showmessage('磁盘空间侦测试拜');
exit;
end;
s:=''+s2+s1+'剩余空间'+inttostr((freebytes div 1024) div 1024)+'MB'+#13#10+s1+'磁盘总空间'+inttostr((totalbytes div 1024) div 1024)+'MB';
diskspace:=freebytes;
lb_disk.caption:=s;
end;
end;

procedure Tfrm_backup.FormShow(Sender: TObject);
begin
query1.close;
query1.sql.clear;
query1.sql.add('select user_name from t_user_ini where user_no=:no');
query1.ParamByName('no').asstring:=frm_resysmenu.vgs_userno;
query1.open;
sbar1.Panels[0].Text:='操作员:'+query1.fieldbyname('user_name').asstring;
timer1.Enabled:=true;
end;

procedure Tfrm_backup.Timer1Timer(Sender: TObject);
begin
sbar1.panels[1].text:='当前系统时间:'+datetimetostr(now);
end;

procedure Tfrm_backup.FormClose(Sender: TObject; var Action: TCloseAction);
begin
timer1.Enabled:=false;
end;

procedure Tfrm_backup.BitBtn2Click(Sender: TObject);
begin
close;
end;

procedure Tfrm_backup.BitBtn1Click(Sender: TObject);
var
s,s1:string;
begin
if bu_file.Text='' then
begin
showmessage('请输入保存备份文件的路径及文件名');
exit;
end;
if (copy(bu_file.text,length(bu_file.text)-3,4)<>'.bak') and (copy(bu_file.text,length(bu_file.text)-3,4)<>'.dat') then
bu_file.Text:=bu_file.text+'.bak';
if diskspace=0 then
begin
showmessage('磁盘空间不足');
exit;
end;
if fileexists(bu_file.text) then
begin
case application.MessageBox('文件已存在,是否覆盖?','提示',mb_yesno) of
6:
begin
backup();
cb_sql.OnChange(self);
end;
7:
exit;
end;
end
else
begin
case application.MessageBox(' 备份该数据库时,'+#10#13+'请先将该数据库的“Truncate log on checkpoint”选项取消!','提示',mb_yesno) of
6:
begin
backup();
cb_sql.OnChange(self);
end;
7:
exit;
end;
end;

end;

procedure Tfrm_backup.bu_fileKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
s,s1,s2,s3,st:string;
i,result,j,k:integer;
userfreebytes,totalbytes,freebytes:int64;
begin
if key=$0d then
begin
messagedlg('确定所选目录为共享目录,否则备份文件信息无效',mtwarning,[mbok],0);
i:=0;
st:='';
st:=bu_file.Text;
while pos('/',st)>0 do
begin
i:=pos('/',st);
st:='%';
end;
if not DirectoryExists(copy(bu_file.text,1,i-1)) then //DirectoryExists
if not createdir(copy(bu_file.text,1,i-1)) then
begin
raise Exception.Create('不能创建目录 '+copy(bu_file.text,1,i));
exit;
end;
s1:=copy(bu_file.text,1,i-1);
if copy(bu_file.text,1,2)='//' then
begin
i:=0;
j:=0;
k:=0;
st:='';
st:=bu_file.text;
while pos('/',st)>0 do
begin
j:=pos('/',st);
st[j]:='%';
k:=k+1;
if k=4 then
break;
end;
i:=j;
end
else
begin
i:=0;
st:='';
st:=bu_file.text;
while pos('/',st)>0 do
begin
i:=pos('/',st);
st:='%';
break;
end;
end;
s3:=copy(bu_file.text,1,i);
result:=GetDriveType(pchar(s3));
case result of
0:
begin
lb_disk.Caption:='未知磁盘';
exit;
end;
1:
begin
lb_disk.caption:='不存在的磁盘';
exit;
end;
2: s2:='移动磁盘';
3:
begin
s2:='本地磁盘';
pccomputer;
//opendialog1.filename:='//'+computer+copy(opendialog1.filename,4,(length(opendialog1.filename)-3));
bu_file.text:='//'+computer+'/'+copy(bu_file.text,4,(length(bu_file.text)-3));
opendialog1.filename:=bu_file.text;
end;
4: s2:='网络共享磁盘';
5: s2:='光盘驱动器';
end;
if not getdiskfreespaceex(pchar(s1),userfreebytes,totalbytes,@freebytes) then
begin
showmessage('磁盘空间侦测失败');
exit;
end;
s:=''+s2+s1+'剩余空间'+inttostr((freebytes div 1024) div 1024)+'MB'+#13#10+s1+'磁盘总空间'+inttostr((totalbytes div 1024) div 1024)+'MB';
diskspace:=freebytes;
lb_disk.caption:=s;
end;
end;

procedure tfrm_backup.backup();
begin
if (copy(bu_file.text,length(bu_file.text)-3,4)<>'.bak') and (copy(bu_file.text,length(bu_file.text)-3,4)<>'.dat') then
bu_file.Text:=bu_file.text+'.bak';
//showmessage(copy(bu_file.text,length(bu_file.text)-4,4));
if (panel2.Visible=true) and (rb_full.Checked=true) then
begin
query2.close;
query2.sql.clear;
query2.sql.add('backup database '+cb_sql.Text+' to disk=:directory ');
query2.sql.add('with description=:descrip,name=:name');
query2.ParamByName('directory').asstring:=bu_file.Text;
query2.ParamByName('descrip').asstring:=bu_dis.Text;
query2.ParamByName('name').asstring:=bu_name.Text;
try
query2.execsql;
showmessage('完全备份完成');
except
showmessage('数据备份失败');
exit;
end;
end
else
begin
case rg1.ItemIndex of
0:
begin
query2.close;
query2.sql.clear;
query2.sql.add('backup database '+cb_sql.Text+' to disk=:directory ');
query2.sql.add('with description=:descrip,name=:name');
query2.ParamByName('directory').asstring:=bu_file.Text;
query2.ParamByName('descrip').asstring:=bu_dis.Text;
query2.ParamByName('name').asstring:=bu_name.Text;
try
query2.execsql;
showmessage('完全备份完成');
except
showmessage('数据备份失败');
exit;
end;
end;
1:
begin
query2.close;
query2.sql.clear;
query2.sql.add('backup database '+cb_sql.Text+' to disk=:directory ');
query2.sql.add('with description=:descrip,name=:name,differential');
query2.ParamByName('directory').asstring:=bu_file.Text;
query2.ParamByName('descrip').asstring:=bu_dis.Text;
query2.ParamByName('name').asstring:=bu_name.Text;
try
query2.execsql;
showmessage('差异备份完成');
except
showmessage('数据备份失败');
exit;
end;
end;
2:
begin
query2.close;
query2.sql.clear;
query2.sql.add('backup log '+cb_sql.Text+' to disk=:directory ');
query2.sql.add('with description=:descrip,name=:name');
query2.sql.add(',no_truncate');
query2.ParamByName('directory').asstring:=bu_file.Text;
query2.ParamByName('descrip').asstring:=bu_dis.Text;
query2.ParamByName('name').asstring:=bu_name.Text;
try
query2.execsql;
showmessage('日志备份完成');
except
showmessage('数据备份失败');
exit;
end;
end;
end;
end;
end;

procedure tfrm_backup.dfull();
begin
try
frm_resysmenu.Database1.Connected:=false;
except
showmessage('临时数据库初始化失败,请重新载入');
frm_backup.Close;
end;

frm_resysmenu.Database1.AliasName:='msdb';
frm_resysmenu.Database1.DatabaseName:='msdb';
frm_resysmenu.database1.Params.Values['user name']:=frm_resysmenu.str_user;
frm_resysmenu.database1.ParamS.values['password']:=frm_resysmenu.str_psd;

try
frm_resysmenu.Database1.Connected:=true;
except
showmessage('临时数据库初始化失败,请重新载入');
datafail();
close;
exit;
end;

full:=false;
query1.DatabaseName:='msdb';
query1.close;
query1.sql.clear;
query1.sql.Add('select type from backupset where database_name=:name');
query1.ParamByName('name').asstring:=cb_sql.Text;
query1.open;
while not query1.eof do
begin
if uppercase(query1.fieldbyname('type').asstring)='D' then
begin
full:=true;
end;
if full=true then
break;
query1.next;
end;

datafail();
query1.DatabaseName:='sfroad';
end;

procedure tfrm_backup.datafail();
begin
try
frm_resysmenu.Database1.Connected:=false;
except
showmessage('临时数据库卸载失败,请重新载入');
frm_backup.Close;
end;
frm_resysmenu.Database1.AliasName:=frm_resysmenu.str_alias;
frm_resysmenu.Database1.DatabaseName:='sfroad';//frm_resysmenu.str_database;
frm_resysmenu.database1.Params.Values['user name']:=frm_resysmenu.str_user;
frm_resysmenu.database1.ParamS.values['password']:=frm_resysmenu.str_psd;
try
frm_resysmenu.Database1.Connected:=true;
except
showmessage('临时数据库卸载失败,请重新载入');
frm_backup.Close;
end;
end;

procedure tfrm_backup.pccomputer;
var
pccomputer:pchar;
dwcsize:dword;
begin
dwcsize:=max_computername_length+1;
getmem(pccomputer,dwcsize);
try
if windows.GetComputerName(pccomputer,dwcsize) then
computer:=pccomputer;
finally
end;
end;

end.
DFM文件:
object frm_backup: Tfrm_backup
Left = 278
Top = 173
AutoScroll = False
BorderIcons = [biSystemMenu, biMinimize]
Caption = '数据备份'
ClientHeight = 376
ClientWidth = 420
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
OnClose = FormClose
OnCreate = FormCreate
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 419
Height = 319
BevelOuter = bvLowered
TabOrder = 0
object Label1: TLabel
Left = 107
Top = 32
Width = 66
Height = 12
Caption = '数据库名称:'
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
ParentFont = False
end
object Label2: TLabel
Left = 115
Top = 58
Width = 54
Height = 12
Caption = '备份名称:'
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
ParentFont = False
end
object Label3: TLabel
Left = 115
Top = 84
Width = 54
Height = 12
Caption = '备份描述:'
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
ParentFont = False
end
object Label4: TLabel
Left = 47
Top = 264
Width = 54
Height = 12
Caption = '备份文件:'
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
ParentFont = False
end
object Label5: TLabel
Left = 46
Top = 293
Width = 78
Height = 12
Caption = '磁盘剩余空间:'
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
ParentFont = False
end
object lb_disk: TLabel
Left = 126
Top = 292
Width = 24
Height = 12
Caption = 'xxmb'
Color = clTeal
Font.Charset = GB2312_CHARSET
Font.Color = clAqua
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
ParentColor = False
ParentFont = False
end
object Bevel1: TBevel
Left = 63
Top = 16
Width = 343
Height = 2
end
object Bevel2: TBevel
Left = 63
Top = 109
Width = 343
Height = 2
end
object Bevel3: TBevel
Left = 63
Top = 244
Width = 343
Height = 2
end
object Image1: TImage
Left = 21
Top = 38
Width = 36
Height = 36
AutoSize = True
Picture.Data = {
07544269746D6170660F0000424D660F00000000000036000000280000002400
0000240000000100180000000000300F0000C40E0000C40E0000000000000000
0000BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBF0000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000BFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF7F7F7F7F7F7F7F7F
7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F
7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F
000000BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBF7F7F7FFFFFFFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBF7F7F7F7F7F7F000000BFBFBFBFBFBFBFBFBFBFB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F7F7F7F7F7F7F7F000000000000BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBF7F7F7FBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF7F7F7F
000000000000000000000000FFFFFF0000000000000000000000007F7F7F7F7F
7F7F7F7F7F7F7F0000007F7F7F7F7F7FBFBFBF0000007F7F7F000000BFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBF7F7F7FBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBF7F7F7F000000000000000000FFFFFF000000FFFFFF0000
000000000000007F7F7F7F7F7F7F7F7F000000BFBFBF0000007F7F7FBFBFBF00
00007F7F7F000000BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF7F7F7FBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF7F7F7F0000000000000000
00000000FFFFFF0000000000000000000000007F7F7F7F7F7F7F7F7F7F7F7F00
00007F7F7F7F7F7FBFBFBF0000007F7F7F000000BFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBF7F7F7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FF7F7F7F0000000000000000000000000000000000000000000000007F7F7F7F
7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7FBFBFBF0000007F7F7F000000
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF7F7F7F7F7F7F7F7F7F7F7F7F7F7F
7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F00000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000007F7F7F000000BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF7F7F
7FBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF7F7F7F0000007F
7F007F7F00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF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BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF
BFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBFBF}
end
object Label6: TLabel
Left = 8
Top = 10
Width = 62
Height = 14
Caption = '备 份'
Font.Charset = GB2312_CHARSET
Font.Color = clBlack
Font.Height = -14
Font.Name = '宋体'
Font.Style = [fsBold]
ParentFont = False
end
object Label7: TLabel
Left = 8
Top = 103
Width = 60
Height = 14
Caption = '备份设置'
Font.Charset = GB2312_CHARSET
Font.Color = clBlack
Font.Height = -14
Font.Name = '宋体'
Font.Style = [fsBold]
ParentFont = False
end
object Label8: TLabel
Left = 8
Top = 239
Width = 60
Height = 14
Caption = '存储路径'
Font.Charset = GB2312_CHARSET
Font.Color = clBlack
Font.Height = -14
Font.Name = '宋体'
Font.Style = [fsBold]
ParentFont = False
end
object cb_sql: TComboBox
Left = 206
Top = 29
Width = 198
Height = 19
Style = csOwnerDrawFixed
ItemHeight = 13
TabOrder = 0
OnChange = cb_sqlChange
end
object bu_name: TEdit
Left = 206
Top = 53
Width = 198
Height = 21
TabOrder = 1
Text = 'bu_name'
end
object bu_dis: TEdit
Left = 206
Top = 80
Width = 198
Height = 21
TabOrder = 2
Text = 'bu_dis'
end
object bu_file: TEdit
Left = 127
Top = 261
Width = 209
Height = 21
TabOrder = 3
Text = 'bu_file'
OnKeyDown = bu_fileKeyDown
end
object btn_file: TButton
Left = 343
Top = 262
Width = 19
Height = 19
Caption = '...'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 4
OnClick = btn_fileClick
end
object Memo1: TMemo
Left = 249
Top = 131
Width = 115
Height = 102
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -14
Font.Name = '宋体'
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
ScrollBars = ssVertical
TabOrder = 5
end
object rg1: TRadioGroup
Left = 127
Top = 125
Width = 112
Height = 108
BiDiMode = bdLeftToRight
Caption = ' 备份方式 '
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = [fsBold]
Items.Strings = (
'完全备份'
'差异备份'
'日志备份')
ParentBiDiMode = False
ParentFont = False
TabOrder = 6
OnClick = rg1Click
end
object Panel2: TPanel
Left = 127
Top = 149
Width = 111
Height = 68
BevelOuter = bvNone
TabOrder = 7
object rb_full: TRadioButton
Left = 8
Top = 26
Width = 95
Height = 17
Caption = '完全备份'
Checked = True
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 0
TabStop = True
end
end
end
object GroupBox2: TGroupBox
Left = 0
Top = 319
Width = 420
Height = 37
TabOrder = 1
object BitBtn1: TBitBtn
Left = 224
Top = 9
Width = 75
Height = 25
Caption = '确定'
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -14
Font.Name = '宋体'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 0
OnClick = BitBtn1Click
Glyph.Data = {
36030000424D3603000000000000360000002800000010000000100000000100
1800000000000003000000000000000000000000000000000000BEBEBEBEBEBE
BEBEBEBEBEBEBEBEBEBEBEBEBBBBBBC6C6C6BDBDBDBEBEBEBEBEBEBEBEBEBEBE
BEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBBBBBBC5C5C5AA
AAAAC0C0C0BDBDBDBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBE
BEBEBEBEBEBEBABABACFCFCF838383252525B8B8B8C0C0C0BDBDBDBEBEBEBEBE
BEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBABABACDCDCD8A8A8A00000000
0000929292C9C9C9BCBCBCBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBE
BBBBBBCDCDCD8B8B8B000000252525080808464646CBCBCBBBBBBBBEBEBEBEBE
BEBEBEBEBEBEBEBEBEBEBEBEBEBCBCBCC9C9C98D8D8D000000363636D1D1D145
4545010101A5A5A5C5C5C5BDBDBDBEBEBEBEBEBEBEBEBEBEBEBEBABABAC6C6C6
9D9D9D000000393939C2C2C2C7C7C7A3A3A3030303474747CCCCCCBABABABEBE
BEBEBEBEBEBEBEBEBEBEBCBCBCC1C1C1B0B0B08E8E8EBBBBBBC2C2C2B9B9B9CC
CCCC757575000000A8A8A8C7C7C7BCBCBCBEBEBEBEBEBEBEBEBEBEBEBEBDBDBD
C1C1C1C9C9C9BFBFBFBDBDBDBEBEBEBEBEBEC2C2C2323232333333C3C3C3BEBE
BEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBDBDBDBCBCBCBDBDBDBEBEBEBEBEBEBD
BDBDC1C1C1C6C6C60A0A0A6E6E6ECFCFCFBBBBBBBEBEBEBEBEBEBEBEBEBEBEBE
BEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBBBBBBC9C9C9828282171717BCBC
BCBFBFBFBDBDBDBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBE
BEBEBEBEBEBBBBBBD0D0D07C7C7C414141CFCFCFBBBBBBBEBEBEBEBEBEBEBEBE
BEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBABABACDCDCD8888
88838383CBCBCBBDBDBDBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBE
BEBEBEBEBEBEBEBEBEBEBEBBBBBBCACACA848484848484C4C4C4BEBEBEBEBEBE
BEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBCBC
BCCBCBCB848484A0A0A0BEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBE
BEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBDBDBDC4C4C4BDBDBD}
end
object BitBtn2: TBitBtn
Left = 328
Top = 9
Width = 75
Height = 25
Caption = '退出'
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -14
Font.Name = '宋体'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 1
OnClick = BitBtn2Click
Glyph.Data = {
36030000424D3603000000000000360000002800000010000000100000000100
1800000000000003000000000000000000000000000000000000BEBEBEBEBEBE
BDBDBDBABABED1D1CBB7B7A8A2A2868B8B708D8D718B8B7395958B9F9FA0B8B8
BBC5C5C5BCBCBCBEBEBEBFBFBEBCBCBDBFBFC0C6C6BE91919C4F4F841D1D9F1F
1F9F1E1EA02D2D95616176787878989892B2B2B5C1C1C1BDBDBDBBBBBDC2C2C0
C0C0B96464900000C50000E60000FF0000FF0000FF0000F80000DC2525A56B6B
6F82827DABABACC1C1C1BEBEC1BFBFB83838B40000E40000FF0000FF0202FB01
01FB0101FB0303FD0000FF0000FA0202CD58587D8D8D86BCBCBEDADAC77373A4
0000E60000FF0707F90909FC0000FD0101FD0202FD0000FD1717FB0000FB0000
FF1212AE7B7B7199999B8181960707D20303FF1313FAC7C7FDBABAFD0505FD03
03FD0000FD4747FDE6E6FD5656FC0000FA0000F92B2B8E9494874141990000E9
0202FD1212FBB8B8FDFFFFFDB0B0FD0101FD4747FDF9F9FDFDFDFD5858FD0000
FB0000FF1414B07979760000C00000FE0000FD0000FD0202FDB1B1FDFFFFFDC9
C9FDF1F1FDF8F8FD4949FD0000FD0202FB0101FD0000E05C5C7A0202BC0000FC
0000FD0101FD0303FD0000FDC6C6FDFFFFFDFEFEFD4F4FFD0000FD0606FD0000
FB0000FE0000DC5D5D780000BF0000FE0000FD0202FD0000FD4949FDEBEBFDFF
FFFDFFFFFDA5A5FD0707FD0000FD0000FB0101FE0000E060607E1919B20101F5
0202FD0000FC4A4AFDF9F9FDFDFDFD5656FDA8A8FDFFFFFDACACFD0E0EFD0202
FB0101FD0707C778788A5E5E8A0000E10202FF1F1FFBF6F6FDFEFEFD4A4AFD00
00FD0606FDACACFDFFFFFD8282FD0000FA0000FF1A1A9CB3B3A3B6B6B33636B7
0000F80202FB5858FC5555FD0000FD0606FD0000FD0404FD7C7CFD0E0EFA0303
FF0101D26F6F99C8C8C3D3D3C9A4A4A80202CC0000FF0000FC0000FC0202FB00
00FB0000FB0000FB0000FB0000FF0000F74141A0CCCCB7BCBCBFB7B7BCC7C7C1
8888AE2121B50000F50000FF0000FF0000FF0000FF0000FF0000FF0404D74A4A
A6BDBDBDBFBFC0BDBDBDBEBEBEBCBCBEC7C7C0BCBCB55151AD2C2CBA0000D501
01D50000D60F0FCD3D3DB08585AFCFCFBCBEBEBFBDBDBDBEBEBE}
end
end
object sbar1: TStatusBar
Left = 0
Top = 357
Width = 420
Height = 19
Panels = <
item
Alignment = taCenter
Width = 120
end
item
Alignment = taCenter
Width = 50
end>
SimplePanel = False
end
object OpenDialog1: TOpenDialog
DefaultExt = 'bak'
Filter = 'Backup File(*.bak,*.dat)|*.bak;*.dat|All Files(*.*)|*.*'
InitialDir = 'c:/backup'
Title = '备份文件目录'
OnCanClose = OpenDialog1CanClose
Left = 72
Top = 327
end
object Query1: TQuery
DatabaseName = 'sfroad'
Left = 8
Top = 326
end
object Query2: TQuery
DatabaseName = 'sfroad'
Left = 40
Top = 326
end
object Timer1: TTimer
OnTimer = Timer1Timer
Left = 105
Top = 327
end
end
 
建立一个存储过程:
CREATE PROCEDURE [dbo].[BackupDatabase]
@dbname VARCHAR(256),
@filename VARCHAR(256),
@devname VARCHAR(256)
AS
IF EXISTS(SELECT name FROM master.dbo.sysdevices WHERE cntrltype=2 AND name=@devname)
RETURN -1
ELSE
BEGIN
EXEC sp_addumpdevice 'disk', @devname, @filename
BACKUP DATABASE @dbname to @devname
RETURN 0
END

然后在DELPHI中调用这个存储过程。这样应该可以,不过,我没试过,你试一下吧。[8D]
>我刚试了一下,可行的。[:)]
 
刚刚有两处笔误,这次改正如下:
建立一个存储过程:
CREATE PROCEDURE [dbo].[BackupDatabase]
@dbname VARCHAR(256),
@filename VARCHAR(256),
@devname VARCHAR(256)
AS
IF EXISTS(SELECT name FROM master.dbo.sysdevices WHERE cntrltype=2 AND name=@devname)
SELECT 'FAIL'
ELSE
BEGIN
EXEC sp_addumpdevice 'disk', @devname, @filename
BACKUP DATABASE @dbname to @devname
SELECT 'OK'
END

//DELPHI中调用
function BackupDatabase(DatabaseName,DevName,FileName:string):boolean;
var
Q:TADOQuery;
begin
Q :=TADOQuery.Create(Self);
try
Q.SQL.Add('EXEC BackupDatabase '+Quotedstr(DatabaseName)+','+
Quotedstr(FileName)+','+Quotedstr(DevName));
Q.Open
result :=Q.Fields[0].AsString='OK';
Q.Close;
finally
Q.Free
end;
end;
 
我只做过恢复数据库的,要Import 微软的MS SQLDMO类型库
procedure TForm1.Button4Click(Sender: TObject);
var
server:OleVariant;
db:OleVariant;
dbs:OleVariant;
res:OleVariant;
dbf:OleVariant;
fg:OleVariant;
begin
try
server:=CreateOleObject('SQLDMO.SQLServer');
db:=CreateOleObject('SQLDMO.Database');
res:=CreateOleObject('SQLDMO.Restore');
dbf:=CreateOleObject('SQLDMO.DBFILE');
fg:=CreateOleObject('SQLDMO.FileGroup');
server.Connect(edit3.Text,'sa',edit2.Text);
dbf.Name:='ziyuanku_db_Data';
dbf.PhysicalName := edit4.text+'/ziyuanku_db_data.mdf';
dbf.size:=2;
dbf.FileGrowthType:= SQLDMOGrowth_Percent;
db.FileGroups.Item(1).DBFiles.Add(dbf);
dbs:=server.databases;
db.name:='ziyuanku_db';
dbs.add(db);
res.database:='ziyuanku_db';
res.Action:= SQLDMORestore_Database;
res.ReplaceDatabase := True;
res.Files:= edit5.Text;
res.SQLRestore(server);
except
Application.MessageBox('数据库恢复错误','错误',MB_OK);
end;
end;
 
各位高手,非常感谢大家,我下去试一试,再次感谢,
祝你们好运,泡美眉时一泡一个准!!!
 
后退
顶部