Save a database image to an external file.
MCO_RET mco_db_save( /*IN*/ void * stream_handle, /*IN*/ mco_stream_write output_stream_writer, /*IN*/ mco_db_h db);
stream_handle | Handle to the output stream |
output_stream_writer |
|
db |
The database handle |
This function is used to stream an eXtremeDB database to permanent storage. Used together with
mco_db_load()
an application can implement robust backup and restore capability.It is the application’s responsibility to open the output stream, in the proper mode to stream binary data, and to ensure that there is adequate space at the destination to hold the database. Indexes are not streamed; they will be rebuilt when the database is reloaded. See the control structure stream writer for further details.
With release 7.1, eXtremeDB has simplified the
mco_db_save()
andmco_db_load()
APIs and the former variantsmco_inmem_save()
,mco_inmem_load()
,mco_disk_save()
,mco_disk_load()
andmco_disk_load_file()
have been deprecated.The simplified version of
mco_db_save()
andmco_db_load()
allow the application to stream database contents to and from a persistent media file, socket, or pipe, withCRC
checking, “binary schema evolution” (BSE
) support and buffering to allow interruption and restart of the streaming process. Database snapshot files are also encrypted ifmco_db_params_t::cipher_key
is specified.
MCO_S_OK | The database was closed successfully |
MCO_E_NOINSTANCE | The specified database is not opened |
MCO_E_WRITE_STREAM | Error writing to output stream |
Application snippet: const char * dbname = "SimpleDb"; /* Stream writer with prototype mco_stream_write */ mco_size_sig_t file_writer( void *stream_handle /* FILE * */, const void *from, mco_size_t nbytes ) { FILE *f = (FILE *)stream_handle; mco_size_sig_t nbs; nbs = fwrite( from, 1, nbytes, f ); return nbs; } int main(int argc, char* argv[]) { mco_db_h db; MCO_RET rc; FILE * fbak; mco_device_t dev; ... if( (rc = mco_runtime_start()) != MCO_S_OK) exit(-1); rc = mco_db_open_dev( dbname, simpledb_get_dictionary(), &dev, 1, &db_params ); if ( MCO_S_OK != rc ) { rc = mco_db_connect(dbname, &db); ... /* Backup database */ fbak = fopen( "backupdb.bak", "wb" ); if ( fbak == 0 ) { printf( "\n\t Can't open output file for streaming\n"); } else { rc = mco_db_save( (void *)fbak, file_writer, db ); fclose( fbak ); sample_rc_check( "\t Save database", rc ); } ... } }