Hardware: VPS bought online YunoHost version: 220.127.116.11 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
Description of my issue
I attempted to perform an update of matrix-synapse, and the update failed. Now I just want to restore the backup, but I am seeing this error. There is another recent post with a very similar error but the solution there did not help me. Also, it appeared that modifying the backup tar file was making the paired json file invalid, not sure the correct way to go about that.
Error: Could not restore synapse: An error occured inside the app restore script
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 20221231-00
4718-backup_restore_app-synapse' to get help
Warning: Here's an extract of the logs before the crash. It might help debugging the error:
Info: WARNING - Dec 30 16:48:02 python: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/synapse/logging/__init__.py", line 17, in <module>
Info: WARNING - Dec 30 16:48:02 python: from synapse.logging._remote import RemoteHandler
Info: WARNING - Dec 30 16:48:02 python: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/synapse/logging/_remote.py", line 29, in <module>
Info: WARNING - Dec 30 16:48:02 python: from twisted.internet.endpoints import (
Info: WARNING - Dec 30 16:48:02 python: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/twisted/internet/endpoints.py", line 63, in <module>
Info: WARNING - Dec 30 16:48:02 python: from twisted.python.systemd import ListenFDs
Info: WARNING - Dec 30 16:48:02 python: File "/opt/yunohost/matrix-synapse/lib/python3.7/site-packages/twisted/python/systemd.py", line 18, in <module>
Info: WARNING - Dec 30 16:48:02 python: from attrs import Factory, define
Info: WARNING - Dec 30 16:48:02 python: ModuleNotFoundError: No module named 'attrs'
Info: WARNING - Dec 30 16:48:02 systemd: matrix-synapse.service: Control process exited, code=exited, status=1/FAILURE
Info: WARNING - Dec 30 16:48:02 systemd: matrix-synapse.service: Failed with result 'exit-code'.
Info: WARNING - Dec 30 16:48:02 systemd: Failed to start Synapse Matrix homeserver.
Promising results when deleting part of the backup: sudo tar --delete --file synapse-pre-upgrade2.tar apps/synapse/backup/opt/yunohost/matrix-synapse/lib/python3.9/site-packages/attrs-20.3.0.dist-info/
However, when I modify my synapse-pre-upgrade2.tar file, it invalidates the synapse-pre-upgrade2.info.json file, and I get an error like:
admin@XXX:archives$ sudo yunohost backup restore synapse-pre-upgrade2 --app
Info: Preparing archive for restoration...
Error: Could not load infos for archive '/home/yunohost.backup/archives/synapse-pre-upgrade2.tar'... The info.json cannot be retrieved (or is not a valid json).
Does anyone know the proper way to update the .json file after modifying the .tar file?
Ok, I fixed my problem and was able to restore my synapse successfully. Likely for someone with a similar problem to mine, they may have a slightly different set of broken libraries, but the process is the same. Any exceptions due to failure to load libraries due to import issues, can be fixed by deleting the offending library from the tar file, installing it locally, then copying the locally installed library into the tar package. May have to do this a few times until there are no more library exceptions during the restore. Below commands summarize it:
After logging in through ssh as the admin user:
# locally install libraries that had errors (goes to /home/admin/.local/lib/python3/site-packages)
pip install -U attr attrs cryptography pyopenssl
# create a temp working directory
# extract the restore file
tar xvf /home/yunohost.backup/archives/synapse-pre-upgrade2.tar
# become root for the next few steps since files in the extracted tar are not all accessible by `admin` user
# remove offending libraries from extracted tar
rm -rf attr attr.py attr-* attrs* cryptography* OpenSSL pyOpenSSL*
# copy over the local libraries, replacing the ones that were removed
cp -r /home/admin/.local/lib/python3.7/site-packages/attr .
cp -r /home/admin/.local/lib/python3.7/site-packages/attr.py .
cp -r /home/admin/.local/lib/python3.7/site-packages/attr-* .
cp -r /home/admin/.local/lib/python3.7/site-packages/attrs* .
cp -r /home/admin/.local/lib/python3.7/site-packages/cryptography* .
cp -r /home/admin/.local/lib/python3.7/site-packages/OpenSSL .
cp -r /home/admin/.local/lib/python3.7/site-packages/pyOpenSSL* .
# make sure ownership of freshly copied files matches ownership of other files in the directory
chown -R admin:1007 attr attr.py attr-* attrs* cryptography* OpenSSL pyOpenSSL*
# leave `root` user and return to `admin` user. Should be back in the /home/admin/tmp folder
# save off the original restore file as a backup
mv /home/yunohost.backup/archive/synapse-pre-upgrade2.tar /home/yunohost.backup/archive/synapse-pre-upgrade2.tar-orig
# tar the files from the `tmp` folder into a new restore tar file with the same name and path as the original. The `--transform` argument makes sure the paths inside the tar file are like what was in the original
tar --transform 's|^\./||' -cvf /home/yunohost.backup/archive/synapse-pre-upgrade2.tar .
# finally, re-attempt the restore operation
sudo yunohost backup restore synapse-pre-upgrade2 --apps