From d76322a362722ef0e6451f0b629be6c3d133244e Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sat, 25 Aug 2018 21:34:43 -0400 Subject: [PATCH] backups: Dump manifests file and include it in backup Signed-off-by: James Valleroy Reviewed-by: Joseph Nuthalapati --- plinth/modules/backups/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plinth/modules/backups/__init__.py b/plinth/modules/backups/__init__.py index 0567b56b6..c6dbed236 100644 --- a/plinth/modules/backups/__init__.py +++ b/plinth/modules/backups/__init__.py @@ -19,6 +19,7 @@ FreedomBox app to manage backup archives. """ import json +import os from django.utils.translation import ugettext_lazy as _ @@ -37,6 +38,8 @@ description = [_('Backups allows creating and managing backup archives.'), ] service = None +MANIFESTS_FOLDER = '/var/lib/plinth/backups-manifests/' + def init(): """Intialize the module.""" @@ -70,7 +73,16 @@ def get_archive(name): def _backup_handler(packet): """Performs backup operation on packet.""" + if not os.path.exists(MANIFESTS_FOLDER): + os.makedirs(MANIFESTS_FOLDER) + + manifest_path = MANIFESTS_FOLDER + packet.label + '.json' + manifests = {x[0]: x[2] for x in packet.manifests} + with open(manifest_path, 'w') as manifest_file: + json.dump(manifests, manifest_file) + paths = packet.directories + packet.files + paths.append(manifest_path) actions.superuser_run('backups', ['create', '--name', packet.label, '--path'] + paths)