mirror of
https://github.com/borgbase/vorta
synced 2025-03-06 19:58:14 +00:00
Add support for --paths-from-command
to extra borg arguments. (#1538)
Backups will run although no sources are specified if `--paths-from-command` is supplied. Also arguments after `--` will be appended to the end of the command after all other arguments. Closes #1537. * src/vorta/borg/create.py * tests/test_create.py : Add test for using `--path-from-commands`. Co-authored-by: real-yfprojects <real-yfprojects@users.noreply.github.com>
This commit is contained in:
parent
bf9285a171
commit
66340bc2a8
2 changed files with 66 additions and 4 deletions
|
@ -77,7 +77,18 @@ class BorgCreateJob(BorgJob):
|
|||
ret['ok'] = False # Set back to False, so we can do our own checks here.
|
||||
|
||||
n_backup_folders = SourceFileModel.select().count()
|
||||
if n_backup_folders == 0:
|
||||
|
||||
# cmd options like `--paths-from-command` require a command
|
||||
# that is appended to the arguments
|
||||
# $ borg create --paths-from-command repo::archive1 -- find /home/user -type f -size -76M
|
||||
extra_cmd_options = []
|
||||
suffix_command = []
|
||||
if profile.repo.create_backup_cmd:
|
||||
s1, sep, s2 = profile.repo.create_backup_cmd.partition('-- ')
|
||||
extra_cmd_options = s1.split()
|
||||
suffix_command = (sep + s2).split()
|
||||
|
||||
if n_backup_folders == 0 and '--paths-from-command' not in extra_cmd_options:
|
||||
ret['message'] = trans_late('messages', 'Add some folders to back up first.')
|
||||
return ret
|
||||
|
||||
|
@ -132,9 +143,7 @@ class BorgCreateJob(BorgJob):
|
|||
'-C',
|
||||
profile.compression,
|
||||
]
|
||||
|
||||
if profile.repo.create_backup_cmd:
|
||||
cmd.extend(profile.repo.create_backup_cmd.split(' '))
|
||||
cmd += extra_cmd_options
|
||||
|
||||
# Add excludes
|
||||
# Partly inspired by borgmatic/borgmatic/borg/create.py
|
||||
|
@ -164,6 +173,8 @@ class BorgCreateJob(BorgJob):
|
|||
for f in SourceFileModel.select().where(SourceFileModel.profile == profile.id):
|
||||
cmd.append(f.dir)
|
||||
|
||||
cmd += suffix_command
|
||||
|
||||
ret['message'] = trans_late('messages', 'Starting backup…')
|
||||
ret['ok'] = True
|
||||
ret['cmd'] = cmd
|
||||
|
|
51
tests/test_create.py
Normal file
51
tests/test_create.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
from vorta.borg.create import BorgCreateJob
|
||||
from vorta.store.models import BackupProfileModel, SourceFileModel
|
||||
|
||||
|
||||
def test_create_paths_from_command():
|
||||
default_profile = BackupProfileModel.get()
|
||||
default_profile.new_archive_name = 'a1'
|
||||
|
||||
default_profile.repo.create_backup_cmd = '--one-file-system'
|
||||
result = BorgCreateJob.prepare(default_profile)
|
||||
|
||||
assert 'cmd' in result
|
||||
assert result['cmd'] == [
|
||||
'borg',
|
||||
'create',
|
||||
'--list',
|
||||
'--progress',
|
||||
'--info',
|
||||
'--log-json',
|
||||
'--json',
|
||||
'--filter=AM',
|
||||
'-C',
|
||||
'lz4',
|
||||
'--one-file-system',
|
||||
'i0fi93@i593.repo.borgbase.com:repo::a1',
|
||||
'/tmp/another',
|
||||
]
|
||||
|
||||
default_profile.repo.create_backup_cmd = '--paths-from-command -- echo /tmp/another'
|
||||
SourceFileModel.delete().execute()
|
||||
|
||||
result = BorgCreateJob.prepare(default_profile)
|
||||
|
||||
assert 'cmd' in result
|
||||
assert result['cmd'] == [
|
||||
'borg',
|
||||
'create',
|
||||
'--list',
|
||||
'--progress',
|
||||
'--info',
|
||||
'--log-json',
|
||||
'--json',
|
||||
'--filter=AM',
|
||||
'-C',
|
||||
'lz4',
|
||||
'--paths-from-command',
|
||||
'i0fi93@i593.repo.borgbase.com:repo::a1',
|
||||
'--',
|
||||
'echo',
|
||||
'/tmp/another',
|
||||
]
|
Loading…
Add table
Reference in a new issue