---
layout: '../../layouts/index.astro'
title: 'Restoration of Synapse after disappearing 1 year of database history'
description: '?'
keys: 'matrix synapse conduit'
le: '19 Aug. 2025'
---

<div class="article">
## Introduction
In July 2025, my PostgreSQL had broken, so I needed to restore it from my 1-y.o. backup. I was thinking about what to do, and my friend sent me [this](https://blog.erethon.com/blog/2023/06/21/what-happens-when-a-matrix-server-disappears/) article, so we understood what to do!

For example, there is a room called #example:example.org (roomid !example:example.org), whose member was @user:example.net.
The problem is that every server knows @user:example.net is in the room #example:example.org. But our server doesn't! So that is what we should aim at solving the problem.

## Architecture
We get 2 types of error messages:
- `synapse.handlers.receipts: [PUT-...] Ignoring receipt for room '!example:example.org' from server example.org as we're not in the room` (there is the same error message, but when you get a typing event from an unknown room)
- `synapse.federation.federation_server: [PUT-...] Ignoring PDU for unknown room_id: !example:example.org`

We can read the journal and parse the error message (I use a bash script to do that). 
Okay, we have a room id! In the given article, the author is the only user of their server, so they can just send [POST /_matrix/client/v3/join/!example:example.org](https://spec.matrix.org/v1.15/client-server-api/#post_matrixclientv3joinroomidoralias) request, and everything will be good.
But my server has multiple users, so I can't use the easiest way. We need to get information about membership (so we need to get state).

As we are admins of our servers, we have their signing keys.
We will need them because we are going to get state via Federation API requests.
How? There are different ways to do that.
However, all of them require at least 1 event id, so firstly we need to do [GET /_matrix/federation/v1/timestamp_to_event](https://spec.matrix.org/v1.15/server-server-api/#get_matrixfederationv1timestamp_to_eventroomid).
Determining request parameters (?dir as direction (b[ackward] or f[orward]) and &ts as timestamp in Unix time format in milliseconds), we have just got either the last or the first event id! In my case, I chose the way of getting the last event, so then I'll have to make [GET /_matrix/federation/v1/state/!example:example.org?event_id=$event_id](https://spec.matrix.org/v1.15/server-server-api/#get_matrixfederationv1stateroomid), and I will get the actual state.
Of course, both of the requests, as I said, should be signed using your server's key ([how to sign events](https://spec.matrix.org/v1.15/server-server-api/#signing-events)).
<br />
(There is no support of timestamp_to_event in Conduit, so it would be a good idea to make support of requesting different servers)

After we receive the state, we need to parse it, but I think this can't make a difficulty.
As a result, we have a list of our users that were in the given room, like ["@user:example.net", "@anotheruser:example.net", "@exampleuser:example.net"].
Then, the simplest way is to get temporary user's auth token via [POST /_synapse/admin/v1/users/user_id/login](https://github.com/matrix-org/synapse/blob/develop/docs/admin_api/user_admin_api.md#login-as-a-user) and make [POST /_matrix/client/v3/join/!example:example.org](https://spec.matrix.org/v1.15/client-server-api/#post_matrixclientv3joinroomidoralias) from the name of the user using their token.
The problem is solved!

## External links
- [Article that gave me the idea](https://blog.erethon.com/blog/2023/06/21/what-happens-when-a-matrix-server-disappears/)
- [Matrix Federation API docs](https://spec.matrix.org/v1.15/server-server-api/)
  - [How to sign Federation API requests](https://spec.matrix.org/v1.15/server-server-api/#signing-events)
  - [GET /_matrix/federation/v1/state/!example:example.org?event_id=$event_id](https://spec.matrix.org/v1.15/server-server-api/#get_matrixfederationv1stateroomid)
  - [GET /_matrix/federation/v1/timestamp_to_event](https://spec.matrix.org/v1.15/server-server-api/#get_matrixfederationv1timestamp_to_eventroomid)
- [Matrix Client API docs](https://spec.matrix.org/v1.15/server-server-api/)
  - [POST /_matrix/client/v3/join/!example:example.org](https://spec.matrix.org/v1.15/client-server-api/#post_matrixclientv3joinroomidoralias)
- [Admin API POST /_synapse/admin/v1/users/user_id/login](https://github.com/matrix-org/synapse/blob/develop/docs/admin_api/user_admin_api.md#login-as-a-user)
</div>
