# Restoring servers from backups

Servers die. A disk gives out, an update goes sideways, and suddenly the only thing between you and a very bad day is a backup. Good news: you’ve got them. Here’s how to bring one back.

Honestly, the easiest path is to [contact us](https://etke.cc/contacts/) and let us do the restore. Pulling servers back from the brink is sort of our whole thing. But if you’d rather get your hands dirty, read on: we’ll walk you through it and flag the spots where it bites. And if you’re [on one of our hosting plans](https://etke.cc/services/hosting/), you’re already covered: daily full-server snapshots, kept for 7 days, nothing for you to set up.

## [BorgBackup](https://etke.cc/help/extras/borgbackup/)

If your server has BorgBackup installed, follow these steps to restore a backup:

1. Get the list of all available backups using `/matrix/backup-borg/bin/borgmatic rlist`.
2. List the files in the archive. Usually, you need specific files from the archive, and extracting a full backup may require a lot of disk space. However, if you need to extract the full archive, skip this step. To find a specific file (e.g., Twitter bridge DB dump), use the following command: `/matrix/backup-borg/bin/borgmatic list --archive <ARCHIVE> --find borgmatic/postgresql_databases/matrix-postgres\:5432/` (replace `<ARCHIVE>` with the archive name from the first step). Example: `/matrix/backup-borg/bin/borgmatic list --archive matrix-2025-04-04-021409 --find borgmatic/postgresql_databases/matrix-postgres\:5432/`.
3. Extract the needed files from the archive using the command `/matrix/backup-borg/bin/borgmatic extract --archive <ARCHIVE> --destination /restore --path <LIST OF PATHS>` (replace `<ARCHIVE>` with the archive name from the first step and `<LIST OF PATHS>` with a space-separated list of paths without leading slash. If you want to extract the full archive, omit the `--path` parameter). Example: `/matrix/backup-borg/bin/borgmatic extract --archive matrix-2025-04-04-021409 --destination /restore --path /borgmatic/postgresql_databases/matrix-postgres/matrix_mautrix_twitter`.
4. The extracted files will be in `/matrix/backup-borg/restored` on the host (the `--destination /restore` inside the container maps to this path). Do whatever you need with them, and don’t forget to remove them when you’re done.

## Local Postgres Backups

Enabled by default **only** for on-premises servers without any other backup solution. If you’d like to enable local Postgres backups on your server, please [contact us](https://etke.cc/contacts/).

1. Find a usable backup in `/matrix/postgres-backup/data/last`; it is usually the latest one (e.g., `synapse-latest.sql.gz`).
2. Replace placeholders and run the following script on the server:

```bash
/usr/bin/env docker run --rm --name matrix-postgres-import \
--log-driver=none --user=998:1001 --cap-drop=ALL --network=matrix \
--env-file=/matrix/postgres/env-postgres-psql \
--mount type=bind,src=./DATABASE_DUMP.sql.gz,dst=/dump.sql.gz,ro \
--entrypoint=/bin/sh docker.io/postgres:POSTGRES_VERSION-alpine \
-c "cat /synapse_dump.sql | gunzip -c | grep -vE '^(CREATE|ALTER) ROLE (matrix)(;| WITH)' | grep -vE '^CREATE DATABASE (matrix)\s' | psql -v ON_ERROR_STOP=1 -h matrix-postgres --dbname=DATABASE_NAME"
```

- `DATABASE_DUMP.sql.gz`: file name on the host filesystem you want to import.
- `POSTGRES_VERSION`: Postgres version; you can find the actual version by running `cat /etc/systemd/system/matrix-postgres.service | grep -o "postgres:.*-alpine"`.
- `DATABASE_NAME`: the actual database name (e.g., `synapse` or `postmoogle`). Usually, the backup filename uses the format: `<database_name-timestamp>.sql.gz`.


---
* [llms.txt](https://etke.cc/llms.txt): full site index in markdown
