[SOLVED][SOLUTION] Synapse upgrade from 1.38 to 1.42 failed. Backup restore failed too

:uk:/:us: Message template (english)

Hardware: VPS bought online
YunoHost version: 4.2.8.3
I have access to my server : Through SSH and through the webadmin

Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no

Synapse upgrade error

I was performing an upgrade

yunohost tools upgrade apps

and the upgrade from synapse 1.38 to 1.42 failed

logs are too long, here the warinings:

2021-10-06 23:24:59,177: WARNING - info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
2021-10-06 23:24:59,420: WARNING - info: checking for self-updates
2021-10-06 23:24:59,482: WARNING - info: cleaning up downloads & tmp directories
2021-10-06 23:31:15,318: WARNING - /opt/yunohost/matrix-synapse/lib/python3.7/site-packages/cryptography/hazmat/backends/openssl/x509.py:18: CryptographyDeprecationWarning: This version of cryptography contains a temporary pyOpenSSL fallback path. Upgrade pyOpenSSL now.
2021-10-06 23:31:15,319: WARNING -   utils.DeprecatedIn35,
2021-10-06 23:31:39,945: WARNING - Additionnal URL 'maindomain.tld/.well-known/matrix' already removed in the additional URL for permission 'synapse.server_api'
2021-10-06 23:31:42,366: WARNING - This URL is either unavailable, or conflicts with the already installed app(s):
2021-10-06 23:31:42,366: WARNING -  * maindomain.tld/ โ†’ web-maindomain.tld (my_webapp)
2021-10-06 23:31:42,938: WARNING - [Error] Upgrade failed.
2021-10-06 23:32:24,044: WARNING - 15898 Could not restore synapse: Something unexpected went wrong:
2021-10-06 23:32:24,045: WARNING - Traceback (most recent call last):
2021-10-06 23:32:24,045: WARNING -   File "/usr/lib/moulinette/yunohost/backup.py", line 1452, in _restore_app
2021-10-06 23:32:24,045: WARNING -     sync_perm=False,
2021-10-06 23:32:24,045: WARNING -   File "/usr/lib/moulinette/yunohost/log.py", line 380, in func_wrapper
2021-10-06 23:32:24,045: WARNING -     result = func(*args, **kwargs)
2021-10-06 23:32:24,045: WARNING -   File "/usr/lib/moulinette/yunohost/permission.py", line 465, in permission_create
2021-10-06 23:32:24,045: WARNING -     sync_perm=False,
2021-10-06 23:32:24,045: WARNING -   File "/usr/lib/moulinette/yunohost/log.py", line 380, in func_wrapper
2021-10-06 23:32:24,045: WARNING -     result = func(*args, **kwargs)
2021-10-06 23:32:24,045: WARNING -   File "/usr/lib/moulinette/yunohost/permission.py", line 531, in permission_url
2021-10-06 23:32:24,045: WARNING -     url = _validate_and_sanitize_permission_url(url, app_main_path, app)
2021-10-06 23:32:24,045: WARNING -   File "/usr/lib/moulinette/yunohost/permission.py", line 937, in _validate_and_sanitize_permission_url
2021-10-06 23:32:24,046: WARNING -     _assert_no_conflicting_apps(domain, path, ignore_app=app)
2021-10-06 23:32:24,046: WARNING -   File "/usr/lib/moulinette/yunohost/app.py", line 3126, in _assert_no_conflicting_apps
2021-10-06 23:32:24,046: WARNING -     "app_location_unavailable", apps="\n".join(apps)
2021-10-06 23:32:24,046: WARNING - yunohost.utils.error.YunohostValidationError: This URL is either unavailable, or conflicts with the already installed app(s):
2021-10-06 23:32:24,046: WARNING -  * maindomain.tld/ โ†’ web-maindomain.tld (my_webapp)
2021-10-06 23:32:24,405: WARNING - 16259 Nothing was restored
2021-10-06 23:32:24,467: WARNING - The app was restored to the way it was before the failed upgrade.

Recover from backup failed

I did check the backups

yunohost backup list
archives: 
  - 20210911-170558
  - 20210911-170820
  - etherpad-mypads-pre-upgrade1
  - synapse-pre-upgrade2

tried to recover using the backup restore, failed

yunohost backup restore  synapse-pre-upgrade2
Warning: YunoHost is already installed
Do you really want to restore an already installed system? [y/N]: n
Error: Could not restore system

i did check the backup files that are in my server

ls -lFh /home/yunohost.backup/archives/
total 1.8G
-rw-r--r-- 1 root root   314 Sep 11 19:06 20210911-170558.info.json
-rw-r--r-- 1 root root  618M Sep 11 19:06 20210911-170558.tar
-rw-r--r-- 1 root root   302 Sep 11 19:08 20210911-170820.info.json
-rw-r--r-- 1 root root  1.3M Sep 11 19:08 20210911-170820.tar
-rw-r--r-- 1 root root   351 Oct  6 23:21 etherpad-mypads-pre-upgrade1.info.json
-rw-r--r-- 1 root root  200M Oct  6 23:21 etherpad-mypads-pre-upgrade1.tar
-rw-r--r-- 1 root root   316 Oct  6 23:24 synapse-pre-upgrade2.info.json
-rw-r--r-- 1 root root 1000M Oct  6 23:24 synapse-pre-upgrade2.tar

