147 lines
4.3 KiB
ObjectPascal
147 lines
4.3 KiB
ObjectPascal
|
|
unit RestaurarCopiaSeguridad;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
|
Dialogs, cxMemo, cxControls, cxContainer, cxEdit, cxTextEdit, cxMaskEdit,
|
|||
|
|
cxButtonEdit, StdCtrls, RdxBotones, RdxBarras, ExtCtrls, RdxPaneles,
|
|||
|
|
Configuracion, RdxShape, RdxFrame, IBServices, Entidades, cxProgressBar;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TfrRestaurarCopiaSeguridad = class(TRdxFrame)
|
|||
|
|
Titulo: TRdxBarraSuperior;
|
|||
|
|
brInferior: TRdxBarraInferior;
|
|||
|
|
bCerrar: TRdxBoton;
|
|||
|
|
ArchivoCopiaSeguridad: TcxButtonEdit;
|
|||
|
|
Label3: TLabel;
|
|||
|
|
bRestore: TRdxBoton;
|
|||
|
|
eMensaje: TLabel;
|
|||
|
|
pnlAtencion: TRdxShape;
|
|||
|
|
Label1: TLabel;
|
|||
|
|
Label2: TLabel;
|
|||
|
|
IBRestoreService1: TIBRestoreService;
|
|||
|
|
OpenDialog1: TOpenDialog;
|
|||
|
|
cxProgressBar1: TcxProgressBar;
|
|||
|
|
procedure ArchivoCopiaSeguridadPropertiesButtonClick(Sender: TObject;
|
|||
|
|
AButtonIndex: Integer);
|
|||
|
|
procedure bCerrarClick(Sender: TObject);
|
|||
|
|
procedure bRestoreClick(Sender: TObject);
|
|||
|
|
procedure ArchivoCopiaSeguridadExit(Sender: TObject);
|
|||
|
|
private
|
|||
|
|
procedure RestaurarBackup;
|
|||
|
|
protected
|
|||
|
|
function CambiarEntidad(EntidadAnterior, Entidad : TRdxEntidad): Boolean; override;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
var
|
|||
|
|
frRestaurarCopiaSeguridad: TfrRestaurarCopiaSeguridad;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
{$R *.dfm}
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
DateUtils, Math, Mensajes, StrFunc, BaseDatos, IB;
|
|||
|
|
|
|||
|
|
procedure TfrRestaurarCopiaSeguridad.ArchivoCopiaSeguridadPropertiesButtonClick(
|
|||
|
|
Sender: TObject; AButtonIndex: Integer);
|
|||
|
|
begin
|
|||
|
|
OpenDialog1.FileName := ArchivoCopiaSeguridad.Text;
|
|||
|
|
if OpenDialog1.Execute then
|
|||
|
|
begin
|
|||
|
|
ArchivoCopiaSeguridad.Text := OpenDialog1.FileName;
|
|||
|
|
bRestore.SetFocus;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrRestaurarCopiaSeguridad.bCerrarClick(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
CloseFrame;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrRestaurarCopiaSeguridad.bRestoreClick(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
if EsCadenaVacia(ArchivoCopiaSeguridad.Text) then
|
|||
|
|
begin
|
|||
|
|
VerMensaje('Debe indicar la ruta y el nombre del archivo de la copia de seguridad a restaurar.');
|
|||
|
|
ArchivoCopiaSeguridad.SetFocus;
|
|||
|
|
Exit;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if not FileExists(ArchivoCopiaSeguridad.Text) then
|
|||
|
|
begin
|
|||
|
|
VerMensaje('El archivo no se encuentra. Aseg<65>rese de que ha escrito correctamente la ruta y el nombre.');
|
|||
|
|
ArchivoCopiaSeguridad.SetFocus;
|
|||
|
|
Exit;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
RestaurarBackup;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrRestaurarCopiaSeguridad.ArchivoCopiaSeguridadExit(
|
|||
|
|
Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
if not EsCadenaVacia(ArchivoCopiaSeguridad.Text) then
|
|||
|
|
begin
|
|||
|
|
if Pos('.gbk', ArchivoCopiaSeguridad.Text) = 0 then
|
|||
|
|
ArchivoCopiaSeguridad.Text := ArchivoCopiaSeguridad.Text + '.gbk';
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrRestaurarCopiaSeguridad.RestaurarBackup;
|
|||
|
|
begin
|
|||
|
|
with IBRestoreService1 do
|
|||
|
|
begin
|
|||
|
|
LoginPrompt := False;
|
|||
|
|
Params.Add('user_name=sysdba');
|
|||
|
|
Params.Add('password=masterkey');
|
|||
|
|
Options := [Replace, UseAllSpace];
|
|||
|
|
PageBuffers := 3000;
|
|||
|
|
PageSize := 4096;
|
|||
|
|
Protocol := TCP;
|
|||
|
|
ServerName := dmBaseDatos.NombreServidor;
|
|||
|
|
DatabaseName.Clear;
|
|||
|
|
DatabaseName.Add(dmBaseDatos.RutaBD);
|
|||
|
|
BackupFile.Clear;
|
|||
|
|
BackupFile.Add(ArchivoCopiaSeguridad.Text);
|
|||
|
|
try
|
|||
|
|
Verbose := True;
|
|||
|
|
Active := True;
|
|||
|
|
dmBaseDatos.Desconectar;
|
|||
|
|
ServiceStart;
|
|||
|
|
eMensaje.Visible := True;
|
|||
|
|
cxProgressBar1.Visible := True;
|
|||
|
|
cxProgressBar1.Position := 0;
|
|||
|
|
eMensaje.Caption := 'Espere, por favor...';
|
|||
|
|
eMensaje.Update;
|
|||
|
|
while not EOF do
|
|||
|
|
begin
|
|||
|
|
GetNextLine;
|
|||
|
|
cxProgressBar1.Position := cxProgressBar1.Position + 1;
|
|||
|
|
end;
|
|||
|
|
Active := False;
|
|||
|
|
dmBaseDatos.Conectar;
|
|||
|
|
cxProgressBar1.Position := cxProgressBar1.Properties.Max;
|
|||
|
|
eMensaje.Caption := 'Copia de seguridad restaurada correctamente.';
|
|||
|
|
VerMensaje('Copia de seguridad restaurada correctamente.');
|
|||
|
|
bCerrar.SetFocus;
|
|||
|
|
except
|
|||
|
|
on E : EIBError do
|
|||
|
|
begin
|
|||
|
|
Active := False;
|
|||
|
|
VerMensaje('Alg<6C>n usuario est<73> conectado a la base de datos. Para poder restaurar la copia de seguridad es necesario que no haya nadie m<>s aparte de usted que est<73> utilizando FactuGES.');
|
|||
|
|
dmBaseDatos.Conectar;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfrRestaurarCopiaSeguridad.CambiarEntidad(EntidadAnterior, Entidad: TRdxEntidad): Boolean;
|
|||
|
|
begin
|
|||
|
|
inherited CambiarEntidad(EntidadAnterior, Entidad);
|
|||
|
|
ConfigurarFrame(Self, Self.Entidad);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|