📜 ⬆️ ⬇️

How do i make backups. DBMS FireBird

image

The trouble came from not having waited ... The client had a cashier process, so it could not withdraw the process through the Task Manager. Workplace "Cashier" - at the same time 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 happened to be on my screw, was minus 8 days. Raised in a quick way with her. But the essence is further.
')
How to make backups for FireBird.

I wrote a script that, when it is launched, backs up a database with the name BaseDanna_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 position 3 in a 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, we are in the execution of commands:

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

would get that 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 not acceptable in the file name for nbackup, the date and time are taken from the current system time. It’s kind of told :) Next, to keep the script running constantly, I added a task to the Windows task scheduler, it runs my script every 4 hours and a new database is created, then I learned how to create tasks in the task scheduler via 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 I added a script to the installer that does what I just described and starts from the installer:

 function NextButtonClick(CurPageID: Integer): Boolean; var ServerHost, ServerPort, DBFileName, FBDirPath: string; ResultCode, ErrorCode: Integer; UDFFrom, UDFTo, ReaderPort: string; RegistryTaskFile, DBDirPath, BackupScriptPath, RegistryFileName: string; begin if CurPageID = SettingsPage.ID then begin ServerHost := SettingsPage.Values[0]; ServerPort := SettingsPage.Values[1]; DBFileName := SettingsPage.Values[2]; if IsComponentSelected(cDB) then begin 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 copy, 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. that if we do the removal of the Parking program, then we need to run a script that deletes 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 a backup every 4 hours, and if we do UnInstall, then everything is clean :)

Original.

Source: https://habr.com/ru/post/329914/


All Articles