so I tried the recover with only synapse app but i failed again

yunohost backup restore  synapse-pre-upgrade2 --apps
Info: Preparing archive for restoration...
Info: Restoring synapse...
Error: Could not restore synapse: Something unexpected went wrong: 
Traceback (most recent call last):
  File "/usr/lib/moulinette/yunohost/backup.py", line 1452, in _restore_app
    sync_perm=False,
  File "/usr/lib/moulinette/yunohost/log.py", line 380, in func_wrapper
    result = func(*args, **kwargs)
  File "/usr/lib/moulinette/yunohost/permission.py", line 412, in permission_create
    raise YunohostValidationError("permission_already_exist", permission=permission)
yunohost.utils.error.YunohostValidationError: Permission 'synapse.main' already exists

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 share 20211006-213923-backup_restore_app-synapse' to get help
Error: Nothing was restored

here we have the log https://paste.yunohost.org/raw/ilaliyudun

ended_at: 2021-10-06 21:39:23.680700
error: "Could not restore synapse: Something unexpected went wrong: \nTraceback (most\
  \ recent call last):\n  File \"/usr/lib/moulinette/yunohost/backup.py\", line 1452,\
  \ in _restore_app\n    sync_perm=False,\n  File \"/usr/lib/moulinette/yunohost/log.py\"\
  , line 380, in func_wrapper\n    result = func(*args, **kwargs)\n  File \"/usr/lib/moulinette/yunohost/permission.py\"\
  , line 412, in permission_create\n    raise YunohostValidationError(\"permission_already_exist\"\
  , permission=permission)\nyunohost.utils.error.YunohostValidationError: Permission\
  \ 'synapse.main' already exists\n"
interface: cli
operation: backup_restore_app
parent: null
related_to:
- - app
  - synapse
started_at: 2021-10-06 21:39:23.499916
success: false
yunohost_version: 4.2.8.3

============

2021-10-06 23:39:23,512: INFO - Restoring synapse...
2021-10-06 23:39:23,679: ERROR - Could not restore synapse: Something unexpected went wrong: 
Traceback (most recent call last):
  File "/usr/lib/moulinette/yunohost/backup.py", line 1452, in _restore_app
    sync_perm=False,
  File "/usr/lib/moulinette/yunohost/log.py", line 380, in func_wrapper
    result = func(*args, **kwargs)
  File "/usr/lib/moulinette/yunohost/permission.py", line 412, in permission_create
    raise YunohostValidationError("permission_already_exist", permission=permission)
yunohost.utils.error.YunohostValidationError: Permission 'synapse.main' already exists

thank you in advance for the help

Update: this morning I did:

checked if synapse is installed
with yunohost app list and also with aptitude search synapse and aptitude search matrix and non installation was registered by the debian/yunohost

install synapse again failed
yunohost app install synapse

args:
  app: synapse
  args: null
  force: false
  label: null
  no_remove_on_failure: false
ended_at: 2021-10-07 08:47:11.245004
error: Permission 'synapse.main' already exists
interface: cli
operation: app_install
parent: null
related_to:
- - app
  - synapse
started_at: 2021-10-07 08:47:11.203837
success: false
yunohost_version: 4.2.8.3

============

2021-10-07 10:47:11,212: INFO - Installing synapse...

removed synapse
yunohost app remove synapse

reinstall new synapse failed
yunohost app install synapse

seems it was conflicting with my static webpage hosted under the main domain

2021-10-07 11:01:14,223: WARNING - This URL is either unavailable, or conflicts with the already installed app(s):
2021-10-07 11:01:14,223: WARNING -  * maindomain.tld/ โ†’ web-maindomain.tld (my_webapp)

disable domain conflict

yunohost backup create --apps my_webapp -n my_webapp-backup
yunohost app remove my_webapp

recover synapse backup before upgrade

yunohost backup restore synapse-pre-upgrade2

perform synapse upgrade

yunohost tools update
Info: Fetching available upgrades for system packages...
Info: Updating application catalogโ€ฆ
Success! The application catalog has been updated!
apps: 
  current_version: 1.38.0~ynh1
  id: synapse
  label: synapse/matrix
  new_version: 1.42.0~ynh1
system: 
yunohost tools upgrade apps

success

Success! synapse upgraded
Success! Upgrade complete

recover app creating conflict

yunohost backup restore my_webapp-backup

Hello,

Same problem here:

  • Upgrade failed because of a custom webapp installed on maindomain.
  • Restore failed because of Permission 'synapse.main' already exists
  • So I made a backup of the custom webapp and I removed it
  • But the synapse restore keeps failing because of Permission 'synapse.main' already exists

Synapse is not installed (not listed in yunohost app list)

But a yunohost user permission list shows me:

  synapse.main: 
    allowed: 
  synapse.server_api: 
    allowed: visitors
  synapse.server_client_infos: 
    allowed: 

Is there a way to force the removal of these permissions?

Thanks to @Aleks, here are the commands that allowed me to remove the permissions that were blocking the restoration:

yunohost tools shell -c "from yunohost.permission import permission_delete; permission_delete('synapse.main', force=True)"
yunohost tools shell -c "from yunohost.permission import permission_delete; permission_delete('synapse.server_api', force=True)"
yunohost tools shell -c "from yunohost.permission import permission_delete; permission_delete('synapse.server_client_infos', force=True)"