Restore from folder rather then tar.gz

Hi

Synapse gave me an error while upgrade and further the restore script gave error to while upgrade. So I lost synapse all together.
To restore the app from the backup archive, I need to extract the backup tar.gz from the archive fix the error in the restore and run the restore manually.

But when I create the synapse.tar.gz from this command $ tar czf synapse.tar.gz synapse/* and run $ yunohost backup restore synapse --debug . I got this error:

310  DEBUG loading actions map namespace 'yunohost'
331  DEBUG extra parameter classes loaded: ['comment', 'ask', 'password', 'required', 'pattern']
331  DEBUG initializing base actions map parser for cli
332  DEBUG registering new callback action 'yunohost.utils.packages.ynh_packages_version' to ['-v', '--version']
409  DEBUG initialize authenticator 'ldap-anonymous' with: uri='ldap://localhost:389', base_dn='dc=yunohost,dc=org', user_rdn='None'
416  DEBUG lock has been acquired
493  DEBUG loading python module yunohost.backup took 0.077s
494  INFO processing action [20312.1]: yunohost.backup.restore with args={'force': False, 'name': 'synapse', 'apps': None, 'system': None, 'auth': <moulinette.authenticators.ldap.Authenticator object at 0x7f00aac2b050>}
494  WARNING YunoHost is already installed
Do you really want to restore an already installed system? [y/N]: Y
12866 DEBUG unable to retrieve '/home/yunohost.backup/archives/synapse.info.json' inside the archive
Traceback (most recent call last):
  File "/usr/lib/moulinette/yunohost/backup.py", line 2233, in backup_info
    tar.extract('info.json', path=info_dir)
  File "/usr/lib/python2.7/tarfile.py", line 2109, in extract
    tarinfo = self.getmember(member)
  File "/usr/lib/python2.7/tarfile.py", line 1829, in getmember
    raise KeyError("filename %r not found" % name)
KeyError: "filename 'info.json' not found"
12868 DEBUG action [20312.1] executed in 12.375s
12868 DEBUG lock has been released
12869 ERROR Invalid backup archive

info.json is present in your folder ?

Yes its present. These files are present apps backup.csv info.json

I think whe you tar again the content you tar the directory and not the content of the directory.

info.json need to be at the root of the archive

Can you tell the command for the tar only the content of the folder in /home/yunohost.backup/archive/synapse to synapse.tar.gz ?

cd /home/yunohost.backup/archive/synapse/ 
tar -zcvf ../synapse.tar.gz .

@ljf
I tried as you suggested but its still failing. What I am doing wrong?

$ yunohost backup   restore   synapse  --debug 
193  DEBUG loading actions map namespace 'yunohost'
217  DEBUG extra parameter classes loaded: ['comment', 'ask', 'password', 'required', 'pattern']
217  DEBUG initializing base actions map parser for cli
219  DEBUG registering new callback action 'yunohost.utils.packages.ynh_packages_version' to ['-v', '--version']
319  DEBUG initialize authenticator 'ldap-anonymous' with: uri='ldap://localhost:389', base_dn='dc=yunohost,dc=org', user_rdn='None'
323  DEBUG lock has been acquired
468  DEBUG loading python module yunohost.backup took 0.144s
468  INFO processing action [31673.1]: yunohost.backup.restore with args={'force': False, 'name': 'synapse', 'apps': None, 'system': None, 'auth': <moulinette.authenticators.ldap.Authenticator object at 0x7f9f62cff050>}
468  WARNING YunoHost is already installed
Do you really want to restore an already installed system? [y/N]: Y
13792 DEBUG unable to retrieve '/home/yunohost.backup/archives/synapse.info.json' inside the archive
Traceback (most recent call last):
  File "/usr/lib/moulinette/yunohost/backup.py", line 2233, in backup_info
    tar.extract('info.json', path=info_dir)
  File "/usr/lib/python2.7/tarfile.py", line 2109, in extract
    tarinfo = self.getmember(member)
  File "/usr/lib/python2.7/tarfile.py", line 1829, in getmember
    raise KeyError("filename %r not found" % name)
KeyError: "filename 'info.json' not found"
13797 DEBUG action [31673.1] executed in 13.328s
13797 DEBUG lock has been released
13798 ERROR Invalid backup archive

What is the output of :

There are lot of my backups but synapse related files are:

drwxr-xr-x 3 root root        4096 May  7 18:24 synapse
-rw-r--r-- 1 root root         272 May  6 01:26 synapse-pre-upgrade2.info.json
-rw-r--r-- 1 root root   199269186 May  6 01:26 synapse-pre-upgrade2.tar.gz
-rw-r--r-- 1 root root   206604819 May  8 22:43 synapse.tar.gz

I have extracted synapse-pre-upgrade2.tar.gz to synapse folder, did changes in restore script and created the synapse.tar.gz as you told in above comment.

Cant I restore from the folder ?

Sorry I did not saw full path

These are the content of the synpse folder.

apps backup.csv info.json

Pour voir ce qu’il y a dans le tar gz
tar -ztvf synapse.tar.gz | grep info.json

?

-rw-r–r-- root/root 272 2019-05-06 01:24 ./info.json

Try to extract the info.json and put it on this path:

Are you up to date on your yunohost?

I have done it already done.

I have found the the bug. The compression is taking ./ as the path, but it should be without ./ as I see in the original backup.

-rw-r–r-- root/root 272 2019-05-06 01:24 ./info.json

Do you know how to tar without the ./ path ?

Follow-up of discussion on the forum : for tar, foo is not the same as ./foo

A quickfix for this is to use tar -zcvf ../synapse.tar.gz * instead of tar -zcvf ../synapse.tar.gz .

A more longterm fix is https://github.com/YunoHost/yunohost/pull/726 though I don’t know how relevant it is considering this is really an edge case of “repackaging a backup archive manually”

1 Like