Backing Up Databases

From InterBase

Go Up to Backing up and Restoring Databases


TIBBackupService contains many properties and methods to allow you to build a backup component into your application. Only the SYSDBA user or the database owner will be able to perform backup operations on a database.

When backing up a database under normal circumstances, the backup file will always be on the local server since the backup service cannot open a file over a network connection. However, TIBBackupService can create a remote file in one of the following is true:

  • The server is running on Windows, the path to the backup file is specified as an UNC name, and the destination for the file is another Windows machine (or a machine which can be connected to via UNC naming conventions).
  • The destination drive is mounted via NFS (or some equivalent) on the machine running the InterBase server.

Setting the Backup Options

The Options property allows you to build backup options of type TBackupOption into your application. The backup options are:

TIBBackupService options
Option Meaning

IgnoreChecksums

Ignore checksums during backup

IgnoreLimbo

Ignored limbo transactions during backup

MetadataOnly

Output backup file for metadata only with empty tables

NoGarbageCollect

Suppress normal garbage collection during backup; improves performance on some databases

OldMetadataDesc

Output metadata in pre-4.0 format

NonTransportable

Output backup file with non-XDR data format; improves space and performance by a negligible amount

ConvertExtTables

Convert external table data to internal tables

Displaying Backup Output

Set the Verbose property to True to display the backup output to a data control, such as a Memo component.

Setting Up a Backup Component

To set up a simple backup component:

1. Drop a TIBBackupService component on a Delphi form.
2. Drop Button and Memo components on the form.
3. Enter the name and path of the database to be backed up in the DatabaseName field and the name and path of the database backup file in the BackupFile string field of the Object Inspector, or double click on the button and set the properties in code:
procedure TForm1.Button1Click(Sender: TObject);
begin
with IBBackupService1 do
  begin
   DatabaseName := 'employee.gdb';
  BackupFile.Add('d:\temp\employee1.gbk');
    end;
end;
4. Attach to the service manager as described in Attaching to a Service Manager, or set the properties in code:
with IBBackupService1 do
begin
  ServerName := 'Poulet';
  LoginPrompt := False;
  Params.Add('user_name=sysdba');
  Params.Add('password=masterkey');
  Active := True;
   end;
5. Set any other options in the Object inspector (or set them in code), and then start the service with the ServiceStart method.

The final code for a backup application that displays verbose backup output in a Memo component might look like this:

procedure TForm1.Button1Click(Sender: TObject);
begin
with IBBackupService1 do
begin
ServerName := 'Poulet';
LoginPrompt := False;
Params.Add('user_name=sysdba');
Params.Add('password=masterkey');
Active := True;
try
verbose := True;
Options := [NonTransportable, IgnoreLimbo];
DatabaseName := 'employee.gdb';
BackupFile.Add('d:\temp\employee1.gbk');
ServiceStart;
While not Eof do
Memo1.Lines.Add(GetNextLine);
finally
Active := False;
end;
end;
end;

Backing Up a Database to Multiple Files

InterBase allows you to back up a database to multiple files. To do this, you must specify the size of each backup file except for the last, which will hold the remaining information.

procedure TForm1.Button2Click(Sender: TObject);
begin
with IBBackupService1 do
begin
ServerName := 'Poulet';
LoginPrompt := False;
Params.Add('user_name=sysdba');
Params.Add('password=masterkey');
Active := True;
try
Verbose := True;
Options := [MetadataOnly, NoGarbageCollection];
DatabaseName := 'employee.gdb';
      BackupFile.Add('c:\temp\e1.gbk = 2048');
BackupFile.Add('c:\temp\e2.gbk' = 4096);
BackupFile.Add('c:\temp\e3.gbk'); ServiceStart;
While not Eof do
Memo1.Lines.Add(GetNextLine);
finally
Active := False;
end;
end;
end;

Advance To: