Improve error handling on rdiff-backup restore
On rdiff-backup restore failure, we should improve the visibility of the error to the user and administrator.
- Continue to return a server error 500.
- Recommend to contact administrator and check the server logs.
- In the logs, provide a better exception that display the command output.
e.g.:
The following stack trace is a good start, but it hide the real problem where rdiff-backup
is not installed.
Traceback (most recent call last):
File "/opt/minarca-server/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 638, in respond
self._do_respond(path_info)
File "/opt/minarca-server/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 697, in _do_respond
response.body = self.handler()
File "/opt/minarca-server/lib/python3.9/site-packages/cherrypy/lib/encoding.py", line 223, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/opt/minarca-server/lib/python3.9/site-packages/cherrypy/_cpdispatch.py", line 54, in __call__
return self.callable(*self.args, **self.kwargs)
File "/opt/minarca-server/lib/python3.9/site-packages/rdiffweb/controller/page_restore.py", line 118, in default
filename, fileobj = repo.restore(path, int(date), kind=kind)
File "/opt/minarca-server/lib/python3.9/site-packages/rdiffweb/core/librdiff.py", line 1174, in restore
raise CalledProcessError(1, cmdline, output)
subprocess.CalledProcessError: Command '[b'/opt/minarca-server/bin/python', b'-m', b'rdiffweb.core.restore', b'--restore-as-of', b'1667573775', b'--encoding', b'utf-8', b'--kind', b'raw', b'/backups/ikus060/DESKTOP-4QNNQ86/C/Users/vmtest/Documents/desktop.ini', b'-']' returned non-zero exit status 1.
[2022-11-04 10:57:10,648][ERROR ][10.255.4.7][ikus060][('CP Server Thread-4',)][rdiffweb.rdw_app] error page: 500 Internal Server Error The server encountered an unexpected condition which prevented it from fulfilling the request.
When running the command line:
/opt/minarca-server/bin/python -m rdiffweb.core.restore --restore-as-of 1667573775 --encoding utf-8 --kind raw /backups/ikus060/DESKTOP-4QNNQ86/C/Users/vmtest/Documents/desktop.ini -
restoring data into temporary folder: b'/tmp/rdiffweb_restore_s4dg1iz1'
error: failure to create the archive
Traceback (most recent call last):
File "/opt/minarca-server/lib/python3.9/site-packages/rdiffweb/core/restore.py", line 298, in main
restore(path, args.restore_as_of, args.kind, args.encoding, output, log=_print_stderr)
File "/opt/minarca-server/lib/python3.9/site-packages/rdiffweb/core/restore.py", line 211, in restore
rdiff_backup_path = find_rdiff_backup()
File "/opt/minarca-server/lib/python3.9/site-packages/rdiffweb/core/librdiff.py", line 71, in find_rdiff_backup
raise FileNotFoundError("can't find `rdiff-backup` executable in PATH: %s" % os.environ['PATH'])
FileNotFoundError: can't find `rdiff-backup` executable in PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Edited by Patrik Dufresne