# Synapse matix backup recovery error with cryptography

**URL:** https://forum.yunohost.org/t/synapse-matix-backup-recovery-error-with-cryptography/15622
**Category:** Support apps
**Tags:** english
**Created:** [May 4, 2021, 1:55pm UTC](https://forum.yunohost.org/t/synapse-matix-backup-recovery-error-with-cryptography/15622 "2021-05-04T13:55:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jorge](https://forum.yunohost.org/user_avatar/forum.yunohost.org/jorge/32/3293_2.png) [@jorge](https://forum.yunohost.org/u/jorge)
#### Post date: [May 4, 2021, 1:55pm UTC](https://forum.yunohost.org/t/synapse-matix-backup-recovery-error-with-cryptography/15622/1 "2021-05-04T13:55:48Z")

</div>

## 🇬🇧/🇺🇸 Message template (english)

**Hardware:**  
VPS bought online  
**YunoHost version:** 4.1.8  
**I have access to my server :**  
Through SSH | through the webadmin  
**Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?** : no

### Error recovering backup from synapse

after an update/upgrade using `younohost tools update` and `younohost tools upgrade --apps` my matrix/synaptic install stopped.

yo I run on my backupd, I have a daily one of the whole server.  
I did put it online, then performed a backup from synaptic  
`yunohost backup --apps synaptic -n yyyymmdd-matrix-mydomain`  
from three different dates, including the one before the upgrade.

I have a local copy of each backup so I can come back whenever I need.

Every time I try to recover the backup this is what I obtain, the same `cryptography` error

```plaintext
#yunohost backup restore 20210428-matrix-vitrubio
Info: Preparing archive for restoration...
Info: Restoring synapse...
Info: [....................] > Loading settings...
Info: [....................] > Validating restoration parameters...
Info: [+++++++.............] > Reinstalling dependencies...
Warning: I: Creating /var/lib/turn/turndb from /usr/share/doc/coturn/schema.sql
Info: [#######+............] > Restoring directory and configuration...
Info: [########+...........] > Check for source up to date...
Warning: Failed building wheel for cryptography
Warning: Failed cleaning build dir for cryptography
Warning: Command "/opt/yunohost/matrix-synapse/bin/python3 -u -c "import setuptools, tokenize; __file__ ='/tmp/pip-install-0r76s_ip/cryptography/setup.py';f=getattr(tokenize, 'open', open)( __file__ );code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__ , 'exec'))" install --record /tmp/pip-record-0z4ht01o/install-record.txt --single-version-externally-managed --compile --install-headers /opt/yunohost/matrix-synapse/include/site/python3.7/cryptography" failed with error code 1 in /tmp/pip-install-0r76s_ip/cryptography/
Error: Could not restore synapse
Info: The operation 'Restore 'synapse' from a backup archive' could not be completed. Please share the full log of this operation using the command 'yunohost log display 20210504-133720-backup_restore_app-synapse --share' to get help
Warning: Here's an extract of the logs before the crash. It might help debugging the error:
Info: DEBUG - set the environment variable `CRYPTOGRAPHY_DONT_BUILD_RUST=1`.
Info: DEBUG - =============================DEBUG ASSISTANCE=============================
Info: DEBUG -
Info: DEBUG - error: can't find Rust compiler
Info: DEBUG -
Info: DEBUG - If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.
Info: DEBUG -
Info: DEBUG - To update pip, run:
Info: DEBUG -
Info: DEBUG - pip install --upgrade pip
Info: DEBUG -
Info: DEBUG - and then retry package installation.
Info: DEBUG -
Info: DEBUG - If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
Info: DEBUG -
Info: DEBUG - This package requires Rust >=1.41.0.
Info: DEBUG -
Info: DEBUG - ----------------------------------------
Info: DEBUG - Rolling back uninstall of cryptography
Info: WARNING - Command "/opt/yunohost/matrix-synapse/bin/python3 -u -c "import setuptools, tokenize; __file__ ='/tmp/pip-install-0r76s_ip/cryptography/setup.py';f=getattr(tokenize, 'open', open)( __file__ );code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__ , 'exec'))" install --record /tmp/pip-record-0z4ht01o/install-record.txt --single-version-externally-managed --compile --install-headers /opt/yunohost/matrix-synapse/include/site/python3.7/cryptography" failed with error code 1 in /tmp/pip-install-0r76s_ip/cryptography/
Info: DEBUG - + ynh_exit_properly
Info: [+...................] > Loading installation settings...
Info: [#+..................] > Stopping and removing the systemd service
Warning: Database matrix_synapse not found
Info: [##+.................] > Removing the PostgreSQL database
Warning: User matrix_synapse not found
Info: [###++++++++.........] > Removing dependencies
Warning: Traceback (most recent call last):
Warning: File "../conf/remove_sso_conf.py", line 10, in <module>
Warning: data["skipped_urls"].remove(domain + "/_matrix")
Warning: KeyError: 'skipped_urls'
Info: [###########+........] > Removing app main directory
Info: [############+.......] > Removing nginx web server configuration
Info: [#############+......] > Removing logrotate configuration
Info: [##############++++..] > Removing fail2ban configuration...
Warning: The user matrix-synapse was not found
Info: [##################..] > Removing the dedicated system user
Info: Due of the backup core only feature the data directory in '/home/yunohost.app/matrix-synapse' was not removed. It need to be removed manually to purge app user data.
Info: [####################] > Removal of synapse completed
Error: Nothing was restored

```

here you have the full pastebin  
[https://paste.yunohost.org/raw/alevonupam](https://paste.yunohost.org/raw/alevonupam)

I am able to do a fresh install of synapse/matrix but then, I have no clue how to get back on my previous account with the conversations, chats and most important, verified sessions.

## thanks in advance

## 🇫🇷 Modèle de message (français)

---

<div class="post-metadata">

### Author: ![SiM](https://forum.yunohost.org/user_avatar/forum.yunohost.org/sim/32/328_2.png) [@SiM](https://forum.yunohost.org/u/SiM)
#### Post date: [May 4, 2021, 9:46pm UTC](https://forum.yunohost.org/t/synapse-matix-backup-recovery-error-with-cryptography/15622/2 "2021-05-04T21:46:19Z")

</div>

Hi,

It’s looks like the error i had.  
I described a workaround to be able to restore the backup here:

> <https://github.com/YunoHost-Apps/synapse_ynh/issues/259>
>
> Hi,
> 
> \## Upgrade error
> I tried to upgrade synapse from 1.23.1 to 1.31.0.
> Upgr…ade fails on configuring permissions.
> Complete log here: https://paste.yunohost.org/raw/asetarulip and permission\_create-synapse log here: https://paste.yunohost.org/raw/eqiqofehum
> My synapse homeserver is installed on \_matrix.domain.net\_ and matrix usernames are configured to be \_@user:domain.net\_.
> A custom webapp is installed on \_domain.net\_, which seems to trigger the error.
> 
> \## Restore error
> As you can see on complete log posted above, the restore fails on building wheel for cryptography.
> 
> By adding \`CRYPTOGRAPHY\_DONT\_BUILD\_RUST=1\` (as explained here: https://github.com/YunoHost-Apps/synapse\_ynh/issues/236#issuecomment-776261101) I don't have the error anymore, but another one appears (log here: https://paste.yunohost.org/raw/uqihanumuq)
> As it looks like this \[error\](https://github.com/YunoHost-Apps/synapse\_ynh/issues/246), I followed the described workaround (https://github.com/YunoHost-Apps/synapse\_ynh/issues/246#issuecomment-810259884), and I finally managed to restore my backup :sweat\_smile: 
> 
> \---
> 
> 
> \`\`\`
> yunohost --version
> yunohost: 
> repo: stable
> version: 4.1.8
> yunohost-admin: 
> repo: stable
> version: 4.1.4
> moulinette: 
> repo: stable
> version: 4.1.4
> ssowat: 
> repo: stable
> version: 4.1.3
> 
> \`\`\`

---

<div class="post-metadata">

### Author: ![jorge](https://forum.yunohost.org/user_avatar/forum.yunohost.org/jorge/32/3293_2.png) [@jorge](https://forum.yunohost.org/u/jorge)
#### Post date: [May 5, 2021, 9:27am UTC](https://forum.yunohost.org/t/synapse-matix-backup-recovery-error-with-cryptography/15622/3 "2021-05-05T09:27:43Z")

</div>

Hello and thanks for the tip.

I hadn’t see the first one you comment out

> <https://github.com/YunoHost-Apps/synapse_ynh/issues/236#issuecomment-776261101>
>
> Hi,
> I istalled a new VM with Debian 10 and tried to installed Synapse. But It f…ails on every try i already tried the tips from the Log:
> \`\`\`
> 2021-02-08 21:41:14,053: DEBUG - =============================DEBUG ASSISTANCE=============================
> 2021-02-08 21:41:14,054: DEBUG - If you are seeing a compilation error please try the following steps to
> 2021-02-08 21:41:14,054: DEBUG - successfully install cryptography:
> 2021-02-08 21:41:14,055: DEBUG - 1) Upgrade to the latest pip and try again. This will fix errors for most
> 2021-02-08 21:41:14,055: DEBUG - users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
> 2021-02-08 21:41:14,055: DEBUG - 2) Read https://cryptography.io/en/latest/installation.html for specific
> 2021-02-08 21:41:14,056: DEBUG - instructions for your platform.
> 2021-02-08 21:41:14,056: DEBUG - 3) Check our frequently asked questions for more information:
> 2021-02-08 21:41:14,057: DEBUG - https://cryptography.io/en/latest/faq.html
> 2021-02-08 21:41:14,057: DEBUG - 4) Ensure you have a recent Rust toolchain installed:
> 2021-02-08 21:41:14,058: DEBUG - https://cryptography.io/en/latest/installation.html#rust
> 2021-02-08 21:41:14,058: DEBUG - 5) If you are experiencing issues with Rust for \*this release only\* you may
> 2021-02-08 21:41:14,058: DEBUG - set the environment variable \`CRYPTOGRAPHY\_DONT\_BUILD\_RUST=1\`.
> 2021-02-08 21:41:14,058: DEBUG - =============================DEBUG ASSISTANCE=============================
> \`\`\`
> 
> But is still fails to install with:
> 
> \`\`\`
> 021-02-08 21:41:14,058: DEBUG - 
> 2021-02-08 21:41:14,059: DEBUG - error: Can not find Rust compiler
> 2021-02-08 21:41:14,059: DEBUG - 
> 2021-02-08 21:41:14,059: DEBUG - ----------------------------------------
> 2021-02-08 21:41:14,059: DEBUG - Running setup.py clean for cryptography
> 2021-02-08 21:41:15,300: DEBUG - Failed to build cryptography
> \`\`\`
> \`\`\`
> Command "/opt/yunohost/matrix-synapse/bin/python3 -u -c "import setuptools, tokenize;\_\_file\_\_='/tmp/pip-install-rnhggt33/cryptography/setup.py';f=getattr(tokenize, 'open', open)(\_\_file\_\_);code=f.read().replace('\\r\\n', '\\n');f.close();exec(compile(code, \_\_file\_\_, 'exec'))" install --record /tmp/pip-record-yc9gffo3/install-record.txt --single-version-externally-managed --compile --install-headers /opt/yunohost/matrix-synapse/include/site/python3.7/cryptography" failed with error code 1 in /tmp/pip-install-rnhggt33/cryptography/
> 
> Failed building wheel for cryptography
> \`\`\`
> System Details:
> VPS 
> 4core
> 8GB ram 
> 200GB SSD
> 
> Has anybody an idea why? 
> 
> If you need more information let me know I will provide it.
> Greetings
> baensch

I had already check this one but didn’t work by it self.

> <https://github.com/YunoHost-Apps/synapse_ynh/issues/246#issuecomment-810259884>
>
> When I tried to upgrade Matrix Synapse, I got an error due to Twisted:
> \`\`\`log
> …2021-03-30 12:45:39,795: DEBUG - mars 30 12:45:39 systemd\[1\]: Failed to start Synapse Matrix homeserver.'
> 2021-03-30 12:45:39,796: DEBUG - mars 30 12:45:39 python\[31125\]: from synapse.federation.transport.server import TransportLayerServer
> 2021-03-30 12:45:39,796: DEBUG - mars 30 12:45:39 python\[31125\]: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/synapse/federation/transport/server.py", line 46, in \<module\>
> 2021-03-30 12:45:39,796: DEBUG - mars 30 12:45:39 python\[31125\]: from synapse.server import HomeServer
> 2021-03-30 12:45:39,796: DEBUG - mars 30 12:45:39 python\[31125\]: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/synapse/server.py", line 48, in \<module\>
> 2021-03-30 12:45:39,796: DEBUG - mars 30 12:45:39 python\[31125\]: from synapse.appservice.api import ApplicationServiceApi
> 2021-03-30 12:45:39,797: DEBUG - mars 30 12:45:39 python\[31125\]: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/synapse/appservice/api.py", line 25, in \<module\>
> 2021-03-30 12:45:39,797: DEBUG - mars 30 12:45:39 python\[31125\]: from synapse.http.client import SimpleHttpClient
> 2021-03-30 12:45:39,797: DEBUG - mars 30 12:45:39 python\[31125\]: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/synapse/http/client.py", line 33, in \<module\>
> 2021-03-30 12:45:39,797: DEBUG - mars 30 12:45:39 python\[31125\]: import treq
> 2021-03-30 12:45:39,797: DEBUG - mars 30 12:45:39 python\[31125\]: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/treq/\_\_init\_\_.py", line 5, in \<module\>
> 2021-03-30 12:45:39,797: DEBUG - mars 30 12:45:39 python\[31125\]: from treq.api import head, get, post, put, patch, delete, request
> 2021-03-30 12:45:39,797: DEBUG - mars 30 12:45:39 python\[31125\]: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/treq/api.py", line 5, in \<module\>
> 2021-03-30 12:45:39,798: DEBUG - mars 30 12:45:39 python\[31125\]: from treq.client import HTTPClient
> 2021-03-30 12:45:39,798: DEBUG - mars 30 12:45:39 python\[31125\]: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/treq/client.py", line 11, in \<module\>
> 2021-03-30 12:45:39,798: DEBUG - mars 30 12:45:39 python\[31125\]: from twisted.python.compat import \_PY3, unicode
> 2021-03-30 12:45:39,798: DEBUG - mars 30 12:45:39 python\[31125\]: ImportError: cannot import name '\\''\_PY3'\\'' from '\\''twisted.python.compat'\\'' (unknown location)
> \`\`\`
> 
> Restoration also failed. I had to extract the backup, change the \_common.sh function and then restore (as root):
> \`\`\`bash
> $ mkdir /tmp/synapse-backup
> $ cd /tmp/synapse-backup
> $ tar xf /home/yunohost.backup/archives/my-synapse-backup.tar
> $ vim ./apps/synapse/settings/scripts/\_common.sh
> \<Change the file as described below\>
> $ tar cf /home/yunohost.backup/archives/new-synapse-backup.tar
> $ yunohost backup restore new-synapse-backup --apps
> \`\`\`
> 
> The patch to apply: https://github.com/YunoHost-Apps/synapse\_ynh/pull/247/commits/33f6dc3efbd834e2d5ec9cf0cc67119593697a30
> The logs: https://paste.yunohost.org/raw/elelixiluk
> 
> Thanks!

then I kept reading on and found

> <https://github.com/YunoHost-Apps/synapse_ynh/issues/244#issuecomment-809747238>
>
> The issue raised in #236 found a solution in #238. However, it uses rustup, whic…h will installed a non-maintained version of the Rust compiler.
> 
> As mention in https://cryptography.io/en/latest/installation.html#rust the minimal required version is 1.41 and Debian stable \[offers 1.41.1\](https://tracker.debian.org/pkg/rustc).
> 
> I see however that it \*might\* be resolved by only upgrading pip in #240, which could be a better solution than installing a compiler, obviously. But if this solution failed, I would much prefer relying on my distribution packages installed globally, and having security fixes on them.

## SOLUTION

so the backup was recovered by installing `rust` from debian

`apt install rustc cargo`

after that just run the backup restore

`yunohost backup restore NAME-OF-YOUR-BACKUP`

---

<div class="post-metadata">

### Author: ![system](https://forum.yunohost.org/uploads/default/original/2X/f/f59fe8e3ee6b100b4f574d30d6e30479c68b89f0.png) [@system](https://forum.yunohost.org/u/system)
#### Post date: [May 20, 2021, 9:28am UTC](https://forum.yunohost.org/t/synapse-matix-backup-recovery-error-with-cryptography/15622/4 "2021-05-20T09:28:30Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
