backups: Use backups API for restore

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
James Valleroy authored and Joseph Nuthalapati committed 2018-09-24 19:43:43 +05:30
1 parent 481a299250
commit 4d8b3c145d
3 files changed
+39 -12

No files matched your search

+15 -4
View File
@@ -29,7 +29,7 @@ from plinth import actions
from plinth.menu import main_menu
from plinth.modules import udiskie
from .backups import backup_apps
from .backups import backup_apps, restore_apps
version = 1
@@ -162,13 +162,24 @@ def get_export_apps(filename):
return output.splitlines()
def _restore_handler(packet):
"""Perform restore operation on packet."""
locations = {
'directories': packet.directories,
'files': packet.files
}
locations_data = json.dumps(locations)
actions.superuser_run(
'backups', ['restore', '--filename', packet.label],
input=locations_data.encode())
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.
actions.superuser_run(
'backups', ['restore', '--filename', filename])
restore_apps(_restore_handler, app_names=apps, create_subvolume=False,
backup_file=filename)
else:
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), filename)
+3 -2
View File
@@ -152,7 +152,8 @@ def backup_apps(backup_handler, app_names=None, label=None):
_lockdown_apps(apps, lockdown=False)
def restore_apps(restore_handler, app_names=None, create_subvolume=True):
def restore_apps(restore_handler, app_names=None, create_subvolume=True,
backup_file=None):
"""Restore data belonging to a set of applications."""
if not app_names:
apps = _list_of_all_apps_for_backup()
@@ -171,7 +172,7 @@ def restore_apps(restore_handler, app_names=None, create_subvolume=True):
restore_root = '/'
subvolume = False
packet = Packet('restore', 'apps', restore_root, manifests)
packet = Packet('restore', 'apps', restore_root, manifests, backup_file)
_run_operation(restore_handler, packet)
if subvolume: