TFBAdmin
│
English (en) │
français (fr) │
References:
Tutorials/practical articles:
Databases |
TFBAdmin is a component that aids in Interbase/Firebird administration tasks. It can be found on the SQLdb tab of the Component Palette and resides in the FBAdmin unit. It provides the following functionality:
- add, modify or delete database users
- backup and restore databases using single or multiple (split) files
- get general database information
- get the database log file listing important database events and errors
There is also a Lazarus component and demo that allows use of the FPC TFBAdmin component.
Example
This shows how to create a multi file backup of a database on a Linux server; 3 backup files, size limited to 600MB; backup progress shown in a TMemo:
procedure TForm1.logadm(Sender: TObject; msg: string; IBAdminAction: string);
begin
Memo1.Lines.add(IBAdminAction+' : '+msg);
end;
procedure TForm1.backup;
var
Admin:TFBAdmin;
sl:TStringList;
begin
Admin:=TFBAdmin.Create(self);
sl:=TStringList.create;
try
Admin.UseExceptions:=true;
Admin.Host:='192.168.2.98';
Admin.Protocol:=IBSPTCPIP;
Admin.User:='sysdba';
Admin.Password:='masterkey';
Admin.Port:= 3050; //change if not using the default port
Admin.Connect;
Admin.OnOutput:=@logadm;
sl.Add('/home/firebird/test.bak1');
sl.Add('/home/firebird/test.bak2');
sl.Add('/home/firebird/test.bak3');
Admin.BackupMultiFile('/home/firebird/test.fdb',sl,600000000,[IBBkpVerbose]);
finally
sl.Destroy;
Admin.Destroy; //disconnects automatically
end;
end;
A demo program is also available in the examples directory of the fcl-db package.
The following example shows how to backup to and restore from a single file on a Windows-server:
uses
FBAdmin;
procedure TForm1.logadm(Sender: TObject; msg: string; IBAdminAction: string);
begin
Memo1.Lines.add(IBAdminAction + ' : ' + msg);
end;
procedure Backup(Database, Backupfile: string);
var
Admin: TFBAdmin;
begin
Admin := TFBAdmin.Create(nil);
try
Admin.UseExceptions := True;
Admin.Host := '192.168.1.66';
Admin.Protocol := IBSPTCPIP;
Admin.User := 'SYSDBA';
Admin.Password := 'masterkey';
Admin.Port := 3050; //change if not using the default port
Admin.Connect;
Admin.OnOutput := @Form1.logadm;
Admin.Backup(Database, Backupfile, [IBBkpVerbose]);
finally
Admin.Free; //disconnects automatically
end;
end;
procedure Restore(Database, Backupfile: string);
var
Admin: TFBAdmin;
begin
Admin := TFBAdmin.Create(nil);
try
Admin.UseExceptions := True;
Admin.Host := '192.168.1.66';
Admin.Protocol := IBSPTCPIP;
Admin.User := 'SYSDBA';
Admin.Password := 'masterkey';
Admin.Port := 3050; //change if not using the default port
Admin.Connect;
Admin.OnOutput := @Form1.logadm;
Admin.Restore(Database, Backupfile, [IBResVerbose, IBResReplace]);
finally
Admin.Free; //disconnects automatically
end;
end;
procedure TForm1.btBackupClick(Sender: TObject);
begin
Backup('c:\data\demo.fdb', 'c:\temp\demo.fbk');
end;
procedure TForm1.btRestoreClick(Sender: TObject);
begin
Restore('c:\data\demo_restored.fdb', 'c:\temp\demo.fbk');
end;
See also
- Firebird Using Firebird with FPC/Lazarus sqldb.