Schedule database backup using DBMaster
To schedule a backup using DBMaster follow the steps below. It is assumed that
you have setup bin paths in the "Preferences" and have an alias fe1 for database
Firebird.localhost.Employee.
- Open Macro Editor from "File" menu.
- Click on "New Macro" button in the toolbar.
- Type command backup fe1 to "c:\Temp\Employee.fbk".
- To save the macro click "Save Macro" button in the toolbar. A save dialog
will pop up asking for macro name, type in anything you want, we will call
this macro FBBackups.
- Close the Command Panel window and open it again from the File menu and
goto Macro tab. Double click on FBBackups. This will put a command Run Macro
FBBackups in the command edit box. Press enter to run the macro. The output
from gbak will be shown in Console Output tab. If the macro executes
successfully then command edit box is cleared and the command is added to
command log.
- To schedule this macro go to Start->All Programs->Accessories->
System Tools->Schedule Tasks and click Add Scheduled Task. This will bring
up the Schedule Task Wizard. Click Next and then search for DBMaster in the
list of applications. Select DBMaster and click Next. Give the task a
suitable name and select an option from Perform this task. We will select
Daily. Select a start time and other parameters you want and click Next.
Enter your user name and password if required and click Next. Check Open
advanced properties for this task when I click Finish and press Finish. In
the Properties Dialog on Task tab you will see path to DBMaster next to Run
label. Add " macro FBBackups" (add a space before macro) after the DBMater
path and click Apply.
- You should now have a new task in your scheduled task list.
- Right click on this task and click Run. This should start DBMaster and
execute macro FBBackups. After the macro has executed go to C:\Temp and you
should see Employee.fbk file there.
- To close DBMaster after executing the macro click on Macros tab and select
FBBackups and press F2 or right click and click Edit Macro. This will open
the Macro Editor window. After the backup command add shutdown command on
the next line and save the macro. Close DBMaster and then run the Schedule
Task again. This time DBMaster should close after running the macro.
- You could add whatever command you want to this macro. You could add
multiple backup command to backup multiple databases. You could also add
commands to run some stored procedures before backing up. You could also
write commands to export some tables to SQLite database and then fire
external program in the macro. This shows that macros can be quite a
powerful tool.
Using Script in SQL window
Open SQL window and execute sql command "select* from country". Go to script tab
and paste the following script
var
lCountry : string;
begin
qry.First;
while not qry.Eof do
begin
lCountry := Country.AsString;
qry.Next;
end;
end.
Press CTRL+F9 to compile the script and F9 to run the script.
From the script it is clear that Field in the query can be accessed using their
names. The name is actually of type TField(like in Delphi). Same script would
work in Script editor with following changes
var
lCountry : string;
begin
if (RunQry('fe1', 'select * from country')) then
begin
qry.First;
while not qry.Eof do
begin
lCountry := qry.FieldValues['COUNTRY'];
qry.Next;
end;
end;
end.