[firebase-br] Backup e Restore usando IBO
Magno System
magno em speet.com.br
Qua Jan 7 14:56:34 -03 2009
Backup:
procedure TFrmBackup.BitBtn1Click(Sender: TObject);
var
origem, servidor, caminho, destino: string;
arquivo: tinifile;
lBackupService: TIBOBackupService;
begin
Arquivo := TInifile.Create(Extractfilepath(Application.ExeName) +
'sisgemp.ini');
Servidor := Arquivo.ReadString('Sisgemp', 'Servidor', '');
Caminho := Arquivo.ReadString('Sisgemp', 'Caminho',
Extractfilepath(Application.ExeName) + 'sisgemp.fdb');
Origem := Caminho;
if copy(Directorylistbox1.Directory, length(Directorylistbox1.Directory), 1)
= '\' then
Destino := Directorylistbox1.Directory + 'BackupSNGPC_' +
formatdatetime('DDMMYYYY', Date) + '_' + formatdatetime('HHmm', time) +
'.fbk'
else
Destino := Directorylistbox1.Directory + '\BackupSNGPC_' +
formatdatetime('DDMMYYYY', Date) + '_' + formatdatetime('HHmm', time) +
'.fbk';
lBackupService := TIBOBackupService.Create(nil);
if Servidor <> '' then
Begin
lBackupService.ServerName := Servidor;
lBackupService.Protocol := cptcp_ip;
end
else
Begin
lBackupService.Protocol := cplocal;
Origem := Caminho;
end;
lBackupService.Params.Add('user_name=SYSDBA');
lBackupService.Params.Add('password=masterkey');
lBackupService.LoginPrompt := false;
lBackupService.Attach;
if lBackupService.Active = true then
begin
Bitbtn1.Enabled := false;
lBackupService.Verbose := true;
lBackupService.DatabaseName := origem;
lBackupService.BackupFile.Text := destino;
lBackupService.ServiceStart;
Memo1.Lines.Clear;
while not lBackupService.eof do
Begin
Memo1.Lines.add( lBackupService.getNextline);
Application.ProcessMessages;
end;
while (lBackupService.IsServiceRunning) do
Application.ProcessMessages;
if lBackupService.Active then
lBackupService.Detach();
Bitbtn1.Enabled := true;
Application.ProcessMessages;
Showmessage('Backup realizado com sucesso!!!');
end;
end;
Restore:
procedure TFrmRestauracao.BitBtn1Click(Sender: TObject);
var
origem, destino: string;
arquivo: tinifile;
lBackupService: TIBORestoreService;
begin
Case Messagedlg('A T E N Ç Ã O !!! Após a restauração o banco de dados
restaurado substituirá o banco de dados atual!!! Confirma a restauração?',
mtconfirmation, [mbyes,mbno], 0) of
id_no: exit;
end;
Arquivo := TInifile.Create(Extractfilepath(Application.ExeName) +
'sisgemp.ini');
Origem := FileListbox1.FileName;
Destino := Extractfilepath(Arquivo.ReadString('Sisgemp', 'Caminho',
Extractfilepath(Application.ExeName) + 'SISGEMP.FDB')) + 'SISGEMP.TMP';
lBackupService := TIBORestoreService.Create(nil);
lBackupService.Params.Add('user_name=SYSDBA');
lBackupService.Params.Add('password=masterkey');
lBackupService.LoginPrompt := false;
lBackupService.Protocol := cpLocal;
//lBackupService.Options := [Replace];
lBackupService.Attach;
if lBackupService.Active = true then
begin
Bitbtn1.Enabled := false;
lBackupService.Verbose := true;
lBackupService.DatabaseName.Add(destino);
lBackupService.BackupFile.Text := origem;
lBackupService.ServiceStart;
Memo1.Lines.Clear;
while not lBackupService.eof do
Begin
Memo1.Lines.add( lBackupService.getNextline);
Application.ProcessMessages;
end;
while (lBackupService.IsServiceRunning) do
Application.ProcessMessages;
if lBackupService.Active then
lBackupService.Detach();
Application.ProcessMessages;
if fileexists(Extractfilepath(Application.ExeName) +
'SISGEMP_ANTIGO.FDB') then
DeleteFile(Extractfilepath(Application.ExeName) +
'SISGEMP_ANTIGO.FDB');
Try
Datacliente.IBSisgemp.Disconnect;
Finally
Begin
RenameFile(Extractfilepath(Application.ExeName) + 'SISGEMP.FDB',
Extractfilepath(Application.ExeName) + 'SISGEMP_ANTIGO.FDB');
RenameFile(Extractfilepath(Application.ExeName) + 'SISGEMP.TMP',
Extractfilepath(Application.ExeName) + 'SISGEMP.FDB');
Bitbtn1.Enabled := true;
Showmessage('Restauração efetuada com sucesso!!! O programa deverá
ser reiniciado');
Application.MainForm.Close;
end;
end;
end;
end;
----- Original Message -----
From: "Cleidson" <cleidson em zmed.com.br>
To: <lista em firebase.com.br>
Sent: Wednesday, January 07, 2009 12:42 PM
Subject: Re: [firebase-br] Backup e Restore usando IBO
Fiz isso, mas ainda não estou conseguindo fazer o backup. Está havendo
dois erros: está acusando a falta da GDS32.DLL mesmo eu tendo colocado a
tal em todos os diretorios possíveis, e o outro erro é que quando dou um
ServiceStart dá o erro: "service is not attached".
Tem algum exemplo de uso do IBOADMIN por ai ?
Carlos H. Cantu escreveu:
> Vc tem que baixar e instalar os componentes IBOAdmin, que contem os
> componentes de backup, restore, etc.
>
> []s
> Carlos H. Cantu
> www.FireBase.com.br - www.firebirdnews.org
> www.warmboot.com.br - blog.firebase.com.br
>
> C> Alguém sabe me dizer como realizar essas operacoes de banco usando o
> IBO ?
>
>
>
> ______________________________________________
> FireBase-BR (www.firebase.com.br) - Hospedado em www.locador.com.br
> Para saber como gerenciar/excluir seu cadastro na lista, use:
> http://www.firebase.com.br/fb/artigo.php?id=1107
> Para consultar mensagens antigas: http://firebase.com.br/pesquisa
>
______________________________________________
FireBase-BR (www.firebase.com.br) - Hospedado em www.locador.com.br
Para saber como gerenciar/excluir seu cadastro na lista, use:
http://www.firebase.com.br/fb/artigo.php?id=1107
Para consultar mensagens antigas: http://firebase.com.br/pesquisa
Mais detalhes sobre a lista de discussão lista