ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/examples/DBAdmin/dlg/RestoreDlgUnit.pas
Revision: 158
Committed: Thu Mar 1 11:23:33 2018 UTC (6 years, 1 month ago) by tony
Content type: text/x-pascal
File size: 5412 byte(s)
Log Message:
Repository resync

File Contents

# Content
1 (*
2 * RestoreDlgUnit.pas
3 * Copyright (C) 2018 Tony Whyman <tony@mwasoftware.co.uk>
4 *
5 * DBAdmin is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * DBAdmin is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 unit RestoreDlgUnit;
19
20 {$mode objfpc}{$H+}
21
22 interface
23
24 uses
25 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
26 StdCtrls, Buttons, ComCtrls, IBServices;
27
28 type
29
30 { TRestoreDlg }
31
32 TRestoreDlg = class(TForm)
33 Button1: TButton;
34 Button2: TButton;
35 DeActivateIndexes: TCheckBox;
36 PageBuffers: TEdit;
37 Label6: TLabel;
38 NoShadow: TCheckBox;
39 NoValidityCheck: TCheckBox;
40 OneRelationAtATime: TCheckBox;
41 RestoreMetaDataOnly: TCheckBox;
42 UseAllSpace: TCheckBox;
43 Edit1: TEdit;
44 DBName: TEdit;
45 SourceArchive: TEdit;
46 PageSize: TEdit;
47 IBRestoreService1: TIBRestoreService;
48 Label1: TLabel;
49 Label2: TLabel;
50 Label3: TLabel;
51 Label4: TLabel;
52 Label5: TLabel;
53 Report: TMemo;
54 OpenDialog1: TOpenDialog;
55 PageControl1: TPageControl;
56 RadioButton1: TRadioButton;
57 RadioButton2: TRadioButton;
58 SpeedButton1: TSpeedButton;
59 SelectTab: TTabSheet;
60 ReportTab: TTabSheet;
61 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
62 procedure FormShow(Sender: TObject);
63 procedure ReportTabShow(Sender: TObject);
64 procedure SpeedButton1Click(Sender: TObject);
65 private
66 { private declarations }
67 procedure DoRestore(Data: PtrInt);
68 public
69 { public declarations }
70 function ShowModal(DefaultPageSize, DefaultNumBuffers: integer): TModalResult;
71 end;
72
73 var
74 RestoreDlg: TRestoreDlg;
75
76 implementation
77
78 {$R *.lfm}
79
80 { TRestoreDlg }
81
82 procedure TRestoreDlg.SpeedButton1Click(Sender: TObject);
83 begin
84 if OpenDialog1.Execute then
85 SourceArchive.Text := OpenDialog1.Filename;
86 end;
87
88 procedure TRestoreDlg.DoRestore(Data: PtrInt);
89 var bakfile: TFileStream;
90 line: string;
91 begin
92 bakfile := nil;
93 if IBRestoreService1.BackupFileLocation = flClientSide then
94 bakfile := TFileStream.Create(IBRestoreService1.BackupFile[0],fmOpenRead);
95 Report.Lines.Add('Restore Started');
96 try
97 IBRestoreService1.ServiceStart;
98 while not IBRestoreService1.Eof do
99 begin
100 case IBRestoreService1.BackupFileLocation of
101 flServerSide:
102 Report.Lines.Add(Trim(IBRestoreService1.GetNextLine));
103 flClientSide:
104 begin
105 IBRestoreService1.SendNextChunk(bakfile,line);
106 if line <> '' then
107 Report.Lines.Add(line);
108 end;
109 end;
110 Application.ProcessMessages
111 end;
112 finally
113 if bakfile <> nil then
114 bakfile.Free;
115 end;
116 while IBRestoreService1.IsServiceRunning do; {flush}
117 IBRestoreService1.ACtive := false;
118
119 Report.Lines.Add('Restore Completed');
120 MessageDlg('Restore Completed',mtInformation,[mbOK],0);
121 end;
122
123 function TRestoreDlg.ShowModal(DefaultPageSize, DefaultNumBuffers: integer
124 ): TModalResult;
125 begin
126 PageSize.Text := IntToStr(DefaultPageSize);
127 PageBuffers.Text := IntToStr(DefaultNumBuffers);
128 Result := inherited ShowModal;
129 end;
130
131 procedure TRestoreDlg.FormShow(Sender: TObject);
132 begin
133 PageControl1.ActivePage := SelectTab;
134 Edit1.Text := IBRestoreService1.ServerName;
135 if IBRestoreService1.BackupFileLocation = flServerSide then
136 RadioButton1.Checked := true
137 else
138 RadioButton2.Checked := true;
139 DBName.Text := IBRestoreService1.DatabaseName[0];
140 IBRestoreService1.BackupFile.Clear;
141 SourceArchive.SetFocus;
142 end;
143
144 procedure TRestoreDlg.ReportTabShow(Sender: TObject);
145 begin
146 Report.Lines.Clear;
147 end;
148
149 procedure TRestoreDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction);
150 begin
151 if ModalResult <> mrOK then Exit;
152
153 if PageControl1.ActivePage = SelectTab then
154 begin
155 CloseAction := caNone;
156 if SourceArchive.Text = '' then
157 raise Exception.Create('A Backup File Name must be given');
158 with IBRestoreService1 do
159 begin
160 if RadioButton1.Checked then
161 BackupFileLocation := flServerSide
162 else
163 BackupFileLocation := flClientSide;
164 BackupFile.Add(SourceArchive.Text);
165 PageSize := StrToInt(self.PageSize.Text);
166 PageBuffers := StrToInt(self.PageBuffers.Text);
167 Options := [Replace];
168 if DeactivateIndexes.Checked then
169 Options := Options + [IBServices.DeactivateIndexes];
170 if NoShadow.Checked then
171 Options := Options + [IBServices.NoShadow];
172 if NoValidityCheck.Checked then
173 Options := Options + [IBServices.NoValidityCheck];
174 if OneRelationAtATime.Checked then
175 Options := Options + [IBServices.OneRelationAtATime];
176 if RestoreMetaDataOnly.Checked then
177 Options := Options + [IBServices.RestoreMetaDataOnly];
178 if UseAllSpace.Checked then
179 Options := Options + [IBServices.UseAllSpace];
180 end;
181
182 PageControl1.ActivePage := ReportTab;
183 Application.QueueAsyncCall(@DoRestore,0);
184 end;
185
186 end;
187
188 end.
189