Commit 6c89cc31 authored by James Valleroy's avatar James Valleroy

backups: Confirm that archive exists before restoring

Signed-off-by: James Valleroy's avatarJames Valleroy <>
parent 9b82fa2f
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
FreedomBox app to manage backup archives. FreedomBox app to manage backup archives.
""" """
import errno
import json import json
import os import os
...@@ -138,15 +139,28 @@ def get_export_files(): ...@@ -138,15 +139,28 @@ def get_export_files():
return export_files return export_files
def restore_exported(label, name): def _find_exported_archive(disk_label, archive_name):
"""Restore files from exported backup archive.""" """Return the full path for the exported archive file."""
path = None
locations = get_export_locations() locations = get_export_locations()
for location in locations: for location in locations:
if location[1] == label: if location[1] == disk_label:
filename = location[0] path = location[0]
if filename[-1] != '/': if path[-1] != '/':
filename += '/' path += '/'
filename += 'FreedomBox-backups/' + name path += 'FreedomBox-backups/' + archive_name
'backups', ['restore', '--filename', filename])
break break
return path
def restore_exported(label, name, apps=None):
"""Restore files from exported backup archive."""
filename = _find_exported_archive(label, name)
if filename:
# TODO: Use backups API.
'backups', ['restore', '--filename', filename])
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), filename)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment