# Hot backups with Percona XtraBackup

Perform non-locking MySQL backups without interrupting database reads or writes.

Percona XtraBackup copies InnoDB data files at the storage level while the database continues running. Unlike `mysqldump`, it does not acquire a global read lock, making it suitable for production databases where downtime or write delays are not acceptable.

## Prerequisites

Before setting up this backup type, ensure you have:

- Percona XtraBackup installed on the server. See the [Percona documentation](https://www.percona.com/resource/percona-xtrabackup) for installation instructions.
- A `.my.cnf` credentials file readable only by the user running the backup script.
- Sufficient permissions to run `xtrabackup` and connect to MySQL.

## Set up the backup script

1. Create a `.my.cnf` credentials file and restrict its permissions:

```plain
[client]
user=root
password=yourpassword
```

```bash
chmod 600 ~/.my.cnf
```

2. Create a backup script — for example `backup_script.sh`:

```bash
#!/bin/bash

BACKUP_DIR=/mnt/hot-backups
DATABASE=mydatabase
CONFIG=~/.my.cnf

mkdir -p ${BACKUP_DIR}

xtrabackup --backup \
  --defaults-file=${CONFIG} \
  --databases=${DATABASE} \
  --target-dir=${BACKUP_DIR}/${DATABASE}_$(date +%Y%m%d%H%M%S)

exit $?
```

Replace `mydatabase` with your database name. If your `.my.cnf` is stored elsewhere, update the `CONFIG` path accordingly.

3. Make the script executable:

```bash
chmod +x backup_script.sh
```

4. Run the script to verify it completes without errors:

```bash
./backup_script.sh
```

A successful run outputs a timestamped directory under `BACKUP_DIR` containing the backup files. In SimpleBackups, use **Custom Script** as the backup type and point it to this script to automate the process on a schedule.
