Difference between revisions of "TFBAdmin"
m (→Example) |
m (Fixed syntax highlighting) |
||
(10 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
− | + | {{TFBAdmin}} | |
− | {{ | + | {{Infobox databases}} |
+ | |||
+ | '''TFBAdmin''' [[image:tfbadmin.png]] 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 | * add, modify or delete database users | ||
* backup and restore databases using single or multiple (split) files | * backup and restore databases using single or multiple (split) files | ||
Line 11: | Line 12: | ||
== Example == | == Example == | ||
− | This shows how to create a multi file backup of a database on a | + | |
− | <syntaxhighlight> | + | 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: |
+ | |||
+ | <syntaxhighlight lang=pascal> | ||
procedure TForm1.logadm(Sender: TObject; msg: string; IBAdminAction: string); | procedure TForm1.logadm(Sender: TObject; msg: string; IBAdminAction: string); | ||
begin | begin | ||
Line 31: | Line 34: | ||
Admin.User:='sysdba'; | Admin.User:='sysdba'; | ||
Admin.Password:='masterkey'; | Admin.Password:='masterkey'; | ||
+ | Admin.Port:= 3050; //change if not using the default port | ||
Admin.Connect; | Admin.Connect; | ||
Admin.OnOutput:=@logadm; | Admin.OnOutput:=@logadm; | ||
Line 45: | Line 49: | ||
A demo program is also available in the examples directory of the fcl-db package. | 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: | ||
+ | |||
+ | <syntaxhighlight lang=pascal> | ||
+ | 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; | ||
+ | </syntaxhighlight> | ||
== See also == | == See also == | ||
− | |||
− | [[ | + | * [[Firebird]] Using Firebird with FPC/Lazarus sqldb. |
− | + | ||
− | + | {{LCL Components}} | |
− |
Latest revision as of 04:50, 1 March 2020
│
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.