> For the complete documentation index, see [llms.txt](https://docs.hivel.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hivel.ai/self-managed-hivel-deployment/on-premises-generic/hivel-on-premises-deployment-guide-generic/backup-and-restore.md).

# Backup and Restore

#### What Must Be Backed Up

The PostgreSQL `insightly` database contains all Hivel data. There is no separate object store to back up in the self-hosted deployment. The database is the complete backup target.

## Backup Strategy

**Recommended frequency:** Daily\
**Recommended retention:** 7 days of dumps

Adjust this cadence to match your compliance or operational requirements.

**Live-backup safety:** `pg_dump` takes a transactionally consistent snapshot at the moment it starts. It is safe to run against the live database without stopping services or pausing integration polling.

**Recommended backup command:**

```bash
pg_dump -h $DB_HOST -U postgres -d insightly -F c -f /backups/insightly_$(date +%Y-%m-%d).dump
```

Set this as a daily cron job to automate backups.

## Restore from Backup

When you need to restore from a backup:

### **Step 1: Stop Services**

On the host, run:

```bash
./deploy.sh --stop
```

### **Step 2: Restore the Database**

On the host, run:

```bash
pg_restore -h $DB_HOST -U postgres -d insightly -c /backups/insightly_<date>.dump
```

Replace `<date>` with the backup date.

### **Step 3: Repoint `.env` and Restart Services (if needed)**

If the restored database now lives on a different host or uses different credentials, update `.env`:

```bash
nano config/.env
```

Update `DB_HOST` and/or `DB_PASSWORD` as needed.

Then restart services:

* If you changed `.env` values: `./deploy.sh --vm`
* If you did not change `.env`: `./deploy.sh --start`

### **Step 4: Re-evaluate Permissions**

Once services are back up, run the following against your deployment's API base URL. This re-evaluates permissions so anything derived from the restored data (roles, access grants) is consistent with the restored state.

**Application/Location:** Run from any machine with network access to Hivel API

```bash
curl --location --request DELETE '<base-url>/hivelapi/v1/permissions/reevaluate?orgId=1'
```

Replace `<base-url>` with your deployment's actual API base URL.

### **Step 5: Validate the Restore**

**Application/Location:** Host (via SSH)

Complete the validation checklist from [Verification and Access](https://docs.hivel.ai/self-managed-hivel-deployment/on-premises/verification-and-access).<br>

{% columns %}
{% column %} <a href="/self-managed-hivel-deployment/on-premises-generic/hivel-on-premises-deployment-guide-generic/troubleshooting.md" class="button primary" data-icon="backward">Back to Troubleshooting</a>
{% endcolumn %}

{% column %}

{% endcolumn %}

{% column %} <a href="/self-managed-hivel-deployment/on-premises-generic/hivel-on-premises-deployment-guide-generic/upgrade-and-rollback.md" class="button primary" data-icon="forward">Upgrade and Rollback</a>
{% endcolumn %}
{% endcolumns %}
