How to schedule a daily, hourly, etc. backup?


Firebird relies on your operating system tools to do that. On Windows, you can use task scheduler to invoke a small .bat script within which you can create directories, invoke command-like gbak tool from 'bin' directory of Firebird installation and use tools like zip or rar to pack the backup file.

On Linux, you can use the crond system service. You can set it up using some graphical tool, or from command line using 'crontab -e' command. Same as with Windows, you can set up a batch job (a shell script) for it. Here's example of Linux script run by cron:

#!/bin/bash
BCKNAME=/mnt/backup/`date +%Y`/mydb-`date +%F`.gbk
LOGNAME=/mnt/backup/`date +%Y`/log/mydb-`date +%F`.log
if [ ! -d /mnt/backup/`date +%Y` ]; then
mkdir /mnt/backup/`date +%Y`
fi
if [ ! -d /mnt/backup/`date +%Y`/log ]; then
mkdir /mnt/backup/`date +%Y`/log
fi
rm -f $BCKNAME.gz
rm -f $LOGNAME.gz
(/opt/firebird/bin/gbak -b -v localhost:/dbases/mydb.fdb -user sysdba -pass ***** $BCKNAME 2>&1) > $LOGNAME
gzip $BCKNAME
gzip $LOGNAME

In this example, all backup files are stored in directory /mnt/backup/YEAR, where YEAR is the current year (ex. 2007). Each backup file is named by the date when it was made in format YYYY-MM-DD which ensures that alphabetical sorting is the same as sort by date. Log of each backup is stored in log subdirectory.

If you do a scheduled backup on Windows, make sure you use localhost: prefix in your database path, as otherwise the Windows requires that you are logged in at the console (and if server reboots for any reason, that will not be the case).

For Mac OSX, you can use the same script with minor modifications (contributed by Karl Kliem):

#!/bin/bash
BCKNAME=/mnt/backup/`date +%Y`/mydb-`date +%F`.gbk
LOGNAME=/mnt/backup/`date +%Y`/log/mydb-`date +%F`.log
if [ ! -d /mnt/backup/`date +%Y` ]; then
mkdir /mnt/backup/`date +%Y`
fi
if [ ! -d /mnt/backup/`date +%Y`/log ]; then
mkdir /mnt/backup/`date +%Y`/log
fi
rm -f $BCKNAME.gz
rm -f $LOGNAME.gz
(/Library/Frameworks/Firebird.framework/Resources/bin/gbak -b -v localhost:/dbases/mydb.fdb -user sysdba -pass ***** $BCKNAME 2>&1) > $LOGNAME
gzip $BCKNAME
gzip $LOGNAME


Some people prefer to use custom-made tools for Windows to do the backup automation. Although cron is also available for Windows, bash shell is not, and Microsoft's command-prompt is still not that extensible. Here are some specialized tools for Windows:

FIBackup - open source - IDPL license
http://fbutils.sourceforge.net/fibackup/

FIBS - open source - GPL license
http://sourceforge.net/projects/fibs-open/
FIBS was originally available at talatdogan.com. Since it is GPL, we host a copy right here are FirebirdFAQ website. We have a binary for version 2.0.0, and the latest source package for version 2.0.2. FIBS is written in Delphi:
http://www.firebirdfaq.org/files/fibs200setup.exe
http://www.firebirdfaq.org/files/fibs-source.zip

Gbak Scheduler by Mauro Barbieri (freeware)
http://gbak.scheduler.googlepages.com/

Firebird SQL Database Manager from Crypton (freeware)
http://www.crypton.co.uk/freetools.html

Time To Backup - commercial
http://www.sqlly.com/download.html

xStarter Job Scheduler for Firebird/Interbase
http://www.xstarter.com/firebird-interbase-job-scheduler.html

There might be other tools, if you are aware of some, please let us know.



Do you find this FAQ incorrect or incomplete? Please e-mail us what needs to be changed. To ensure quality, each change is checked by our editors (and often tested on live Firebird databases), before it enters the main FAQ database. If you desire so, the changes will be credited to your name. To learn more, visit our add content page.

If you are a commercial tool maker and your tool features a great way to handle the issue written about in this FAQ, please check out our advertisement page.



All contents are copyright © 2007-2017 FirebirdFAQ.org unless otherwise stated in the text.


Links   Firebird   News   FlameRobin   Home Inventory powered by FB  
Add content   Advertise   About  

Categories
 Newbies
 SQL
 Installation and setup
 Backup and restore
 Performance
 Security
 Connectivity and API
 HOWTOs
 Errors and error codes
 Miscellaneous