# Incremental Backup and Restore with xSQL

> The following xSQL commands are provided to perform incremental backup and restore operations on in-memory and persistent databases. (Also note that file backup can be performed for persistent databases by calling SQL function `file_backup()`.)

> Note: backup_map_size should be defined in `db_params` and set to a power of two.

> ## BACKUP

>         XSQL>backup [TO] file_name [FULL|INCREMENTAL|AUTO] [[AS] label]
>             [WITH CIPHER=key [',' COMPRESSION=level ]];

> The `file_name` argument is required; the other parameters are optional.

> Note that it is quite possible to perform a continuous backup in a loop. For example, using bash:

>         !/bin/bash
>         While true; do
>             xsql ... "BACKUP ..."
>         done

> ## RESTORE a backup

> The `restore` command is used to restore the current database from a given backup file. If it is necessary to restore a database from several consecutive backups, it has to be done by calling the `restore` several times in the chronological order:

>         XSQL>restore [FROM] file_name [[TO] label] [WITH CIPHER=key];

> ## List the backup contents

> To list the content of a backup file use the SQL function `backup <backup-file>` to print out the backup labels and some generic backup information to the console:

>         XSQL>select * from backup <backup-file>;