Before you begin, make sure that:
Firebird (e.g. version 4.0) is installed on your system,
you have write permissions for the backup folder,
the file gbak.exe exists (usually in the Firebird installation path),
and the Windows Task Scheduler is available.
๐ป Firebird Silent Automatic Backup Script
Filename: portier_backup.bat
@echo offsetlocal EnableExtensions EnableDelayedExpansion:: ================== Settings ==================set "FBPATH=C:\Program Files (x86)\Firebird\Firebird_4_0\gbak.exe"set "DBPATH=C:\portier\vision5\PORTIERVISION.GDB"set "BKPATH=C:\portier\Backup"set "USER=SYSDBA"set "PASS=masterkey"set "RETENTION_DAYS_BACKUPS=14"set "RETENTION_DAYS_LOGS=30":: ====================================================:: --- Pre-checks & create folder ---if not exist "%BKPATH%" mkdir "%BKPATH%" 2>nulif not exist "%BKPATH%" exit /b 2if not exist "%DBPATH%" exit /b 3if not exist "%FBPATH%" exit /b 4:: --- Timestamp for unique filenames ---for /f %%i in ('powershell -NoProfile -Command "(Get-Date).ToString(\"yyyy-MM-dd_HH-mm-ss\")"') do set "STAMP=%%i"set "BKFILE=%BKPATH%\portier_%STAMP%.fbk"set "LOGFILE=%BKPATH%\backup_log_%STAMP%.txt"( echo ================================================== echo Backup started: %DATE% %TIME% echo gbak: "%FBPATH%" echo DB : "%DBPATH%" echo Target: "%BKFILE%" echo ==================================================)>>"%LOGFILE%":: --- Execute backup silently ---"%FBPATH%" -b -v -user %USER% -pas %PASS% "%DBPATH%" "%BKFILE%" >>"%LOGFILE%" 2>&1set "RC=%ERRORLEVEL%"if "%RC%"=="0" ( echo [%DATE% %TIME%] Backup OK >>"%LOGFILE%") else ( echo [%DATE% %TIME%] ERROR, Code %RC% >>"%LOGFILE%"):: --- Cleanup old backups ---echo.>>"%LOGFILE%"echo [%DATE% %TIME%] Cleaning: *.fbk older than %RETENTION_DAYS_BACKUPS% days >>"%LOGFILE%"forfiles /p "%BKPATH%" /m *.fbk /d -%RETENTION_DAYS_BACKUPS% /c "cmd /c del /q /f @path" 2>>"%LOGFILE%":: --- Cleanup old logs ---echo [%DATE% %TIME%] Cleaning: Logs older than %RETENTION_DAYS_LOGS% days >>"%LOGFILE%"forfiles /p "%BKPATH%" /m backup_log_*.txt /d -%RETENTION_DAYS_LOGS% /c "cmd /c del /q /f @path" 2>>"%LOGFILE%"echo ==================================================>>"%LOGFILE%"echo Backup completed. >>"%LOGFILE%"endlocal & exit /b %RC%Section | Description
Settings | Defines paths and credentials for Firebird, database, and backup folder, as well as file retention days.
Pre-checks | Verifies required folders and files exist; exits with an error code if not.
Timestamp | Generates a unique timestamp (yyyy-MM-dd_HH-mm-ss) for each backup and log file.
Silent Backup Execution | Runs gbak.exe silently, logging all output instead of displaying it on screen.
Error Handling | Writes success or failure (with return code) to the log file.
Cleanup Routine | Automatically deletes old backups and log files older than the defined retention period.
Exit Codes | Returns an exit code to the system (0 = OK, 3 = database missing, etc.), useful for monitoring tools.
==================================================Backup started: 13.10.2025 07:00:01gbak: "C:\Program Files (x86)\Firebird\Firebird_4_0\gbak.exe"DB : "C:\portier\vision5\PORTIERVISION.GDB"Target: "C:\portier\Backup\portier_2025-10-13_07-00-01.fbk"==================================================Starting backup...gbak: creating file C:\portier\Backup\portier_2025-10-13_07-00-01.fbkgbak: writing data...gbak: finishing, closing, and going home[13.10.2025 07:01:12] Backup OKTo run the backup automatically (for example, every night at 2:00 AM):
Open Windows Task Scheduler (taskschd.msc)
Click Create Task
Under General:Name: portier Firebird Backup SilentCheck Run with highest privilegesCheck Run whether user is logged on or not
Under Triggers:New โ Daily โ Time: 02:00
Under Actions:Start a program โ Path: C:\portier\backup\portier_backup_silent.bat
Save and test the task with Right-click โ Run.
โ The script will now run silently in the background โ no console, no confirmation, just logs.
This silent Firebird backup script provides a simple and reliable way to protect your database automatically โ without user interaction.
It logs every operation, removes old files automatically, and can be scheduled to run unattended through the Windows Task Scheduler.