diff --git a/actions/backups b/actions/backups index 252552215..f0364abef 100755 --- a/actions/backups +++ b/actions/backups @@ -21,6 +21,7 @@ Configuration helper for backups. """ import argparse +import json import os import subprocess @@ -54,6 +55,10 @@ def parse_arguments(): export.add_argument('--name', help='Archive name', required=True) export.add_argument('--filename', help='Tarball file name', required=True) + list_exports = subparsers.add_parser( + 'list-exports', help='List exported backup archive files') + list_exports.add_argument('--locations', nargs='+', + help='list of locations to check') subparsers.required = True return parser.parse_args() @@ -114,6 +119,21 @@ def subcommand_export(arguments): ], check=True) +def subcommand_list_exports(arguments): + """List exported backup archive files.""" + archive_files = [] + for location in arguments.locations: + backup_path = location + if backup_path[-1] != '/': + backup_path += '/' + backup_path += 'FreedomBox-backups/' + if os.path.exists(backup_path): + for filename in os.listdir(backup_path): + archive_files.append(os.path.join(backup_path, filename)) + + print(json.dumps(archive_files)) + + def main(): """Parse arguments and perform all duties.""" arguments = parse_arguments() diff --git a/plinth/modules/backups/__init__.py b/plinth/modules/backups/__init__.py index 83ddb059f..d38e37e9c 100644 --- a/plinth/modules/backups/__init__.py +++ b/plinth/modules/backups/__init__.py @@ -100,3 +100,11 @@ def get_export_locations(): locations.append((device['mount_points'][0], name)) return locations + + +def list_export_files(): + """Return a list of exported backup archives found in storage locations.""" + locations = [x[0] for x in get_export_locations()] + command = ['list-exports', '--locations'] + locations + output = actions.superuser_run('backups', command) + return json.loads(output) diff --git a/plinth/modules/backups/templates/backups.html b/plinth/modules/backups/templates/backups.html index 6121e396a..4f40c9e21 100644 --- a/plinth/modules/backups/templates/backups.html +++ b/plinth/modules/backups/templates/backups.html @@ -47,6 +47,7 @@

+

{% trans 'Backup archives' %}

{% if not archives %}

{% trans 'No archives currently exist.' %}

{% else %} @@ -86,4 +87,26 @@ {% endif %} +

{% trans 'Exported backup archives' %}

+ {% if not exports %} +

{% trans 'No exported backup archives were found.' %}

+ {% else %} + + + + + + + + + {% for export in exports %} + + + + {% endfor %} + +
{% trans "Name" %}
{{ export }}
+ {% endif %} + {% endblock %} diff --git a/plinth/modules/backups/views.py b/plinth/modules/backups/views.py index 8ed56ca0a..b3bc80424 100644 --- a/plinth/modules/backups/views.py +++ b/plinth/modules/backups/views.py @@ -42,6 +42,7 @@ class IndexView(TemplateView): context['description'] = backups.description context['info'] = backups.get_info() context['archives'] = backups.list_archives() + context['exports'] = backups.list_export_files() return context