backups: Check if paths exist before passing them to borgbackup

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
Joseph Nuthalapati 2018-08-27 13:56:35 +05:30
parent 7997835c27
commit 5633fccaa3
No known key found for this signature in database
GPG Key ID: 5398F00A2FA43C35
2 changed files with 15 additions and 8 deletions

View File

@ -41,8 +41,8 @@ def parse_arguments():
create = subparsers.add_parser('create', help='Create archive') create = subparsers.add_parser('create', help='Create archive')
create.add_argument('--name', help='Archive name', required=True) create.add_argument('--name', help='Archive name', required=True)
create.add_argument( create.add_argument('--paths', help='Paths to include in archive',
'--path', help='Paths to include in archive', nargs='+') nargs='+')
delete = subparsers.add_parser('delete', help='Delete archive') delete = subparsers.add_parser('delete', help='Delete archive')
delete.add_argument('--name', help='Archive name', required=True) delete.add_argument('--name', help='Archive name', required=True)
@ -90,9 +90,13 @@ def subcommand_list(_):
def subcommand_create(arguments): def subcommand_create(arguments):
"""Create archive.""" """Create archive."""
paths = filter(os.path.exists, arguments.paths)
subprocess.run([ subprocess.run([
'borg', 'create', '--json', REPOSITORY + '::' + arguments.name, 'borg',
] + arguments.path, check=True) 'create',
'--json',
REPOSITORY + '::' + arguments.name,
] + list(paths), check=True)
def subcommand_delete(arguments): def subcommand_delete(arguments):

View File

@ -23,18 +23,21 @@ import os
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from .backups import backup_apps
from plinth import actions from plinth import actions
from plinth.menu import main_menu from plinth.menu import main_menu
from plinth.modules import udiskie from plinth.modules import udiskie
from .backups import backup_apps
version = 1 version = 1
managed_packages = ['borgbackup'] managed_packages = ['borgbackup']
name = _('Backups') name = _('Backups')
description = [_('Backups allows creating and managing backup archives.'), ] description = [
_('Backups allows creating and managing backup archives.'),
]
service = None service = None
@ -87,8 +90,8 @@ def _backup_handler(packet):
paths = packet.directories + packet.files paths = packet.directories + packet.files
paths.append(manifest_path) paths.append(manifest_path)
actions.superuser_run('backups', actions.superuser_run(
['create', '--name', packet.label, '--path'] + paths) 'backups', ['create', '--name', packet.label, '--paths'] + paths)
def create_archive(name, app_names): def create_archive(name, app_names):