Backing Up and Restoring Databases Using isc_action_svc_backup
Go Up to Invoking Service Tasks with isc_service_start( )
Use the cluster identifier isc_action_svc_backup
to request that the Services Manager perform a backup operation. This is a programmatic method to invoke the gbak
tool as a thread in the ibserver
process. You must specify the path of the database primary file, and the path of the backup output file or files.
Paths of backup files are relative to the server. Because the Services Manager executes backup and restore tasks on the server host, the Services Manager reads and writes backup files on the server host. The Services Manager also creates files in the context of the server. If, on a UNIX system, you run your server as root, restoring a backup may fail because of the protection put on the backup file when the server created it.
You can specify additional options as needed. Some options require arguments, while other options are bits in an option bitmask.
The following table lists arguments to isc_action_svc_backup
:
Argument | Purpose | Argument length | Argument value |
---|---|---|---|
|
Path of the primary file of the database, from the server’s point of view |
2 bytes + string |
String |
|
If specified, the Services Manager prepares output to return via |
— |
— |
|
Path of a backup output file; you can specify multiple output files; corresponds to |
2 bytes + string |
String |
|
Length in bytes of the backup output file; you must specify one length value for each output file except the last; corresponds to |
2 bytes + string |
String |
|
Tape device blocking factor; corresponds to |
4 bytes |
Unsigned long |
|
The following value is a bitmask of |
4 bytes |
Bitmask |
|
Ignore checksums during backup; corresponds to |
— |
Bit |
|
Ignore limbo transactions during backup; corresponds to |
— |
Bit |
|
Output backup file for metadata only with empty tables; corresponds to |
— |
Bit |
|
Suppress normal garbage collection during backup; improves performance on some databases; corresponds to |
— |
Bit |
|
Output metadata in pre-4.0 format; corresponds to |
— |
Bit |
|
Output backup file format with non-XDR data format; improves space and performance by a negligible amount; corresponds to |
— |
Bit |
|
Convert external table data to internal tables; corresponds to |
— |
Bit |
|
Database pages to be preallocated; corresponds to gbak -preallocate. Set to 0 to disable preallocation |
4 byptes |
Unsigned long |
Starting a database backup service in C/C++
char request[100], *x, *p = request;
/* Identify cluster */
*p++ = isc_action_svc_backup;
/* Argument for database filename */
*p++ = isc_spb_dbname;
ADD_SPB_LENGTH(p, strlen(argv[1]));
for (x = argv[1]; *x; ) *p++ = *x++;
/* Argument for backup output filename */
*p++ = isc_spb_bkp_file;
ADD_SPB_LENGTH(p, strlen(argv[2]));
for (x = argv[2]; *x; ) *p++ = *x++;
/* Argument to request verbose output */
*p++ = isc_spb_verbose;
if (isc_service_start(status, &service_handle, NULL, p - request, request)) {
isc_print_status(status);
isc_service_detach(status, service_handle);
exit(1);
}
You can also restore a database backup file to create a new database file. The following table lists arguments to the cluster identifier isc_action_svc_restore
:
Argument | Purpose | Argument length | Argument value |
---|---|---|---|
|
The path of the backup file name |
2 bytes + string |
String |
|
Path of the primary file of the database, from the server’s point of view; you can specify multiple database files |
2 bytes + string |
String |
|
The length in pages of the restored database file; must not exceed 2 gigabytes; you must supply a length for each database file except the last |
4 bytes |
Unsigned long; |
|
If specified, the Services Manager prepares output to return via |
— |
— |
|
The number of default cache buffers to configure for attachments to the restored database; corresponds to |
4 bytes |
Unsigned long; number of buffers |
|
The page size for the restored database; corresponds to |
||
|
Set the access mode of the database; the next byte must be one of:
Corresponds to |
1 byte |
Byte |
|
User name to authenticate with EUA user accounts in backup file |
2 bytes + string |
String |
|
Password to authenticate with EUA user accounts in backup file |
2 bytes + string |
String |
|
The following value is a bitmask of |
4 bytes |
Bitmask |
|
Do not build user indexes during restore; corresponds to |
— |
Bit |
|
Do not recreate shadow files during restore; corresponds to |
— |
Bit |
|
Do not enforce validity conditions (for example, |
— |
Bit |
|
Commit after completing restore of each table; corresponds to |
— |
Bit |
|
Replace database, if one exists; corresponds to |
— |
Bit |
|
Restore but do not overwrite an existing database; corresponds to |
— |
Bit |
|
Enables validation during a database restore. |
||
|
Do not reserve 20 percent of each data page for future record versions; useful for read-only databases; corresponds to |
— |
Bit |
|
Set the write mode of the database; the next byte must be one of: - isc_spb_res_wm_async Corresponds to gbak -write |
1 byte |
Byte |
|
Database pages to be preallocated; corresponds to gbak -preallocate. Set to 0 to disable preallocation |
4 bytes |
Unsigned long |
|
Restore database with specified major ODS version as the target version |
4-byte ISC_ULONG integer |
Unsigned long; |
Starting a Database Restore Service in C/C++
char request[100], *x, *p = request;
unsigned long options;
/* Identify cluster */
*p++ = isc_action_svc_restore;
/* Arguments for backup filenames */
for (i = 1; argc > 1; --argc; ++i) {
*p++ = isc_spb_bkp_file;
ADD_SPB_LENGTH(p, strlen(argv[i]));
for (x = argv[i]; *x; ) *p++ = *x++;
}
/* Argument for database filename */
*p++ = isc_spb_db_name;
ADD_SPB_LENGTH(p, strlen(argv[i]));
for (x = argv[i]; *x; ) *p++ = *x++;
/* Argument to request verbose output */
*p++ = isc_spb_verbose;
/* Argument to specify restore options */
*p++ = isc_spb_options;
options = isc_spb_res_ create;
ADD_SPB_NUMERIC(p, options);
if (isc_service_start(status, &service_handle, NULL, p - request, request)) {
isc_print_status(status);
isc_service_detach(status, service_handle);
exit(1);
}