# mco_backup_chunk
RT

> Internal callback function. This function is used internally by the eXtremeDB backup subsystem to write data chunks to a backup file. It is passed as a callback to low-level backup routines and should not be called directly by applications.

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

### Prototype

        MCO_RET mco_backup_chunk(
            /*IN*/ mco_uint4 chunk_id,
            /*IN*/ const char *chunk,
            /*IN*/ mco_uint4 chunk_size,
            /*IN*/ void *param
        );

### Arguments

`chunk_id`
Identifier of the data chunk type (e.g., `MCO_BACKUP_CHUNK_PAGE_MEMORY`, `MCO_BACKUP_CHUNK_DICT`, `MCO_BACKUP_CHUNK_STOP`).
`chunk`
Pointer to the data buffer containing the chunk content. May be `NULL` if `chunk_size` is zero.
`chunk_size`
Size of the data chunk in bytes.
`param`
Opaque pointer to a `mco_backup_ctx_t` context structure, cast to `void*`. This context holds the backup file handle, buffer state, and encryption settings.

### Description

> This internal function appends a single data chunk to the backup stream. It is designed to be used as a callback by the core backup engine (e.g., from `mco_backup()`) during snapshot or incremental backup operations.

> The function:

> - Writes a chunk header containing the `chunk_id` and `size`,
> - Copies the chunk data into an internal buffer,
> - Automatically flushes the buffer to the backup file when it becomes full,
> - Performs a final flush when the `MCO_BACKUP_CHUNK_STOP` marker is received.

> It handles buffer management, I/O buffering, and optional encryption (via the context). Direct use of this function may lead to corrupted backup files.

> Applications should use high-level APIs such as `mco_backup_create()` instead.

> See Incremental Backup and Restore for more details.

### Return Codes

`MCO_S_OK`
Chunk successfully written to the backup buffer (or flushed to file).
Other error codes
May include I/O errors (`MCO_E_DISK_WRITE`), memory allocation failures, or internal system errors during buffer flush.

### Files

Header file:
mco.h
Source file:
mcobackup.c
Library:
libmcobackup.a