Although this function provides one way to add backup features to an application, the recommended way to do this task is to use the BACKUP DATABASE statement.
void db_backup( SQLCA * sqlca, int op, int file_num, unsigned long page_num, struct sqlda * sqlda);
Must be connected as a user with BACKUP DATABASE system privilege, or have the SYS_RUN_REPLICATION_ROLE system role.
Although this function provides one way to add backup features to an application, the recommended way to do this task is to use the BACKUP DATABASE statement.
The action performed depends on the value of the op parameter:
The file_num, page_num, and sqlda parameters are ignored.
The page_num and sqlda parameters are ignored.
DT_BINARY data contains a two-byte length followed by the actual binary data, so the buffer must be two bytes longer than the page size.
If the database server is unable to rename the log at the current time (for example in version 7.0.x or earlier databases there may be incomplete transactions), the SQLE_BACKUP_CANNOT_RENAME_LOG_YET error is set. In this case, do not use the page returned, but instead reissue the request until you receive SQLE_NOERROR and then write the page. Continue reading the pages until you receive the SQLE_NOTFOUND condition.
The SQLE_BACKUP_CANNOT_RENAME_LOG_YET error may be returned multiple times and on multiple pages. In your retry loop, you should add a delay so as not to slow the server down with too many requests.
When you receive the SQLE_NOTFOUND condition, the transaction log has been backed up successfully and the file has been renamed. The name for the old transaction file is returned in the sqlerrmc field of the SQLCA.
You should check the sqlda->sqlvar[0].sqlind value after a db_backup call. If this value is greater than zero, the last log page has been written and the log file has been renamed. The new name is still in sqlca.sqlerrmc, but the SQLCODE value is SQLE_NOERROR.
You should not call db_backup again after this, except to close files and finish the backup. If you do, you get a second copy of your backed up log file and you receive SQLE_NOTFOUND.
The page_num and sqlda parameters are ignored.
The file_num, page_num and sqlda parameters are ignored.
The file_num parameter instructs the database server to rename the transaction log and start a new one after the last page of the transaction log has been returned. If the value is non-zero then the transaction log is renamed or restarted. Otherwise, it is not renamed and restarted. This parameter eliminates the need for the DB_BACKUP_READ_RENAME_LOG operation, which is not allowed during a parallel backup operation.
The page_num parameter informs the database server of the maximum size of the client's buffer, in database pages. On the server side, the parallel backup readers try to read sequential blocks of pages—this value lets the server know how large to allocate these blocks: passing a value of nnn lets the server know that the client is willing to accept at most nnnn database pages at a time from the server. The server may return blocks of pages of less than size nnn if it is unable to allocate enough memory for blocks of nnn pages. If the client does not know the size of database pages until after the call to DB_BACKUP_PARALLEL_START, this value can be provided to the server with the DB_BACKUP_INFO operation. This value must be provided before the first call to retrieve backup pages (DB_BACKUP_PARALLEL_READ).
The sqlda descriptor should be set up with one variable of type DT_LONGBINARY pointing to a buffer. The buffer should be large enough to hold binary data of the size nnn pages (specified in the DB_BACKUP_START_PARALLEL operation, or in a DB_BACKUP_INFO operation).
The server returns a sequential block of database pages for a particular database file. The page number of the first page in the block is returned in the SQLCOUNT field. The file number that the pages belong to is returned in the SQLIOESTIMATE field, and this value matches one of the file numbers used in the DB_BACKUP_OPEN_FILE calls. The size of the data returned is available in the stored_len field of the DT_LONGBINARY variable, and is always a multiple of the database page size. While the data returned by this call contains a block of sequential pages for a given file, it is not safe to assume that separate blocks of data are returned in sequential order, or that all of one database file's pages are returned before another database file's pages. The caller should be prepared to receive portions of another individual file out of sequential order, or of any opened database file on any given call.
An application should make repeated calls to this operation until the size of the read data is 0, or the value of sqlda->sqlvar[0].sqlind is greater than 0. If the backup is started with transaction log renaming/restarting, SQLERROR could be set to SQLE_BACKUP_CANNOT_RENAME_LOG_YET. In this case, do not use the pages returned, but instead reissue the request until you receive SQLE_NOERROR, and then write the data. The SQLE_BACKUP_CANNOT_RENAME_LOG_YET error may be returned multiple times and on multiple pages. In your retry loop, you should add a delay so the database server is not slowed down by too many requests. Continue reading the pages until either of the first two conditions are met.
The dbbackup utility uses the following algorithm. This is not C code, and does not include error checking.
sqlda->sqld = 1; sqlda->sqlvar[0].sqltype = DT_LONGBINARY /* Allocate LONGBINARY value for page buffer. It MUST have */ /* enough room to hold the requested number (128) of database pages */ sqlda->sqlvar[0].sqldata = allocated buffer /* Open the server files needing backup */ for file_num = 0 to DB_BACKUP_MAX_FILE db_backup( ... DB_BACKUP_OPEN_FILE, file_num ... ) if SQLCODE == SQLE_NO_ERROR /* The file exists */ num_pages = SQLCOUNT file_time = SQLE_IO_ESTIMATE open backup file with name from sqlca.sqlerrmc end for /* read pages from the server, write them locally */ while TRUE /* file_no and page_no are ignored */ db_backup( &sqlca, DB_BACKUP_PARALLEL_READ, 0, 0, &sqlda ); if SQLCODE != SQLE_NO_ERROR break; if buffer->stored_len == 0 || sqlda->sqlvar[0].sqlind > 0 break; /* SQLCOUNT contains the starting page number of the block */ /* SQLIOESTIMATE contains the file number the pages belong to */ write block of pages to appropriate backup file end while /* close the server backup files */ for file_num = 0 to DB_BACKUP_MAX_FILE /* close backup file */ db_backup( ... DB_BACKUP_CLOSE_FILE, file_num ... ) end for /* shut down the backup */ db_backup( ... DB_BACKUP_END ... ) /* cleanup */ free page buffer