# mco_backup_restore
RT

> Restore backup records starting from the latest snapshot record in the specified file up to the specified label.

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

### Prototype

        void mco_backup_restore(
            /*IN*/  mco_db_h con,
            /*IN*/  const char *file_name,
            /*IN*/  const char *label,
            /*IN*/  const char *cipher,
            /*IN*/  char *err_buf,
            /*IN-OUT*/ unsigned int *err_buf_sz
        );

### Arguments

`con`
Database connection handle for the target database to restore into.
`file_name`
Name of the backup file to use for restoration.
`label`
Label of the backup point to restore.
`cipher`
Optional decryption key if the backup is encrypted. May be `NULL` for unencrypted backups.
`err_buf`
Buffer for error message (may be `NULL` if error details are not needed).
`err_buf_sz`
On input: size of `err_buf`. On output: number of characters written. If `NULL`, the function returns `MCO_E_ILLEGAL_PARAM`.

### Description

> This function restores a database to the state corresponding to the specified `label` by applying the latest snapshot and all subsequent incremental backup records up to that label.

> The target database must have identical properties (e.g., page size, memory layout) as the original database that was backed up. Restoration into a database with different configuration is not supported.

> See Incremental Backup and Restore for more details.

### Return Codes

`MCO_S_OK`
Database successfully restored to the specified label.
`MCO_E_DISK_OPEN`
Failed to open the backup file.
`MCO_E_ILLEGAL_PARAM`
One of the following occurred:

- Incremental backup records in the file are out of order,
- The specified `label` was not found,
- A cipher key is required but not provided.

`MCO_E_DISK_SEEK`
Failed to seek to the required position in the backup file (possible file corruption).

### Example

        {
            mco_db_h con;
            MCO_RET rc;
            const char *filename = "backup.bak";
            const char *label = "v1.2";

            rc = mco_db_connect("mydb", &con);
            if (rc != MCO_S_OK) {
                /* handle connection error */
            }

            rc = mco_backup_restore(con, filename, label, NULL, NULL);
            if (rc != MCO_S_OK) {
                /* handle restore error */
            }
        }

### Files

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