How do I make backups. DBMS FireBird

  • Tutorial
image

The trouble came from where they didn’t wait ... The “Cashier” process hung up on the client, so he could not remove the process through the Task Manager. The workplace “Cashier” is simultaneously the server of the entire system.

The client decided to reset via the button.

As a result, DB died. Firebird 2.5

Backups were not configured, so the latest version of the database, which accidentally lay on my screw, was minus 8 days. They picked it up quickly from her. But the point is further.

How to make backups for FireBird.

I wrote a script that, when it is launched, backs up a database called DatabaseDannah_30_05_2017_23_07_51.fbk

@echo off
set "currentTime=%Time: =0%"
set now=%date:~-4%_%date:~3,2%_%date:~0,2%_%currentTime:~0,2%_%currentTime:~3,2%_%currentTime:~6,2%set user=SYSDBA
set password=masterkey
set database_name=PARKDB.FDB
set backup_name=Backup\PARKDB
set ext=.fbk
set backup_filename=%backup_name%_%now%%ext%echo%backup_filename%
nbackup -U %user% -P %password% -B 0%database_name%%backup_filename%

%date:~3,2%

This means taking from the result date (this is a Windows system function), 2 characters, starting at 3 positions in the line. Normal% date% = 05/31/2017

set "currentTime=%Time: =0%"

It means taking time, considering 0, when the clock is less than 10, that is, without this command, when executing the commands:

set now=%date:~-4%_%date:~3,2%_%date:~0,2%_%currentTime:~0,2%_%currentTime:~3,2%_%currentTime:~6,2%

would get now = 2017_05_31_ 0_44_33, and the file name would look like this: Backup \ PARKDB_2017_05_31_ 0_44_33.fbk. The space is not very visible, but it is unacceptable in the file name for nbackup date and time are taken from the current system time. It kind of told :) Next, to make the script run constantly, I added the task to the Windows task scheduler, it launches my script every 4 hours and a new database is created, then I learned how to create tasks in the task scheduler through the command line:

@echo off
set script_name=e:\SoftBuild\Parking\DB\DB_Backup.bat
set task_name=LotParkingBackup
SCHTASKS /Create /SC DAILY /TN %task_name% /TR %script_name% /HRESULT /F /RI 240 /DU 24:00 /v1

Details of the parameters can be found in the help. SCHTASKS / Create /?

Then he added a script to the installer that does what I just described, and starts from the installer:

functionNextButtonClick(CurPageID: Integer): Boolean;
var
  ServerHost, ServerPort, DBFileName, FBDirPath: string;
  ResultCode, ErrorCode: Integer;
  UDFFrom, UDFTo, ReaderPort: string;
  RegistryTaskFile, DBDirPath, BackupScriptPath, RegistryFileName: string;
beginif CurPageID = SettingsPage.ID thenbegin
    ServerHost := SettingsPage.Values[0];
    ServerPort := SettingsPage.Values[1];
    DBFileName := SettingsPage.Values[2];
    if IsComponentSelected(cDB) thenbegin
      DBDirPath := Copy(DBFileName, 1, Pos('PARKDB.FDB', DBFileName) - 1);
      BackupScriptPath := DBDirPath + 'DB_Backup.bat'
      RegistryTaskFile := '@echo off' + #13#10 + 
                          'set script_name=' + BackupScriptPath + #13#10 + 
                          'set task_name=LotParkingBackup' + #13#10 + 
                          'SCHTASKS /Create /SC DAILY /TN %task_name% /TR %script_name% /HRESULT /F /RI 240 /DU 24:00 /v1' + #13#10;
      RegistryFileName := DBDirPath + 'DB_RegistryBackup.bat';
      SaveStringToFile(RegistryFileName, RegistryTaskFile, False);
      Exec(ExpandConstant(RegistryFileName), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
    end;    
  end;
end;

Now I have a script that makes a backup, and a script that registers the task, then I learned to delete the task from the scheduler, again from the command line:

@echo off
set task_name=LotParkingBackup
SCHTASKS /DELETE /TN %task_name% /F

And added to the installer. what if we do the removal of the Parking program, then we need to run a script that will remove the task from the Scheduler:

[UninstallRun]
Filename: "{app}\DB\DB_DeleteTask.bat"; WorkingDir: "{app}\DB\"; Flags: runhidden waituntilterminated; Components: DB

As a result, we have backup every 4 hours, and if we do UnInstall, then everything is clean :)

Original.

Also popular now: