Incremental online backup can be performed while normal database activity proceeds uninterrupted using the C++ McoSqlEngine methods described below. Alternatively, C++ applications can call the C API functions described in the Incremental Backup and Restore in C page.
The McoSqlEngine methods
backupCreate()andbackupRestore()perform incremental backup and restore operations; andbackupInfo()can be called to list the contents of a backup file. (Also note that file backup can be performed for persistent databases by calling methodfileBackup().)BACKUP
The
backupCreate()method call must specify theBackupKindas one of the following:
Snapshot, which creates a backup record for the entire database,Incremental(partial), which records only the database modifications since the previous backup, orAutowhich creates aSnapshotorIncrementalbackup record depending on the content of the backup file: If there is no snapshot in the file yet the backup process will create one; otherwise a partial backup record is created.The statement and can also specify an optional
label. For example:{ MCO_RET rc; mco_device_t dev[4]; McoSqlEngine engine; McoSqlOpenParameters params; char * backup_file = "SimpleDb_backup.dbs"; char label[MAX_LABEL_SIZE]; int duration_msec = 1000; int msec; ... do { rc = engine.open(params); if ( MCO_S_OK == rc ) { msec = (int)MCO_SYSTEM_GET_CURRENT_TIME_MSEC(); sprintf(label, "Backup at %d msec", msec); /* backup the database */ rc = engine.backupCreate( backup_file, label, Auto, 0, NULL); sleep_msec(duration_msec); engine.close(); } } while (rc == MCO_S_OK && !stop); ... } void backupRestore(McoSql::String* file, McoSql::String* label, McoSql::String* cipherKey); void backupInfo(McoSql::String* file, McoSql::SyntheticTable* backupInfo, McoSql::Allocator* allocator);Note that a
Snapshotbackup must be done at least once before anIncrementalbackup can be done successfully.RESTORE a backup
To restore the database the
backupRestore()method specifies the backup file and an optional label (to restore the database contents up to that label only). For example:{ MCO_RET rc; mco_device_t dev[4]; McoSqlEngine engine; McoSqlOpenParameters params; char * backup_file = "SimpleDb_backup.dbs"; char * label = ""; ... rc = engine.open(params); if ( MCO_S_OK == rc ) { rc = engine.backupRestore( backup_file, label, NULL); engine.close(); } ... }List the backup contents
The
backupInfo()method can be used to list the contents of a backup file. For example:{ MCO_RET rc; mco_device_t dev[4]; McoSqlEngine engine; McoSqlOpenParameters params; char * backup_file = "SimpleDb_backup.dbs"; SyntheticTable * table = SyntheticTable(); Allocator * allocator = Allocator(); ... rc = engine.open(params); if ( MCO_S_OK == rc ) { rc = engine.backupInfo( backup_file, table, allocator); engine.close(); } ... }