IBBackupService com ProgressBar/Gauge

23/10/2003

0

Olá pessoal, implementei um sistema de Backup/Restore
usando o IBBackupService e o IBRestoreService
Funciona perfeitamente, agora pretendo utilizar
um ProgressBar ou Gauge para mostrar o andamento
do backup/restore.
Como proceder???
Qualquer ajuda será bem vinda.
T+


Eniorm

Eniorm

Responder

Posts

27/10/2003

Eniorm

Ae galera, alguem sabe ou naum,
Ligar o IBBackupService e IBRestoreService com
uma progressbar ou gauge???
T+


Responder

03/03/2005

Christian_adriano

Sobe....


Responder

03/03/2005

Christian_adriano

Segue o Código a baixo:

// função auxiliar que achei necessário

function VerificarSubTexto(Texto : TRichEdit; ValorProcurar : String) : Boolean;
var
i : Integer;
begin

result := false;
for I := 0 to Texto.Lines.Count do
begin
if (Texto.Lines.Strings[i] = ValorProcurar) then
begin
result := True;
Exit;
end;
end;

end;


// Controla a Barra de Progresso (TProgressBar)

procedure BackupTextNotify(mmBackup : TRichEdit; Text: String; pbBackup : TProgressBar);
begin

if (Pos(´writing domains´, Text) > 0) or (Pos(´started transaction´, Text) > 0) then
begin
mmBackup.Lines.Add(´Domínios...´); // TRichEdit pra adicionar a ação atual
pbBackup.StepIt; // Atualiza barra de progresso
end;

if (Pos(´writing shadow files´, Text) > 0) or (Pos(´restoring domain´, Text) > 0) then
if not (VerificarSubTexto(mmBackup, ´Arquivos Ocultos...´)) then
begin
mmBackup.Lines.Add(´Arquivos Ocultos...´);
pbBackup.StepIt;
end;

if (Pos(´writing tables´, Text) > 0) or (Pos(´restoring table´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Tabelas...´)) then
begin
mmBackup.Lines.Add(´Tabelas...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing functions´, Text) > 0) or (Pos(´restoring function´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Funções...´)) then
begin
mmBackup.Lines.Add(´Funções...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing types´, Text) > 0) or (Pos(´restoring type´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Tipos...´)) then
begin
mmBackup.Lines.Add(´Tipos...´);
pbBackup.StepIt;
end;
end;


if (Pos(´writing filters´, Text) > 0) or (Pos(´restoring filter´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Filtros...´)) then
begin
mmBackup.Lines.Add(´Filtros...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing id generators´, Text) > 0) or (Pos(´restoring generator´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Geradores...´)) then
begin
mmBackup.Lines.Add(´Geradores...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing stored procedures´, Text) > 0) or (Pos(´restoring stored procedure´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Procedimentos...´)) then
begin
mmBackup.Lines.Add(´Procedimentos...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing exceptions´, Text) > 0) or (Pos(´restoring exception´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Exceções...´)) then
begin
mmBackup.Lines.Add(´Exceções...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing Character Sets´, Text) > 0) or (Pos(´restoring Character´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Tipo de Caracteres...´)) then
begin
mmBackup.Lines.Add(´Tipo de Caracteres...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing Collations´, Text) > 0) or (Pos(´restoring data for table´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Registros...´)) then
begin
mmBackup.Lines.Add(´Collations...´);
mmBackup.Lines.Add(´Registros...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing triggers´, Text) > 0) or (Pos(´restoring trigger´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Gatilhos...´)) then
begin
mmBackup.Lines.Add(´Gatilhos...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing trigger messages´, text) > 0) or (Pos(´restoring trigger message´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Mensagens...´)) then
begin
mmBackup.Lines.Add(´Mensagens...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing table constraints´, Text) > 0) or (Pos(´restoring table constraints´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Chaves...´)) then
begin
mmBackup.Lines.Add(´Chaves...´);
pbBackup.StepIt;
end;
end;

if (Pos(´restoring privilege´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Privilégios...´)) then
begin
mmBackup.Lines.Add(´Privilégios...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing referential constraints´, Text) > 0) or (Pos(´restoring referential´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Referências...´)) then
begin
mmBackup.Lines.Add(´Referências...´);
pbBackup.StepIt;
end;
end;

if (Pos(´writing check constraints´, text) > 0) or (Pos(´restoring check constraint´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Verificações...´)) then
begin
mmBackup.Lines.Add(´Verificações...´);
pbBackup.StepIt;
end;
end;

if (Pos(´creating indexes´, text) > 0) then
begin
mmBackup.Lines.Add(´Índices...´);
pbBackup.StepIt;
end;

if (Pos(´writing SQL roles´, Text) > 0) or (Pos(´restoring SQL role´, Text) > 0) then
begin
if not (VerificarSubTexto(mmBackup, ´Páginas...´)) then
begin
mmBackup.Lines.Add(´Páginas...´);
pbBackup.StepIt;
end;
end;

Application.ProcessMessages;

end;



// Restauração

procedure RestaurarDatabase(IBRestoreService : TIBRestoreService; StatusTexto : TRichEdit; aServerName, UserName, Password, aDatabaseName, aDirBackup : String; TipoProtocolo : TProtocol; Progress : TProgressBar);
var
extensao : String[3];
begin

if not FileExists(aDirBackup) then begin
Application.MessageBox(´Não foi encontrado nenhum arquivo de Backup.´ + #13 +´Efetue um Backup e tente novamente.´, ´Restauração´, mb_OK + MB_ICONERROR);
abort;
end;

Screen.Cursor := crHourGlass;
extensao := Copy(aDatabaseName, Length(aDatabaseName)-2, Length(aDatabaseName));

// Inicializações do TProgressBar
Progress.Min := 0;
Progress.Position := 0;
Progress.Step := 1;
Progress.Max := 10;

with IBRestoreService.Create(nil) do begin
try
Params.Clear;
Params.Add(´user_name=´ + Trim(UserName));
Params.Add(´password=´ + Trim(Password));
LoginPrompt := false;
Verbose := true;
DatabaseName.Add(Trim(aDatabaseName + ´=4096´));
ServerName := Trim(aServerName);
StatusTexto.Lines.Clear;
BackupFile.Clear;
BackupFile.Add(Trim(aDirBackup));
Protocol := TipoProtocolo;
Options := [CreateNewDB];
Active := true;

// Faz uma cópia e Exclui o Arquivo
if FileExists(Copy(aDatabaseName, 0, Length(aDatabaseName)-4) + ´_Anterior.´ + extensao) then
DeleteFile(PChar(Copy(aDatabaseName, 0, Length(aDatabaseName)-4) + ´_Anterior.´ + extensao));
CopyFile(PChar(aDatabaseName), PChar(Copy(aDatabaseName, 0, Length(aDatabaseName)-4) + ´_Anterior.´ + extensao), True);
// Verifica se exite um arquivo de banco - se tive é excluido
if FileExists(aDatabaseName) then DeleteFile(PChar(aDatabaseName));

Status(StatusTexto, ´ Restauração Iniciada ´,clYellow, 10);
Status(StatusTexto, Format(´Restauração Iniciada às ¬s horas´, [FormatDateTime(´hh:nn:ss´, now)]), clGreen, 1);
StatusTexto.Lines.Add(´´);
ServiceStart;
While not(Eof)do begin
BackupTextNotify(StatusTexto, GetNextLine, Progress);
StaTusTexto.SetFocus;
end;
StatusTexto.Lines.Add(´´);
Status(StatusTexto, ´ Restauração Finalizada ´,clRed, 10);
finally
Active := false;
DeleteFile(PChar(aDirBackup));
Screen.Cursor := crDefault;
StaTusTexto.SetFocus;
end;
end;
end;


// Backup

procedure BackupDatabase(IBBackupService : TIBBackupService; StatusTexto : TRichEdit; aServerName, UserName, Password, aDatabaseName, aDirBackup : String; TipoProtocolo : TProtocol; Progress : TProgressBar);
begin

if not FileExists(aDatabaseName) then begin
Application.MessageBox(´Não foi encontrado a Base de Dados do Sistema.´ + #13 +´Consulte o Administrador do Sistema para obter mais informação.´, ´Backup´, mb_OK + MB_ICONERROR);
abort;
end;

Screen.Cursor := crHourGlass;

// Inicializações do TProgressBar
Progress.Min := 0;
Progress.Position := 0;
Progress.Step := 1;
Progress.Max := 17;

if FileExists(PChar(aDirBackup)) then DeleteFile(PChar(aDirBackup));
with IBBackupService do begin
try
Params.Clear;
Params.Add(´user_name=´ + Trim(UserName));
Params.Add(´password=´ + Trim(Password));
LoginPrompt := false;
Verbose := true;
DatabaseName := Trim(aDatabaseName);
ServerName := Trim(aServerName);
StatusTexto.Lines.Clear;
BackupFile.Clear;
BackupFile.Add(aDirBackup + ´=2048´);
Protocol := TipoProtocolo;
Options := [IgnoreChecksums];
Active := true;
Status(StatusTexto, ´ Backup Iniciado ´,clYellow, 10);
Status(StatusTexto, Format(´Backup Iniciado às ¬s horas´, [FormatDateTime(´hh:nn:ss´, now)]), clGreen, 1);
StatusTexto.Lines.Add(´´);
ServiceStart;
While not(Eof)do begin
BackupTextNotify(StatusTexto, GetNextLine, Progress);
StatusTexto.SetFocus;
end;
StatusTexto.Lines.Add(´´);
Status(StatusTexto, ´ Backup Finalizado ´,clRed, 10);
finally
Active := false;
Screen.Cursor := crDefault;
StatusTexto.SetFocus;
end;
end;
end;


Responder

03/03/2005

Christian_adriano

Desculpa,

Esqueci mais uma função:


procedure Status(StatusTexto : TRichEdit; Status: String; Cor: TColor; Tamanho: byte);
begin
StatusTexto.SelAttributes.Color := Cor;
StatusTexto.SelAttributes.Size := Tamanho;
StatusTexto.Lines.Add(Status);
end;


Abraços,
Christian.


Responder

30/04/2017

Edilberto Oliviera

como posso fazer um stop já que não um método?
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar