test_create.py 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582
  1. import logging
  2. import pytest
  3. from flexmock import flexmock
  4. from borgmatic.borg import create as module
  5. from ..test_verbosity import insert_logging_mock
  6. def test_expand_directory_with_basic_path_passes_it_through():
  7. flexmock(module.os.path).should_receive('expanduser').and_return('foo')
  8. flexmock(module.glob).should_receive('glob').and_return([])
  9. paths = module._expand_directory('foo')
  10. assert paths == ['foo']
  11. def test_expand_directory_with_glob_expands():
  12. flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
  13. flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
  14. paths = module._expand_directory('foo*')
  15. assert paths == ['foo', 'food']
  16. def test_expand_directories_flattens_expanded_directories():
  17. flexmock(module).should_receive('_expand_directory').with_args('~/foo').and_return(
  18. ['/root/foo']
  19. )
  20. flexmock(module).should_receive('_expand_directory').with_args('bar*').and_return(
  21. ['bar', 'barf']
  22. )
  23. paths = module._expand_directories(('~/foo', 'bar*'))
  24. assert paths == ('/root/foo', 'bar', 'barf')
  25. def test_expand_directories_considers_none_as_no_directories():
  26. paths = module._expand_directories(None)
  27. assert paths == ()
  28. def test_expand_home_directories_expands_tildes():
  29. flexmock(module.os.path).should_receive('expanduser').with_args('~/bar').and_return('/foo/bar')
  30. flexmock(module.os.path).should_receive('expanduser').with_args('baz').and_return('baz')
  31. paths = module._expand_home_directories(('~/bar', 'baz'))
  32. assert paths == ('/foo/bar', 'baz')
  33. def test_expand_home_directories_considers_none_as_no_directories():
  34. paths = module._expand_home_directories(None)
  35. assert paths == ()
  36. def test_map_directories_to_devices_gives_device_id_per_path():
  37. flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
  38. flexmock(module.os).should_receive('stat').with_args('/bar').and_return(flexmock(st_dev=66))
  39. device_map = module.map_directories_to_devices(('/foo', '/bar'))
  40. assert device_map == {
  41. '/foo': 55,
  42. '/bar': 66,
  43. }
  44. def test_map_directories_to_devices_with_missing_path_does_not_error():
  45. flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
  46. flexmock(module.os).should_receive('stat').with_args('/bar').and_raise(FileNotFoundError)
  47. device_map = module.map_directories_to_devices(('/foo', '/bar'))
  48. assert device_map == {
  49. '/foo': 55,
  50. '/bar': None,
  51. }
  52. @pytest.mark.parametrize(
  53. 'directories,expected_directories',
  54. (
  55. ({'/': 1, '/root': 1}, ('/',)),
  56. ({'/': 1, '/root/': 1}, ('/',)),
  57. ({'/': 1, '/root': 2}, ('/', '/root')),
  58. ({'/root': 1, '/': 1}, ('/',)),
  59. ({'/root': 1, '/root/foo': 1}, ('/root',)),
  60. ({'/root/': 1, '/root/foo': 1}, ('/root/',)),
  61. ({'/root': 1, '/root/foo/': 1}, ('/root',)),
  62. ({'/root': 1, '/root/foo': 2}, ('/root', '/root/foo')),
  63. ({'/root/foo': 1, '/root': 1}, ('/root',)),
  64. ({'/root': None, '/root/foo': None}, ('/root', '/root/foo')),
  65. ({'/root': 1, '/etc': 1, '/root/foo/bar': 1}, ('/etc', '/root')),
  66. ({'/root': 1, '/root/foo': 1, '/root/foo/bar': 1}, ('/root',)),
  67. ({'/dup': 1, '/dup': 1}, ('/dup',)),
  68. ({'/foo': 1, '/bar': 1}, ('/bar', '/foo')),
  69. ({'/foo': 1, '/bar': 2}, ('/bar', '/foo')),
  70. ),
  71. )
  72. def test_deduplicate_directories_removes_child_paths_on_the_same_filesystem(
  73. directories, expected_directories
  74. ):
  75. assert module.deduplicate_directories(directories) == expected_directories
  76. def test_write_pattern_file_does_not_raise():
  77. temporary_file = flexmock(name='filename', write=lambda mode: None, flush=lambda: None)
  78. flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
  79. module._write_pattern_file(['exclude'])
  80. def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
  81. module._write_pattern_file([])
  82. def test_make_pattern_flags_includes_pattern_filename_when_given():
  83. pattern_flags = module._make_pattern_flags(
  84. location_config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
  85. )
  86. assert pattern_flags == ('--patterns-from', '/tmp/patterns')
  87. def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
  88. pattern_flags = module._make_pattern_flags(
  89. location_config={'patterns_from': ['patterns', 'other']}
  90. )
  91. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
  92. def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
  93. pattern_flags = module._make_pattern_flags(
  94. location_config={'patterns_from': ['patterns']}, pattern_filename='/tmp/patterns'
  95. )
  96. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
  97. def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
  98. pattern_flags = module._make_pattern_flags(location_config={'patterns_from': None})
  99. assert pattern_flags == ()
  100. def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
  101. exclude_flags = module._make_exclude_flags(
  102. location_config={'exclude_patterns': ['*.pyc', '/var']}, exclude_filename='/tmp/excludes'
  103. )
  104. assert exclude_flags == ('--exclude-from', '/tmp/excludes')
  105. def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
  106. exclude_flags = module._make_exclude_flags(
  107. location_config={'exclude_from': ['excludes', 'other']}
  108. )
  109. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
  110. def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
  111. exclude_flags = module._make_exclude_flags(
  112. location_config={'exclude_from': ['excludes']}, exclude_filename='/tmp/excludes'
  113. )
  114. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
  115. def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
  116. exclude_flags = module._make_exclude_flags(location_config={'exclude_from': None})
  117. assert exclude_flags == ()
  118. def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
  119. exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': True})
  120. assert exclude_flags == ('--exclude-caches',)
  121. def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
  122. exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': False})
  123. assert exclude_flags == ()
  124. def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
  125. exclude_flags = module._make_exclude_flags(
  126. location_config={'exclude_if_present': ['exclude_me', 'also_me']}
  127. )
  128. assert exclude_flags == (
  129. '--exclude-if-present',
  130. 'exclude_me',
  131. '--exclude-if-present',
  132. 'also_me',
  133. )
  134. def test_make_exclude_flags_includes_keep_exclude_tags_when_true_in_config():
  135. exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': True})
  136. assert exclude_flags == ('--keep-exclude-tags',)
  137. def test_make_exclude_flags_does_not_include_keep_exclude_tags_when_false_in_config():
  138. exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': False})
  139. assert exclude_flags == ()
  140. def test_make_exclude_flags_includes_exclude_nodump_when_true_in_config():
  141. exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': True})
  142. assert exclude_flags == ('--exclude-nodump',)
  143. def test_make_exclude_flags_does_not_include_exclude_nodump_when_false_in_config():
  144. exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': False})
  145. assert exclude_flags == ()
  146. def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
  147. exclude_flags = module._make_exclude_flags(location_config={})
  148. assert exclude_flags == ()
  149. def test_borgmatic_source_directories_set_when_directory_exists():
  150. flexmock(module.os.path).should_receive('exists').and_return(True)
  151. flexmock(module.os.path).should_receive('expanduser')
  152. assert module.borgmatic_source_directories('/tmp') == ['/tmp']
  153. def test_borgmatic_source_directories_empty_when_directory_does_not_exist():
  154. flexmock(module.os.path).should_receive('exists').and_return(False)
  155. flexmock(module.os.path).should_receive('expanduser')
  156. assert module.borgmatic_source_directories('/tmp') == []
  157. def test_borgmatic_source_directories_defaults_when_directory_not_given():
  158. flexmock(module.os.path).should_receive('exists').and_return(True)
  159. flexmock(module.os.path).should_receive('expanduser')
  160. assert module.borgmatic_source_directories(None) == [module.DEFAULT_BORGMATIC_SOURCE_DIRECTORY]
  161. DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
  162. ARCHIVE_WITH_PATHS = ('repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar')
  163. def test_create_archive_calls_borg_with_parameters():
  164. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  165. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  166. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  167. flexmock(module).should_receive('_expand_directories').and_return(())
  168. flexmock(module).should_receive('_expand_home_directories').and_return(())
  169. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  170. flexmock(module.feature).should_receive('available').and_return(True)
  171. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  172. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  173. flexmock(module).should_receive('execute_command').with_args(
  174. ('borg', 'create') + ARCHIVE_WITH_PATHS,
  175. output_log_level=logging.INFO,
  176. output_file=None,
  177. borg_local_path='borg',
  178. )
  179. module.create_archive(
  180. dry_run=False,
  181. repository='repo',
  182. location_config={
  183. 'source_directories': ['foo', 'bar'],
  184. 'repositories': ['repo'],
  185. 'exclude_patterns': None,
  186. },
  187. storage_config={},
  188. local_borg_version='1.2.3',
  189. )
  190. def test_create_archive_with_patterns_calls_borg_with_patterns():
  191. pattern_flags = ('--patterns-from', 'patterns')
  192. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  193. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  194. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  195. flexmock(module).should_receive('_expand_directories').and_return(())
  196. flexmock(module).should_receive('_expand_home_directories').and_return(())
  197. flexmock(module).should_receive('_write_pattern_file').and_return(
  198. flexmock(name='/tmp/patterns')
  199. ).and_return(None)
  200. flexmock(module.feature).should_receive('available').and_return(True)
  201. flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
  202. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  203. flexmock(module).should_receive('execute_command').with_args(
  204. ('borg', 'create') + pattern_flags + ARCHIVE_WITH_PATHS,
  205. output_log_level=logging.INFO,
  206. output_file=None,
  207. borg_local_path='borg',
  208. )
  209. module.create_archive(
  210. dry_run=False,
  211. repository='repo',
  212. location_config={
  213. 'source_directories': ['foo', 'bar'],
  214. 'repositories': ['repo'],
  215. 'patterns': ['pattern'],
  216. },
  217. storage_config={},
  218. local_borg_version='1.2.3',
  219. )
  220. def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
  221. exclude_flags = ('--exclude-from', 'excludes')
  222. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  223. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  224. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  225. flexmock(module).should_receive('_expand_directories').and_return(())
  226. flexmock(module).should_receive('_expand_home_directories').and_return(('exclude',))
  227. flexmock(module).should_receive('_write_pattern_file').and_return(None).and_return(
  228. flexmock(name='/tmp/excludes')
  229. )
  230. flexmock(module.feature).should_receive('available').and_return(True)
  231. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  232. flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
  233. flexmock(module).should_receive('execute_command').with_args(
  234. ('borg', 'create') + exclude_flags + ARCHIVE_WITH_PATHS,
  235. output_log_level=logging.INFO,
  236. output_file=None,
  237. borg_local_path='borg',
  238. )
  239. module.create_archive(
  240. dry_run=False,
  241. repository='repo',
  242. location_config={
  243. 'source_directories': ['foo', 'bar'],
  244. 'repositories': ['repo'],
  245. 'exclude_patterns': ['exclude'],
  246. },
  247. storage_config={},
  248. local_borg_version='1.2.3',
  249. )
  250. def test_create_archive_with_log_info_calls_borg_with_info_parameter():
  251. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  252. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  253. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  254. flexmock(module).should_receive('_expand_directories').and_return(())
  255. flexmock(module).should_receive('_expand_home_directories').and_return(())
  256. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  257. flexmock(module.feature).should_receive('available').and_return(True)
  258. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  259. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  260. flexmock(module).should_receive('execute_command').with_args(
  261. ('borg', 'create', '--info') + ARCHIVE_WITH_PATHS,
  262. output_log_level=logging.INFO,
  263. output_file=None,
  264. borg_local_path='borg',
  265. )
  266. insert_logging_mock(logging.INFO)
  267. module.create_archive(
  268. dry_run=False,
  269. repository='repo',
  270. location_config={
  271. 'source_directories': ['foo', 'bar'],
  272. 'repositories': ['repo'],
  273. 'exclude_patterns': None,
  274. },
  275. storage_config={},
  276. local_borg_version='1.2.3',
  277. )
  278. def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
  279. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  280. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  281. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  282. flexmock(module).should_receive('_expand_directories').and_return(())
  283. flexmock(module).should_receive('_expand_home_directories').and_return(())
  284. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  285. flexmock(module.feature).should_receive('available').and_return(True)
  286. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  287. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  288. flexmock(module).should_receive('execute_command').with_args(
  289. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  290. output_log_level=None,
  291. output_file=None,
  292. borg_local_path='borg',
  293. )
  294. insert_logging_mock(logging.INFO)
  295. module.create_archive(
  296. dry_run=False,
  297. repository='repo',
  298. location_config={
  299. 'source_directories': ['foo', 'bar'],
  300. 'repositories': ['repo'],
  301. 'exclude_patterns': None,
  302. },
  303. storage_config={},
  304. local_borg_version='1.2.3',
  305. json=True,
  306. )
  307. def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
  308. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  309. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  310. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  311. flexmock(module).should_receive('_expand_directories').and_return(())
  312. flexmock(module).should_receive('_expand_home_directories').and_return(())
  313. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  314. flexmock(module.feature).should_receive('available').and_return(True)
  315. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  316. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  317. flexmock(module).should_receive('execute_command').with_args(
  318. ('borg', 'create', '--debug', '--show-rc') + ARCHIVE_WITH_PATHS,
  319. output_log_level=logging.INFO,
  320. output_file=None,
  321. borg_local_path='borg',
  322. )
  323. insert_logging_mock(logging.DEBUG)
  324. module.create_archive(
  325. dry_run=False,
  326. repository='repo',
  327. location_config={
  328. 'source_directories': ['foo', 'bar'],
  329. 'repositories': ['repo'],
  330. 'exclude_patterns': None,
  331. },
  332. storage_config={},
  333. local_borg_version='1.2.3',
  334. )
  335. def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
  336. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  337. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  338. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  339. flexmock(module).should_receive('_expand_directories').and_return(())
  340. flexmock(module).should_receive('_expand_home_directories').and_return(())
  341. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  342. flexmock(module.feature).should_receive('available').and_return(True)
  343. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  344. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  345. flexmock(module).should_receive('execute_command').with_args(
  346. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  347. output_log_level=None,
  348. output_file=None,
  349. borg_local_path='borg',
  350. )
  351. insert_logging_mock(logging.DEBUG)
  352. module.create_archive(
  353. dry_run=False,
  354. repository='repo',
  355. location_config={
  356. 'source_directories': ['foo', 'bar'],
  357. 'repositories': ['repo'],
  358. 'exclude_patterns': None,
  359. },
  360. storage_config={},
  361. local_borg_version='1.2.3',
  362. json=True,
  363. )
  364. def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
  365. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  366. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  367. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  368. flexmock(module).should_receive('_expand_directories').and_return(())
  369. flexmock(module).should_receive('_expand_home_directories').and_return(())
  370. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  371. flexmock(module.feature).should_receive('available').and_return(True)
  372. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  373. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  374. flexmock(module).should_receive('execute_command').with_args(
  375. ('borg', 'create', '--dry-run') + ARCHIVE_WITH_PATHS,
  376. output_log_level=logging.INFO,
  377. output_file=None,
  378. borg_local_path='borg',
  379. )
  380. module.create_archive(
  381. dry_run=True,
  382. repository='repo',
  383. location_config={
  384. 'source_directories': ['foo', 'bar'],
  385. 'repositories': ['repo'],
  386. 'exclude_patterns': None,
  387. },
  388. storage_config={},
  389. local_borg_version='1.2.3',
  390. )
  391. def test_create_archive_with_stats_and_dry_run_calls_borg_without_stats_parameter():
  392. # --dry-run and --stats are mutually exclusive, see:
  393. # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
  394. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  395. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  396. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  397. flexmock(module).should_receive('_expand_directories').and_return(())
  398. flexmock(module).should_receive('_expand_home_directories').and_return(())
  399. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  400. flexmock(module.feature).should_receive('available').and_return(True)
  401. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  402. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  403. flexmock(module).should_receive('execute_command').with_args(
  404. ('borg', 'create', '--info', '--dry-run') + ARCHIVE_WITH_PATHS,
  405. output_log_level=logging.INFO,
  406. output_file=None,
  407. borg_local_path='borg',
  408. )
  409. insert_logging_mock(logging.INFO)
  410. module.create_archive(
  411. dry_run=True,
  412. repository='repo',
  413. location_config={
  414. 'source_directories': ['foo', 'bar'],
  415. 'repositories': ['repo'],
  416. 'exclude_patterns': None,
  417. },
  418. storage_config={},
  419. local_borg_version='1.2.3',
  420. stats=True,
  421. )
  422. def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
  423. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  424. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  425. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  426. flexmock(module).should_receive('_expand_directories').and_return(())
  427. flexmock(module).should_receive('_expand_home_directories').and_return(())
  428. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  429. flexmock(module.feature).should_receive('available').and_return(True)
  430. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  431. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  432. flexmock(module).should_receive('execute_command').with_args(
  433. ('borg', 'create', '--checkpoint-interval', '600') + ARCHIVE_WITH_PATHS,
  434. output_log_level=logging.INFO,
  435. output_file=None,
  436. borg_local_path='borg',
  437. )
  438. module.create_archive(
  439. dry_run=False,
  440. repository='repo',
  441. location_config={
  442. 'source_directories': ['foo', 'bar'],
  443. 'repositories': ['repo'],
  444. 'exclude_patterns': None,
  445. },
  446. storage_config={'checkpoint_interval': 600},
  447. local_borg_version='1.2.3',
  448. )
  449. def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_parameters():
  450. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  451. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  452. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  453. flexmock(module).should_receive('_expand_directories').and_return(())
  454. flexmock(module).should_receive('_expand_home_directories').and_return(())
  455. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  456. flexmock(module.feature).should_receive('available').and_return(True)
  457. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  458. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  459. flexmock(module).should_receive('execute_command').with_args(
  460. ('borg', 'create', '--chunker-params', '1,2,3,4') + ARCHIVE_WITH_PATHS,
  461. output_log_level=logging.INFO,
  462. output_file=None,
  463. borg_local_path='borg',
  464. )
  465. module.create_archive(
  466. dry_run=False,
  467. repository='repo',
  468. location_config={
  469. 'source_directories': ['foo', 'bar'],
  470. 'repositories': ['repo'],
  471. 'exclude_patterns': None,
  472. },
  473. storage_config={'chunker_params': '1,2,3,4'},
  474. local_borg_version='1.2.3',
  475. )
  476. def test_create_archive_with_compression_calls_borg_with_compression_parameters():
  477. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  478. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  479. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  480. flexmock(module).should_receive('_expand_directories').and_return(())
  481. flexmock(module).should_receive('_expand_home_directories').and_return(())
  482. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  483. flexmock(module.feature).should_receive('available').and_return(True)
  484. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  485. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  486. flexmock(module).should_receive('execute_command').with_args(
  487. ('borg', 'create', '--compression', 'rle') + ARCHIVE_WITH_PATHS,
  488. output_log_level=logging.INFO,
  489. output_file=None,
  490. borg_local_path='borg',
  491. )
  492. module.create_archive(
  493. dry_run=False,
  494. repository='repo',
  495. location_config={
  496. 'source_directories': ['foo', 'bar'],
  497. 'repositories': ['repo'],
  498. 'exclude_patterns': None,
  499. },
  500. storage_config={'compression': 'rle'},
  501. local_borg_version='1.2.3',
  502. )
  503. @pytest.mark.parametrize(
  504. 'feature_available,option_flag', ((True, '--upload-ratelimit'), (False, '--remote-ratelimit')),
  505. )
  506. def test_create_archive_with_remote_rate_limit_calls_borg_with_upload_ratelimit_parameters(
  507. feature_available, option_flag
  508. ):
  509. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  510. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  511. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  512. flexmock(module).should_receive('_expand_directories').and_return(())
  513. flexmock(module).should_receive('_expand_home_directories').and_return(())
  514. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  515. flexmock(module.feature).should_receive('available').and_return(feature_available)
  516. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  517. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  518. flexmock(module).should_receive('execute_command').with_args(
  519. ('borg', 'create', option_flag, '100') + ARCHIVE_WITH_PATHS,
  520. output_log_level=logging.INFO,
  521. output_file=None,
  522. borg_local_path='borg',
  523. )
  524. module.create_archive(
  525. dry_run=False,
  526. repository='repo',
  527. location_config={
  528. 'source_directories': ['foo', 'bar'],
  529. 'repositories': ['repo'],
  530. 'exclude_patterns': None,
  531. },
  532. storage_config={'remote_rate_limit': 100},
  533. local_borg_version='1.2.3',
  534. )
  535. def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
  536. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  537. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  538. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  539. flexmock(module).should_receive('_expand_directories').and_return(())
  540. flexmock(module).should_receive('_expand_home_directories').and_return(())
  541. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  542. flexmock(module.feature).should_receive('available').and_return(True)
  543. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  544. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  545. flexmock(module).should_receive('execute_command').with_args(
  546. ('borg', 'create', '--one-file-system') + ARCHIVE_WITH_PATHS,
  547. output_log_level=logging.INFO,
  548. output_file=None,
  549. borg_local_path='borg',
  550. )
  551. module.create_archive(
  552. dry_run=False,
  553. repository='repo',
  554. location_config={
  555. 'source_directories': ['foo', 'bar'],
  556. 'repositories': ['repo'],
  557. 'one_file_system': True,
  558. 'exclude_patterns': None,
  559. },
  560. storage_config={},
  561. local_borg_version='1.2.3',
  562. )
  563. @pytest.mark.parametrize(
  564. 'feature_available,option_flag', ((True, '--numeric-ids'), (False, '--numeric-owner')),
  565. )
  566. def test_create_archive_with_numeric_owner_calls_borg_with_numeric_ids_parameter(
  567. feature_available, option_flag
  568. ):
  569. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  570. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  571. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  572. flexmock(module).should_receive('_expand_directories').and_return(())
  573. flexmock(module).should_receive('_expand_home_directories').and_return(())
  574. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  575. flexmock(module.feature).should_receive('available').and_return(feature_available)
  576. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  577. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  578. flexmock(module).should_receive('execute_command').with_args(
  579. ('borg', 'create', option_flag) + ARCHIVE_WITH_PATHS,
  580. output_log_level=logging.INFO,
  581. output_file=None,
  582. borg_local_path='borg',
  583. )
  584. module.create_archive(
  585. dry_run=False,
  586. repository='repo',
  587. location_config={
  588. 'source_directories': ['foo', 'bar'],
  589. 'repositories': ['repo'],
  590. 'numeric_owner': True,
  591. 'exclude_patterns': None,
  592. },
  593. storage_config={},
  594. local_borg_version='1.2.3',
  595. )
  596. def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
  597. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  598. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  599. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  600. flexmock(module).should_receive('_expand_directories').and_return(())
  601. flexmock(module).should_receive('_expand_home_directories').and_return(())
  602. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  603. flexmock(module.feature).should_receive('available').and_return(True)
  604. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  605. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  606. flexmock(module).should_receive('execute_command').with_args(
  607. ('borg', 'create', '--read-special') + ARCHIVE_WITH_PATHS,
  608. output_log_level=logging.INFO,
  609. output_file=None,
  610. borg_local_path='borg',
  611. )
  612. module.create_archive(
  613. dry_run=False,
  614. repository='repo',
  615. location_config={
  616. 'source_directories': ['foo', 'bar'],
  617. 'repositories': ['repo'],
  618. 'read_special': True,
  619. 'exclude_patterns': None,
  620. },
  621. storage_config={},
  622. local_borg_version='1.2.3',
  623. )
  624. @pytest.mark.parametrize(
  625. 'option_name,option_value',
  626. (('ctime', True), ('ctime', False), ('birthtime', True), ('birthtime', False),),
  627. )
  628. def test_create_archive_with_basic_option_calls_borg_with_corresponding_parameter(
  629. option_name, option_value
  630. ):
  631. option_flag = '--no' + option_name.replace('_', '') if option_value is False else None
  632. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  633. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  634. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  635. flexmock(module).should_receive('_expand_directories').and_return(())
  636. flexmock(module).should_receive('_expand_home_directories').and_return(())
  637. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  638. flexmock(module.feature).should_receive('available').and_return(True)
  639. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  640. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  641. flexmock(module).should_receive('execute_command').with_args(
  642. ('borg', 'create') + ((option_flag,) if option_flag else ()) + ARCHIVE_WITH_PATHS,
  643. output_log_level=logging.INFO,
  644. output_file=None,
  645. borg_local_path='borg',
  646. )
  647. module.create_archive(
  648. dry_run=False,
  649. repository='repo',
  650. location_config={
  651. 'source_directories': ['foo', 'bar'],
  652. 'repositories': ['repo'],
  653. option_name: option_value,
  654. 'exclude_patterns': None,
  655. },
  656. storage_config={},
  657. local_borg_version='1.2.3',
  658. )
  659. @pytest.mark.parametrize(
  660. 'option_value,feature_available,option_flag',
  661. (
  662. (True, True, '--atime'),
  663. (True, False, None),
  664. (False, True, None),
  665. (False, False, '--noatime'),
  666. ),
  667. )
  668. def test_create_archive_with_atime_option_calls_borg_with_corresponding_parameter(
  669. option_value, feature_available, option_flag
  670. ):
  671. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  672. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  673. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  674. flexmock(module).should_receive('_expand_directories').and_return(())
  675. flexmock(module).should_receive('_expand_home_directories').and_return(())
  676. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  677. flexmock(module.feature).should_receive('available').and_return(feature_available)
  678. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  679. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  680. flexmock(module).should_receive('execute_command').with_args(
  681. ('borg', 'create') + ((option_flag,) if option_flag else ()) + ARCHIVE_WITH_PATHS,
  682. output_log_level=logging.INFO,
  683. output_file=None,
  684. borg_local_path='borg',
  685. )
  686. module.create_archive(
  687. dry_run=False,
  688. repository='repo',
  689. location_config={
  690. 'source_directories': ['foo', 'bar'],
  691. 'repositories': ['repo'],
  692. 'atime': option_value,
  693. 'exclude_patterns': None,
  694. },
  695. storage_config={},
  696. local_borg_version='1.2.3',
  697. )
  698. @pytest.mark.parametrize(
  699. 'option_value,feature_available,option_flag',
  700. (
  701. (True, True, None),
  702. (True, False, None),
  703. (False, True, '--noflags'),
  704. (False, False, '--nobsdflags'),
  705. ),
  706. )
  707. def test_create_archive_with_bsd_flags_option_calls_borg_with_corresponding_parameter(
  708. option_value, feature_available, option_flag
  709. ):
  710. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  711. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  712. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  713. flexmock(module).should_receive('_expand_directories').and_return(())
  714. flexmock(module).should_receive('_expand_home_directories').and_return(())
  715. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  716. flexmock(module.feature).should_receive('available').and_return(feature_available)
  717. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  718. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  719. flexmock(module).should_receive('execute_command').with_args(
  720. ('borg', 'create') + ((option_flag,) if option_flag else ()) + ARCHIVE_WITH_PATHS,
  721. output_log_level=logging.INFO,
  722. output_file=None,
  723. borg_local_path='borg',
  724. )
  725. module.create_archive(
  726. dry_run=False,
  727. repository='repo',
  728. location_config={
  729. 'source_directories': ['foo', 'bar'],
  730. 'repositories': ['repo'],
  731. 'bsd_flags': option_value,
  732. 'exclude_patterns': None,
  733. },
  734. storage_config={},
  735. local_borg_version='1.2.3',
  736. )
  737. def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
  738. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  739. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  740. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  741. flexmock(module).should_receive('_expand_directories').and_return(())
  742. flexmock(module).should_receive('_expand_home_directories').and_return(())
  743. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  744. flexmock(module.feature).should_receive('available').and_return(True)
  745. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  746. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  747. flexmock(module).should_receive('execute_command').with_args(
  748. ('borg', 'create', '--files-cache', 'ctime,size') + ARCHIVE_WITH_PATHS,
  749. output_log_level=logging.INFO,
  750. output_file=None,
  751. borg_local_path='borg',
  752. )
  753. module.create_archive(
  754. dry_run=False,
  755. repository='repo',
  756. location_config={
  757. 'source_directories': ['foo', 'bar'],
  758. 'repositories': ['repo'],
  759. 'files_cache': 'ctime,size',
  760. 'exclude_patterns': None,
  761. },
  762. storage_config={},
  763. local_borg_version='1.2.3',
  764. )
  765. def test_create_archive_with_local_path_calls_borg_via_local_path():
  766. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  767. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  768. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  769. flexmock(module).should_receive('_expand_directories').and_return(())
  770. flexmock(module).should_receive('_expand_home_directories').and_return(())
  771. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  772. flexmock(module.feature).should_receive('available').and_return(True)
  773. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  774. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  775. flexmock(module).should_receive('execute_command').with_args(
  776. ('borg1', 'create') + ARCHIVE_WITH_PATHS,
  777. output_log_level=logging.INFO,
  778. output_file=None,
  779. borg_local_path='borg1',
  780. )
  781. module.create_archive(
  782. dry_run=False,
  783. repository='repo',
  784. location_config={
  785. 'source_directories': ['foo', 'bar'],
  786. 'repositories': ['repo'],
  787. 'exclude_patterns': None,
  788. },
  789. storage_config={},
  790. local_borg_version='1.2.3',
  791. local_path='borg1',
  792. )
  793. def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
  794. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  795. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  796. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  797. flexmock(module).should_receive('_expand_directories').and_return(())
  798. flexmock(module).should_receive('_expand_home_directories').and_return(())
  799. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  800. flexmock(module.feature).should_receive('available').and_return(True)
  801. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  802. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  803. flexmock(module).should_receive('execute_command').with_args(
  804. ('borg', 'create', '--remote-path', 'borg1') + ARCHIVE_WITH_PATHS,
  805. output_log_level=logging.INFO,
  806. output_file=None,
  807. borg_local_path='borg',
  808. )
  809. module.create_archive(
  810. dry_run=False,
  811. repository='repo',
  812. location_config={
  813. 'source_directories': ['foo', 'bar'],
  814. 'repositories': ['repo'],
  815. 'exclude_patterns': None,
  816. },
  817. storage_config={},
  818. local_borg_version='1.2.3',
  819. remote_path='borg1',
  820. )
  821. def test_create_archive_with_umask_calls_borg_with_umask_parameters():
  822. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  823. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  824. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  825. flexmock(module).should_receive('_expand_directories').and_return(())
  826. flexmock(module).should_receive('_expand_home_directories').and_return(())
  827. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  828. flexmock(module.feature).should_receive('available').and_return(True)
  829. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  830. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  831. flexmock(module).should_receive('execute_command').with_args(
  832. ('borg', 'create', '--umask', '740') + ARCHIVE_WITH_PATHS,
  833. output_log_level=logging.INFO,
  834. output_file=None,
  835. borg_local_path='borg',
  836. )
  837. module.create_archive(
  838. dry_run=False,
  839. repository='repo',
  840. location_config={
  841. 'source_directories': ['foo', 'bar'],
  842. 'repositories': ['repo'],
  843. 'exclude_patterns': None,
  844. },
  845. storage_config={'umask': 740},
  846. local_borg_version='1.2.3',
  847. )
  848. def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
  849. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  850. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  851. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  852. flexmock(module).should_receive('_expand_directories').and_return(())
  853. flexmock(module).should_receive('_expand_home_directories').and_return(())
  854. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  855. flexmock(module.feature).should_receive('available').and_return(True)
  856. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  857. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  858. flexmock(module).should_receive('execute_command').with_args(
  859. ('borg', 'create', '--lock-wait', '5') + ARCHIVE_WITH_PATHS,
  860. output_log_level=logging.INFO,
  861. output_file=None,
  862. borg_local_path='borg',
  863. )
  864. module.create_archive(
  865. dry_run=False,
  866. repository='repo',
  867. location_config={
  868. 'source_directories': ['foo', 'bar'],
  869. 'repositories': ['repo'],
  870. 'exclude_patterns': None,
  871. },
  872. storage_config={'lock_wait': 5},
  873. local_borg_version='1.2.3',
  874. )
  875. def test_create_archive_with_stats_calls_borg_with_stats_parameter_and_warning_output_log_level():
  876. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  877. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  878. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  879. flexmock(module).should_receive('_expand_directories').and_return(())
  880. flexmock(module).should_receive('_expand_home_directories').and_return(())
  881. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  882. flexmock(module.feature).should_receive('available').and_return(True)
  883. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  884. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  885. flexmock(module).should_receive('execute_command').with_args(
  886. ('borg', 'create', '--stats') + ARCHIVE_WITH_PATHS,
  887. output_log_level=logging.WARNING,
  888. output_file=None,
  889. borg_local_path='borg',
  890. )
  891. module.create_archive(
  892. dry_run=False,
  893. repository='repo',
  894. location_config={
  895. 'source_directories': ['foo', 'bar'],
  896. 'repositories': ['repo'],
  897. 'exclude_patterns': None,
  898. },
  899. storage_config={},
  900. local_borg_version='1.2.3',
  901. stats=True,
  902. )
  903. def test_create_archive_with_stats_and_log_info_calls_borg_with_stats_parameter_and_info_output_log_level():
  904. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  905. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  906. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  907. flexmock(module).should_receive('_expand_directories').and_return(())
  908. flexmock(module).should_receive('_expand_home_directories').and_return(())
  909. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  910. flexmock(module.feature).should_receive('available').and_return(True)
  911. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  912. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  913. flexmock(module).should_receive('execute_command').with_args(
  914. ('borg', 'create', '--info', '--stats') + ARCHIVE_WITH_PATHS,
  915. output_log_level=logging.INFO,
  916. output_file=None,
  917. borg_local_path='borg',
  918. )
  919. insert_logging_mock(logging.INFO)
  920. module.create_archive(
  921. dry_run=False,
  922. repository='repo',
  923. location_config={
  924. 'source_directories': ['foo', 'bar'],
  925. 'repositories': ['repo'],
  926. 'exclude_patterns': None,
  927. },
  928. storage_config={},
  929. local_borg_version='1.2.3',
  930. stats=True,
  931. )
  932. def test_create_archive_with_files_calls_borg_with_list_parameter_and_warning_output_log_level():
  933. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  934. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  935. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  936. flexmock(module).should_receive('_expand_directories').and_return(())
  937. flexmock(module).should_receive('_expand_home_directories').and_return(())
  938. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  939. flexmock(module.feature).should_receive('available').and_return(True)
  940. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  941. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  942. flexmock(module).should_receive('execute_command').with_args(
  943. ('borg', 'create', '--list', '--filter', 'AME-') + ARCHIVE_WITH_PATHS,
  944. output_log_level=logging.WARNING,
  945. output_file=None,
  946. borg_local_path='borg',
  947. )
  948. module.create_archive(
  949. dry_run=False,
  950. repository='repo',
  951. location_config={
  952. 'source_directories': ['foo', 'bar'],
  953. 'repositories': ['repo'],
  954. 'exclude_patterns': None,
  955. },
  956. storage_config={},
  957. local_borg_version='1.2.3',
  958. files=True,
  959. )
  960. def test_create_archive_with_files_and_log_info_calls_borg_with_list_parameter_and_info_output_log_level():
  961. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  962. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  963. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  964. flexmock(module).should_receive('_expand_directories').and_return(())
  965. flexmock(module).should_receive('_expand_home_directories').and_return(())
  966. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  967. flexmock(module.feature).should_receive('available').and_return(True)
  968. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  969. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  970. flexmock(module).should_receive('execute_command').with_args(
  971. ('borg', 'create', '--list', '--filter', 'AME-', '--info') + ARCHIVE_WITH_PATHS,
  972. output_log_level=logging.INFO,
  973. output_file=None,
  974. borg_local_path='borg',
  975. )
  976. insert_logging_mock(logging.INFO)
  977. module.create_archive(
  978. dry_run=False,
  979. repository='repo',
  980. location_config={
  981. 'source_directories': ['foo', 'bar'],
  982. 'repositories': ['repo'],
  983. 'exclude_patterns': None,
  984. },
  985. storage_config={},
  986. local_borg_version='1.2.3',
  987. files=True,
  988. )
  989. def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_parameter_and_no_list():
  990. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  991. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  992. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  993. flexmock(module).should_receive('_expand_directories').and_return(())
  994. flexmock(module).should_receive('_expand_home_directories').and_return(())
  995. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  996. flexmock(module.feature).should_receive('available').and_return(True)
  997. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  998. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  999. flexmock(module).should_receive('execute_command').with_args(
  1000. ('borg', 'create', '--info', '--progress') + ARCHIVE_WITH_PATHS,
  1001. output_log_level=logging.INFO,
  1002. output_file=module.DO_NOT_CAPTURE,
  1003. borg_local_path='borg',
  1004. )
  1005. insert_logging_mock(logging.INFO)
  1006. module.create_archive(
  1007. dry_run=False,
  1008. repository='repo',
  1009. location_config={
  1010. 'source_directories': ['foo', 'bar'],
  1011. 'repositories': ['repo'],
  1012. 'exclude_patterns': None,
  1013. },
  1014. storage_config={},
  1015. local_borg_version='1.2.3',
  1016. progress=True,
  1017. )
  1018. def test_create_archive_with_progress_calls_borg_with_progress_parameter():
  1019. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1020. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1021. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1022. flexmock(module).should_receive('_expand_directories').and_return(())
  1023. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1024. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1025. flexmock(module.feature).should_receive('available').and_return(True)
  1026. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1027. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1028. flexmock(module).should_receive('execute_command').with_args(
  1029. ('borg', 'create', '--progress') + ARCHIVE_WITH_PATHS,
  1030. output_log_level=logging.INFO,
  1031. output_file=module.DO_NOT_CAPTURE,
  1032. borg_local_path='borg',
  1033. )
  1034. module.create_archive(
  1035. dry_run=False,
  1036. repository='repo',
  1037. location_config={
  1038. 'source_directories': ['foo', 'bar'],
  1039. 'repositories': ['repo'],
  1040. 'exclude_patterns': None,
  1041. },
  1042. storage_config={},
  1043. local_borg_version='1.2.3',
  1044. progress=True,
  1045. )
  1046. def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progress_parameter():
  1047. processes = flexmock()
  1048. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1049. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1050. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1051. flexmock(module).should_receive('_expand_directories').and_return(())
  1052. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1053. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1054. flexmock(module.feature).should_receive('available').and_return(True)
  1055. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1056. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1057. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1058. ('borg', 'create', '--one-file-system', '--read-special', '--progress')
  1059. + ARCHIVE_WITH_PATHS,
  1060. processes=processes,
  1061. output_log_level=logging.INFO,
  1062. output_file=module.DO_NOT_CAPTURE,
  1063. borg_local_path='borg',
  1064. )
  1065. module.create_archive(
  1066. dry_run=False,
  1067. repository='repo',
  1068. location_config={
  1069. 'source_directories': ['foo', 'bar'],
  1070. 'repositories': ['repo'],
  1071. 'exclude_patterns': None,
  1072. },
  1073. storage_config={},
  1074. local_borg_version='1.2.3',
  1075. progress=True,
  1076. stream_processes=processes,
  1077. )
  1078. def test_create_archive_with_json_calls_borg_with_json_parameter():
  1079. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1080. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1081. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1082. flexmock(module).should_receive('_expand_directories').and_return(())
  1083. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1084. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1085. flexmock(module.feature).should_receive('available').and_return(True)
  1086. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1087. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1088. flexmock(module).should_receive('execute_command').with_args(
  1089. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  1090. output_log_level=None,
  1091. output_file=None,
  1092. borg_local_path='borg',
  1093. ).and_return('[]')
  1094. json_output = module.create_archive(
  1095. dry_run=False,
  1096. repository='repo',
  1097. location_config={
  1098. 'source_directories': ['foo', 'bar'],
  1099. 'repositories': ['repo'],
  1100. 'exclude_patterns': None,
  1101. },
  1102. storage_config={},
  1103. local_borg_version='1.2.3',
  1104. json=True,
  1105. )
  1106. assert json_output == '[]'
  1107. def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter():
  1108. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1109. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1110. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1111. flexmock(module).should_receive('_expand_directories').and_return(())
  1112. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1113. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1114. flexmock(module.feature).should_receive('available').and_return(True)
  1115. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1116. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1117. flexmock(module).should_receive('execute_command').with_args(
  1118. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  1119. output_log_level=None,
  1120. output_file=None,
  1121. borg_local_path='borg',
  1122. ).and_return('[]')
  1123. json_output = module.create_archive(
  1124. dry_run=False,
  1125. repository='repo',
  1126. location_config={
  1127. 'source_directories': ['foo', 'bar'],
  1128. 'repositories': ['repo'],
  1129. 'exclude_patterns': None,
  1130. },
  1131. storage_config={},
  1132. local_borg_version='1.2.3',
  1133. json=True,
  1134. stats=True,
  1135. )
  1136. assert json_output == '[]'
  1137. def test_create_archive_with_source_directories_glob_expands():
  1138. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1139. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
  1140. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1141. flexmock(module).should_receive('_expand_directories').and_return(())
  1142. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1143. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1144. flexmock(module.feature).should_receive('available').and_return(True)
  1145. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1146. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1147. flexmock(module).should_receive('execute_command').with_args(
  1148. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  1149. output_log_level=logging.INFO,
  1150. output_file=None,
  1151. borg_local_path='borg',
  1152. )
  1153. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
  1154. module.create_archive(
  1155. dry_run=False,
  1156. repository='repo',
  1157. location_config={
  1158. 'source_directories': ['foo*'],
  1159. 'repositories': ['repo'],
  1160. 'exclude_patterns': None,
  1161. },
  1162. storage_config={},
  1163. local_borg_version='1.2.3',
  1164. )
  1165. def test_create_archive_with_non_matching_source_directories_glob_passes_through():
  1166. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1167. flexmock(module).should_receive('deduplicate_directories').and_return(('foo*',))
  1168. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1169. flexmock(module).should_receive('_expand_directories').and_return(())
  1170. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1171. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1172. flexmock(module.feature).should_receive('available').and_return(True)
  1173. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1174. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1175. flexmock(module).should_receive('execute_command').with_args(
  1176. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'),
  1177. output_log_level=logging.INFO,
  1178. output_file=None,
  1179. borg_local_path='borg',
  1180. )
  1181. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
  1182. module.create_archive(
  1183. dry_run=False,
  1184. repository='repo',
  1185. location_config={
  1186. 'source_directories': ['foo*'],
  1187. 'repositories': ['repo'],
  1188. 'exclude_patterns': None,
  1189. },
  1190. storage_config={},
  1191. local_borg_version='1.2.3',
  1192. )
  1193. def test_create_archive_with_glob_calls_borg_with_expanded_directories():
  1194. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1195. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
  1196. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1197. flexmock(module).should_receive('_expand_directories').and_return(())
  1198. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1199. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1200. flexmock(module.feature).should_receive('available').and_return(True)
  1201. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1202. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1203. flexmock(module).should_receive('execute_command').with_args(
  1204. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  1205. output_log_level=logging.INFO,
  1206. output_file=None,
  1207. borg_local_path='borg',
  1208. )
  1209. module.create_archive(
  1210. dry_run=False,
  1211. repository='repo',
  1212. location_config={
  1213. 'source_directories': ['foo*'],
  1214. 'repositories': ['repo'],
  1215. 'exclude_patterns': None,
  1216. },
  1217. storage_config={},
  1218. local_borg_version='1.2.3',
  1219. )
  1220. def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
  1221. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1222. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1223. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1224. flexmock(module).should_receive('_expand_directories').and_return(())
  1225. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1226. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1227. flexmock(module.feature).should_receive('available').and_return(True)
  1228. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1229. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1230. flexmock(module).should_receive('execute_command').with_args(
  1231. ('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'),
  1232. output_log_level=logging.INFO,
  1233. output_file=None,
  1234. borg_local_path='borg',
  1235. )
  1236. module.create_archive(
  1237. dry_run=False,
  1238. repository='repo',
  1239. location_config={
  1240. 'source_directories': ['foo', 'bar'],
  1241. 'repositories': ['repo'],
  1242. 'exclude_patterns': None,
  1243. },
  1244. storage_config={'archive_name_format': 'ARCHIVE_NAME'},
  1245. local_borg_version='1.2.3',
  1246. )
  1247. def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
  1248. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1249. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1250. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1251. flexmock(module).should_receive('_expand_directories').and_return(())
  1252. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1253. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1254. flexmock(module.feature).should_receive('available').and_return(True)
  1255. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1256. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1257. flexmock(module).should_receive('execute_command').with_args(
  1258. ('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'),
  1259. output_log_level=logging.INFO,
  1260. output_file=None,
  1261. borg_local_path='borg',
  1262. )
  1263. module.create_archive(
  1264. dry_run=False,
  1265. repository='repo',
  1266. location_config={
  1267. 'source_directories': ['foo', 'bar'],
  1268. 'repositories': ['repo'],
  1269. 'exclude_patterns': None,
  1270. },
  1271. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  1272. local_borg_version='1.2.3',
  1273. )
  1274. def test_create_archive_with_repository_accepts_borg_placeholders():
  1275. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1276. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1277. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1278. flexmock(module).should_receive('_expand_directories').and_return(())
  1279. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1280. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1281. flexmock(module.feature).should_receive('available').and_return(True)
  1282. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1283. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1284. flexmock(module).should_receive('execute_command').with_args(
  1285. ('borg', 'create', '{fqdn}::Documents_{hostname}-{now}', 'foo', 'bar'),
  1286. output_log_level=logging.INFO,
  1287. output_file=None,
  1288. borg_local_path='borg',
  1289. )
  1290. module.create_archive(
  1291. dry_run=False,
  1292. repository='{fqdn}',
  1293. location_config={
  1294. 'source_directories': ['foo', 'bar'],
  1295. 'repositories': ['{fqdn}'],
  1296. 'exclude_patterns': None,
  1297. },
  1298. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  1299. local_borg_version='1.2.3',
  1300. )
  1301. def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
  1302. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1303. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1304. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1305. flexmock(module).should_receive('_expand_directories').and_return(())
  1306. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1307. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1308. flexmock(module.feature).should_receive('available').and_return(True)
  1309. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1310. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1311. flexmock(module).should_receive('execute_command').with_args(
  1312. ('borg', 'create', '--extra', '--options') + ARCHIVE_WITH_PATHS,
  1313. output_log_level=logging.INFO,
  1314. output_file=None,
  1315. borg_local_path='borg',
  1316. )
  1317. module.create_archive(
  1318. dry_run=False,
  1319. repository='repo',
  1320. location_config={
  1321. 'source_directories': ['foo', 'bar'],
  1322. 'repositories': ['repo'],
  1323. 'exclude_patterns': None,
  1324. },
  1325. storage_config={'extra_borg_options': {'create': '--extra --options'}},
  1326. local_borg_version='1.2.3',
  1327. )
  1328. def test_create_archive_with_stream_processes_calls_borg_with_processes():
  1329. processes = flexmock()
  1330. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1331. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1332. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1333. flexmock(module).should_receive('_expand_directories').and_return(())
  1334. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1335. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1336. flexmock(module.feature).should_receive('available').and_return(True)
  1337. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1338. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1339. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1340. ('borg', 'create', '--one-file-system', '--read-special') + ARCHIVE_WITH_PATHS,
  1341. processes=processes,
  1342. output_log_level=logging.INFO,
  1343. output_file=None,
  1344. borg_local_path='borg',
  1345. )
  1346. module.create_archive(
  1347. dry_run=False,
  1348. repository='repo',
  1349. location_config={
  1350. 'source_directories': ['foo', 'bar'],
  1351. 'repositories': ['repo'],
  1352. 'exclude_patterns': None,
  1353. },
  1354. storage_config={},
  1355. local_borg_version='1.2.3',
  1356. stream_processes=processes,
  1357. )