# Backup

### 1. Data Persistence Setup

CheckCle uses **PocketBase** as its embedded database. By default, PocketBase stores all application data in the `pb_data` folder inside the container. To prevent data loss when restarting or recreating the container, you should persist this directory on the host machine.

#### Example: Host Volume Mount

In your container configuration:

* **Host Path**: `/mnt/db/pb_data`
* **Container Path**: `/mnt/pb_data`
* **Mode**: `RW` (Read/Write)

This ensures all PocketBase data (SQLite database, uploaded files, migrations, logs) is stored on the host at:

```
/mnt/db/pb_data
```

With this setup, even if the container is removed or recreated, the CheckCle data will persist.

<figure><img src="https://1469101793-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkGNii3LLQCh3Lj3WL2Xg%2Fuploads%2FzspfptrJhSFPBohZKHOA%2Fimage.png?alt=media&#x26;token=1c254e86-f2e7-4397-b522-9fbf54a2c178" alt=""><figcaption></figcaption></figure>

### 2. Backup Strategy for `pb_data`

Since `pb_data` contains the SQLite database and file storage, backing it up regularly is critical. Here are recommended strategies:

#### A. Simple File Copy Backup

Use `rsync` or `cp` to copy the `pb_data` folder to a backup location:

```bash
# Example: backup to /backups/checkcle with timestamp
rsync -avz /mnt/db/pb_data /backups/checkcle/pb_data_$(date +%F_%H-%M-%S)
```

#### B. Compressed Archive Backup

Create a compressed `.tar.gz` archive for portability:

```bash
tar -czvf /backups/checkcle/pb_data_$(date +%F).tar.gz /mnt/db/pb_data
```

#### C. Automated Cron Job

Automate daily backups with `cron`:

```bash
0 2 * * * rsync -avz /mnt/db/pb_data /backups/checkcle/pb_data_$(date +\%F) >> /var/log/checkcle_backup.log 2>&1
```

This runs at **2 AM daily**.

#### D. Remote Backup (Optional)

Push backups to a remote server or cloud (S3, MinIO, rsync to another server):

```bash
rsync -avz /mnt/db/pb_data user@remote-server:/remote/backups/checkcle/
```

***

### 3. Restore Strategy

To restore a backup:

1. Stop the CheckCle (PocketBase) container:

   ```bash
   docker stop checkcle
   ```
2. Replace the `pb_data` directory with your backup:

   ```bash
   rm -rf /mnt/db/pb_data
   cp -r /backups/checkcle/pb_data_2025-09-15 /mnt/db/pb_data
   ```
3. Restart the container:

   ```bash
   docker start checkcle
   ```

### 4. Best Practices

* **Always back up before upgrades** of CheckCle or PocketBase.
* **Test restore procedures** regularly to ensure backups are valid.
* **Use off-site storage** (S3, Minio, or another server) for disaster recovery.
* **Monitor disk space** on the host to prevent backup failures.
