Código
unit BackuExemplo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, IBServices;
type
TForm1 = class(TForm)
ibRestore: TIBRestoreService;
ibBackup: TIBBackupService;
edtBanco: TEdit;
Label1: TLabel;
Label2: TLabel;
edtPass: TEdit;
Label3: TLabel;
edtUser: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Memo: TMemo;
opArquivo: TOpenDialog;
Label4: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
with ibBackup do
begin
Active := false;
ServerName := 'LocalHost';
Protocol := Local;
LoginPrompt := False;
Params.Clear;
Params.Add('user_name=' + edtUser.Text );
Params.Add('password='+ edtPass.Text );
try
Active := True;
except
on E: Exception do
begin
MessageDlg('Erro ao executar backup.' + #13 +
'Erro: ' + E.Message, mtError, [mbok], 0);
Screen.Cursor := crDefault;
end;
end;
Try
// Opção de verbose
Verbose := True;
// Opção de extração de dados
// pois pode-e extrair somente o metadados.
Options := [NonTransportable];
DatabaseName := edtBanco.Text ;
BackupFile.Clear;
BackupFile.Add( ExtractFilePath(ParamStr(0)) +
FormatDateTime('dd MM', now) + '.fbk');
ServiceStart;
memo.Clear;
while not eof do
begin
//Delete(GetNextLine, 1, 5);
memo.Lines.Add( GetNextLine );
Application.ProcessMessages;
end;
memo.clear;
memo.Lines.Add('Ultimo arquivo criado: ' +
ExtractFilePath(ParamStr(0)) +
FormatDateTime('dd MM', now) + '.fbk') ;
except
on E: Exception do
begin
MessageDlg('Erro ao tentar fazer backup' + #13 +
'Erro: ' + e.message, mtError, [mbok],0) ;
end;
end;
end; // with
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
opArquivo.InitialDir := ExtractFilePath(ParamStr(0));
opArquivo.FileName := '';
if opArquivo.Execute then begin
try
memo.Lines.Add('Restaurando Base ');
memo.Lines.Add('Horário Inicial: ' + FormatDateTime('HH:nn:ss', Now ));
with ibRestore do begin
ibRestore.Active := false;
LoginPrompt := False;
Params.Clear;
Params.Add('user_name=' + edtUser.Text );
Params.Add('password='+ edtPass.Text );
try
Active := True;
except
on E: Exception do begin
MessageDlg('Erro ao executar backup.' + #13 +
'Erro: ' + E.Message, mtError, [mbok], 0);
Screen.Cursor := crDefault;
end;
end;
Verbose := True;
Options := [Replace, UseAllSpace];
databasename.add(edtBanco.Text);
BackupFile.Clear;
backupfile.add( opArquivo.FileName );
active := true;
servicestart;
while not Eof do begin
memo.Lines.Add( GetNextLine );
Application.ProcessMessages;
end;
end;
memo.Lines.Add('Término da restauração da Base ');
memo.Lines.Add('Horário Final: ' + FormatDateTime('HH:nn:ss', Now ));
except
memo.Lines.Add('');
memo.Lines.Add('Erro na restauração da Base');
end;
end;
end;
end.
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009