# mco_backup

> Internal function. This is a low-level runtime routine used by `mco_backup_create()` to perform database backup operations.

### For an overview see page Incremental Online Backup in C

### Prototype

        MCO_RET mco_backup(
            /*IN*/ mco_db_h connection,
            /*IN*/ const char *label,
            /*IN*/ mco_backup_type backup_type,
            /*IN*/ mco_backup_info_proc_t proc_info,
            /*IN*/ mco_backup_chunk_proc_t proc_chunk,
            /*IN*/ void *proc_arg
        );

### Arguments

`connection`
Valid database connection handle.
`label`
Label to associate with this backup record (must not exceed `MCO_MAX_BACKUP_LABEL_SIZE`).
`backup_type`
Type of backup to perform: `MCO_BACKUP_TYPE_SNAPSHOT`, `MCO_BACKUP_TYPE_INCREMENTAL`, or `MCO_BACKUP_TYPE_AUTO`.
`proc_info`
Callback function to receive backup metadata (e.g., header information). Must not be `NULL`.
`proc_chunk`
Callback function to receive data chunks during backup. Must not be `NULL`.
`proc_arg`
Opaque pointer passed to both callback functions for context.

### Description

> This internal function implements the core logic for creating snapshot and incremental backups of an eXtremeDB database. It is invoked by the public API function `mco_backup_create()` and should not be called directly by applications.

> The function performs the following steps:

> - Validates that incremental backup is enabled in the database configuration,
> - Determines the appropriate backup type based on existing backup history,
> - Iteratively scans memory and disk pages, collecting modified data since the last mark,
> - Invokes `proc_info` to report backup metadata,
> - Invokes `proc_chunk` repeatedly to deliver data chunks (pages, dictionary, indexes, transaction logs, etc.).

> Backup progress can be monitored via the database’s backup context structure. The function supports both full (snapshot) and differential (incremental) backup modes.

> See Incremental Backup and Restore in C for usage examples.

### Return Codes

`MCO_S_OK`
Backup completed successfully.
`MCO_E_ILLEGAL_PARAM`
Invalid argument (e.g., `NULL` connection, missing callbacks).
`MCO_E_BACKUP_INVALID_PARAM`
Incremental backup is not enabled in the database configuration (`MCO_DB_INCREMENTAL_BACKUP_ENABLED` flag missing).
`MCO_E_BACKUP_SNAPSHOT_ONLY`
An incremental backup was requested, but no initial snapshot exists yet.
Other error codes
May include I/O errors, memory allocation failures, or internal system errors.

### Files

Header file:
mco.h
Source file:
mcoabst.c
Library:
libmcolib.a