mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
backups: Add list of exported archives
Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
ab9f961091
commit
bd45de2915
@ -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()
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -47,6 +47,7 @@
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<h3>{% trans 'Backup archives' %}</h3>
|
||||
{% if not archives %}
|
||||
<p>{% trans 'No archives currently exist.' %}</p>
|
||||
{% else %}
|
||||
@ -86,4 +87,26 @@
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
<h3>{% trans 'Exported backup archives' %}</h3>
|
||||
{% if not exports %}
|
||||
<p>{% trans 'No exported backup archives were found.' %}</p>
|
||||
{% else %}
|
||||
<table class="table table-bordered table-condensed table-striped"
|
||||
id="exports-list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Name" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for export in exports %}
|
||||
<tr id="export-{{ export }}" class="export">
|
||||
<td class="export-name">{{ export }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user