2
0

test_create.py 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445
  1. import logging
  2. import sys
  3. import pytest
  4. from flexmock import flexmock
  5. from borgmatic.borg import create as module
  6. from ..test_verbosity import insert_logging_mock
  7. def test_expand_directory_with_basic_path_passes_it_through():
  8. flexmock(module.os.path).should_receive('expanduser').and_return('foo')
  9. flexmock(module.glob).should_receive('glob').and_return([])
  10. paths = module.expand_directory('foo')
  11. assert paths == ['foo']
  12. def test_expand_directory_with_glob_expands():
  13. flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
  14. flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
  15. paths = module.expand_directory('foo*')
  16. assert paths == ['foo', 'food']
  17. def test_expand_directories_flattens_expanded_directories():
  18. flexmock(module).should_receive('expand_directory').with_args('~/foo').and_return(['/root/foo'])
  19. flexmock(module).should_receive('expand_directory').with_args('bar*').and_return(
  20. ['bar', 'barf']
  21. )
  22. paths = module.expand_directories(('~/foo', 'bar*'))
  23. assert paths == ('/root/foo', 'bar', 'barf')
  24. def test_expand_directories_considers_none_as_no_directories():
  25. paths = module.expand_directories(None)
  26. assert paths == ()
  27. def test_expand_home_directories_expands_tildes():
  28. flexmock(module.os.path).should_receive('expanduser').with_args('~/bar').and_return('/foo/bar')
  29. flexmock(module.os.path).should_receive('expanduser').with_args('baz').and_return('baz')
  30. paths = module.expand_home_directories(('~/bar', 'baz'))
  31. assert paths == ('/foo/bar', 'baz')
  32. def test_expand_home_directories_considers_none_as_no_directories():
  33. paths = module.expand_home_directories(None)
  34. assert paths == ()
  35. def test_map_directories_to_devices_gives_device_id_per_path():
  36. flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
  37. flexmock(module.os).should_receive('stat').with_args('/bar').and_return(flexmock(st_dev=66))
  38. device_map = module.map_directories_to_devices(('/foo', '/bar'))
  39. assert device_map == {
  40. '/foo': 55,
  41. '/bar': 66,
  42. }
  43. def test_map_directories_to_devices_with_missing_path_does_not_error():
  44. flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
  45. flexmock(module.os).should_receive('stat').with_args('/bar').and_raise(FileNotFoundError)
  46. device_map = module.map_directories_to_devices(('/foo', '/bar'))
  47. assert device_map == {
  48. '/foo': 55,
  49. '/bar': None,
  50. }
  51. @pytest.mark.parametrize(
  52. 'directories,additional_directories,expected_directories',
  53. (
  54. ({'/': 1, '/root': 1}, {}, ('/',)),
  55. ({'/': 1, '/root/': 1}, {}, ('/',)),
  56. ({'/': 1, '/root': 2}, {}, ('/', '/root')),
  57. ({'/root': 1, '/': 1}, {}, ('/',)),
  58. ({'/root': 1, '/root/foo': 1}, {}, ('/root',)),
  59. ({'/root/': 1, '/root/foo': 1}, {}, ('/root/',)),
  60. ({'/root': 1, '/root/foo/': 1}, {}, ('/root',)),
  61. ({'/root': 1, '/root/foo': 2}, {}, ('/root', '/root/foo')),
  62. ({'/root/foo': 1, '/root': 1}, {}, ('/root',)),
  63. ({'/root': None, '/root/foo': None}, {}, ('/root', '/root/foo')),
  64. ({'/root': 1, '/etc': 1, '/root/foo/bar': 1}, {}, ('/etc', '/root')),
  65. ({'/root': 1, '/root/foo': 1, '/root/foo/bar': 1}, {}, ('/root',)),
  66. ({'/dup': 1, '/dup': 1}, {}, ('/dup',)),
  67. ({'/foo': 1, '/bar': 1}, {}, ('/bar', '/foo')),
  68. ({'/foo': 1, '/bar': 2}, {}, ('/bar', '/foo')),
  69. ({'/root/foo': 1}, {'/root': 1}, ()),
  70. ({'/root/foo': 1}, {'/root': 2}, ('/root/foo',)),
  71. ({'/root/foo': 1}, {}, ('/root/foo',)),
  72. ),
  73. )
  74. def test_deduplicate_directories_removes_child_paths_on_the_same_filesystem(
  75. directories, additional_directories, expected_directories
  76. ):
  77. assert (
  78. module.deduplicate_directories(directories, additional_directories) == expected_directories
  79. )
  80. def test_write_pattern_file_writes_pattern_lines():
  81. temporary_file = flexmock(name='filename', flush=lambda: None)
  82. temporary_file.should_receive('write').with_args('R /foo\n+ /foo/bar')
  83. flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
  84. module.write_pattern_file(['R /foo', '+ /foo/bar'])
  85. def test_write_pattern_file_with_sources_writes_sources_as_roots():
  86. temporary_file = flexmock(name='filename', flush=lambda: None)
  87. temporary_file.should_receive('write').with_args('R /foo\n+ /foo/bar\nR /baz\nR /quux')
  88. flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
  89. module.write_pattern_file(['R /foo', '+ /foo/bar'], sources=['/baz', '/quux'])
  90. def test_write_pattern_file_without_patterns_but_with_sources_writes_sources_as_roots():
  91. temporary_file = flexmock(name='filename', flush=lambda: None)
  92. temporary_file.should_receive('write').with_args('R /baz\nR /quux')
  93. flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
  94. module.write_pattern_file([], sources=['/baz', '/quux'])
  95. def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
  96. module.write_pattern_file([])
  97. def test_write_pattern_file_overwrites_existing_file():
  98. pattern_file = flexmock(name='filename', flush=lambda: None)
  99. pattern_file.should_receive('seek').with_args(0).once()
  100. pattern_file.should_receive('write').with_args('R /foo\n+ /foo/bar')
  101. flexmock(module.tempfile).should_receive('NamedTemporaryFile').never()
  102. module.write_pattern_file(['R /foo', '+ /foo/bar'], pattern_file=pattern_file)
  103. @pytest.mark.parametrize(
  104. 'filename_lists,opened_filenames',
  105. (
  106. ([('foo', 'bar'), ('baz', 'quux')], ('foo', 'bar', 'baz', 'quux')),
  107. ([None, ('foo', 'bar')], ('foo', 'bar')),
  108. ([None, None], ()),
  109. ),
  110. )
  111. def test_ensure_files_readable_opens_filenames(filename_lists, opened_filenames):
  112. for expected_filename in opened_filenames:
  113. flexmock(sys.modules['builtins']).should_receive('open').with_args(
  114. expected_filename
  115. ).and_return(flexmock(close=lambda: None))
  116. module.ensure_files_readable(*filename_lists)
  117. def test_make_pattern_flags_includes_pattern_filename_when_given():
  118. pattern_flags = module.make_pattern_flags(
  119. location_config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
  120. )
  121. assert pattern_flags == ('--patterns-from', '/tmp/patterns')
  122. def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
  123. pattern_flags = module.make_pattern_flags(
  124. location_config={'patterns_from': ['patterns', 'other']}
  125. )
  126. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
  127. def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
  128. pattern_flags = module.make_pattern_flags(
  129. location_config={'patterns_from': ['patterns']}, pattern_filename='/tmp/patterns'
  130. )
  131. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
  132. def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
  133. pattern_flags = module.make_pattern_flags(location_config={'patterns_from': None})
  134. assert pattern_flags == ()
  135. def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
  136. exclude_flags = module.make_exclude_flags(
  137. location_config={'exclude_patterns': ['*.pyc', '/var']}, exclude_filename='/tmp/excludes'
  138. )
  139. assert exclude_flags == ('--exclude-from', '/tmp/excludes')
  140. def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
  141. exclude_flags = module.make_exclude_flags(
  142. location_config={'exclude_from': ['excludes', 'other']}
  143. )
  144. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
  145. def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
  146. exclude_flags = module.make_exclude_flags(
  147. location_config={'exclude_from': ['excludes']}, exclude_filename='/tmp/excludes'
  148. )
  149. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
  150. def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
  151. exclude_flags = module.make_exclude_flags(location_config={'exclude_from': None})
  152. assert exclude_flags == ()
  153. def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
  154. exclude_flags = module.make_exclude_flags(location_config={'exclude_caches': True})
  155. assert exclude_flags == ('--exclude-caches',)
  156. def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
  157. exclude_flags = module.make_exclude_flags(location_config={'exclude_caches': False})
  158. assert exclude_flags == ()
  159. def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
  160. exclude_flags = module.make_exclude_flags(
  161. location_config={'exclude_if_present': ['exclude_me', 'also_me']}
  162. )
  163. assert exclude_flags == (
  164. '--exclude-if-present',
  165. 'exclude_me',
  166. '--exclude-if-present',
  167. 'also_me',
  168. )
  169. def test_make_exclude_flags_includes_keep_exclude_tags_when_true_in_config():
  170. exclude_flags = module.make_exclude_flags(location_config={'keep_exclude_tags': True})
  171. assert exclude_flags == ('--keep-exclude-tags',)
  172. def test_make_exclude_flags_does_not_include_keep_exclude_tags_when_false_in_config():
  173. exclude_flags = module.make_exclude_flags(location_config={'keep_exclude_tags': False})
  174. assert exclude_flags == ()
  175. def test_make_exclude_flags_includes_exclude_nodump_when_true_in_config():
  176. exclude_flags = module.make_exclude_flags(location_config={'exclude_nodump': True})
  177. assert exclude_flags == ('--exclude-nodump',)
  178. def test_make_exclude_flags_does_not_include_exclude_nodump_when_false_in_config():
  179. exclude_flags = module.make_exclude_flags(location_config={'exclude_nodump': False})
  180. assert exclude_flags == ()
  181. def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
  182. exclude_flags = module.make_exclude_flags(location_config={})
  183. assert exclude_flags == ()
  184. def test_collect_borgmatic_source_directories_set_when_directory_exists():
  185. flexmock(module.os.path).should_receive('exists').and_return(True)
  186. flexmock(module.os.path).should_receive('expanduser')
  187. assert module.collect_borgmatic_source_directories('/tmp') == ['/tmp']
  188. def test_collect_borgmatic_source_directories_empty_when_directory_does_not_exist():
  189. flexmock(module.os.path).should_receive('exists').and_return(False)
  190. flexmock(module.os.path).should_receive('expanduser')
  191. assert module.collect_borgmatic_source_directories('/tmp') == []
  192. def test_collect_borgmatic_source_directories_defaults_when_directory_not_given():
  193. flexmock(module.os.path).should_receive('exists').and_return(True)
  194. flexmock(module.os.path).should_receive('expanduser')
  195. assert module.collect_borgmatic_source_directories(None) == [
  196. module.state.DEFAULT_BORGMATIC_SOURCE_DIRECTORY
  197. ]
  198. def test_pattern_root_directories_deals_with_none_patterns():
  199. assert module.pattern_root_directories(patterns=None) == []
  200. def test_pattern_root_directories_parses_roots_and_ignores_others():
  201. assert module.pattern_root_directories(
  202. ['R /root', '+ /root/foo', '- /root/foo/bar', 'R /baz']
  203. ) == ['/root', '/baz']
  204. @pytest.mark.parametrize(
  205. 'character_device,block_device,fifo,expected_result',
  206. (
  207. (False, False, False, False),
  208. (True, False, False, True),
  209. (False, True, False, True),
  210. (True, True, False, True),
  211. (False, False, True, True),
  212. (False, True, True, True),
  213. (True, False, True, True),
  214. ),
  215. )
  216. def test_special_file_looks_at_file_type(character_device, block_device, fifo, expected_result):
  217. flexmock(module.os).should_receive('stat').and_return(flexmock(st_mode=flexmock()))
  218. flexmock(module.stat).should_receive('S_ISCHR').and_return(character_device)
  219. flexmock(module.stat).should_receive('S_ISBLK').and_return(block_device)
  220. flexmock(module.stat).should_receive('S_ISFIFO').and_return(fifo)
  221. assert module.special_file('/dev/special') == expected_result
  222. def test_special_file_treats_broken_symlink_as_non_special():
  223. flexmock(module.os).should_receive('stat').and_raise(FileNotFoundError)
  224. assert module.special_file('/broken/symlink') is False
  225. def test_any_parent_directories_treats_parents_as_match():
  226. module.any_parent_directories('/foo/bar.txt', ('/foo', '/etc'))
  227. def test_any_parent_directories_treats_grandparents_as_match():
  228. module.any_parent_directories('/foo/bar/baz.txt', ('/foo', '/etc'))
  229. def test_any_parent_directories_treats_unrelated_paths_as_non_match():
  230. module.any_parent_directories('/foo/bar.txt', ('/usr', '/etc'))
  231. def test_collect_special_file_paths_parses_special_files_from_borg_dry_run_file_list():
  232. flexmock(module).should_receive('execute_command_and_capture_output').and_return(
  233. 'Processing files ...\n- /foo\n+ /bar\n- /baz'
  234. )
  235. flexmock(module).should_receive('special_file').and_return(True)
  236. flexmock(module).should_receive('any_parent_directories').and_return(False)
  237. assert module.collect_special_file_paths(
  238. ('borg', 'create'),
  239. local_path=None,
  240. working_directory=None,
  241. borg_environment=None,
  242. skip_directories=flexmock(),
  243. ) == ('/foo', '/bar', '/baz')
  244. def test_collect_special_file_paths_excludes_requested_directories():
  245. flexmock(module).should_receive('execute_command_and_capture_output').and_return(
  246. '+ /foo\n- /bar\n- /baz'
  247. )
  248. flexmock(module).should_receive('special_file').and_return(True)
  249. flexmock(module).should_receive('any_parent_directories').and_return(False).and_return(
  250. True
  251. ).and_return(False)
  252. assert module.collect_special_file_paths(
  253. ('borg', 'create'),
  254. local_path=None,
  255. working_directory=None,
  256. borg_environment=None,
  257. skip_directories=flexmock(),
  258. ) == ('/foo', '/baz')
  259. def test_collect_special_file_paths_excludes_non_special_files():
  260. flexmock(module).should_receive('execute_command_and_capture_output').and_return(
  261. '+ /foo\n+ /bar\n+ /baz'
  262. )
  263. flexmock(module).should_receive('special_file').and_return(True).and_return(False).and_return(
  264. True
  265. )
  266. flexmock(module).should_receive('any_parent_directories').and_return(False)
  267. assert module.collect_special_file_paths(
  268. ('borg', 'create'),
  269. local_path=None,
  270. working_directory=None,
  271. borg_environment=None,
  272. skip_directories=flexmock(),
  273. ) == ('/foo', '/baz')
  274. DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
  275. REPO_ARCHIVE_WITH_PATHS = (f'repo::{DEFAULT_ARCHIVE_NAME}', 'foo', 'bar')
  276. def test_create_archive_calls_borg_with_parameters():
  277. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  278. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  279. flexmock(module).should_receive('collect_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('pattern_root_directories').and_return([])
  284. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  285. flexmock(module).should_receive('expand_home_directories').and_return(())
  286. flexmock(module).should_receive('write_pattern_file').and_return(None)
  287. flexmock(module.feature).should_receive('available').and_return(True)
  288. flexmock(module).should_receive('ensure_files_readable')
  289. flexmock(module).should_receive('make_pattern_flags').and_return(())
  290. flexmock(module).should_receive('make_exclude_flags').and_return(())
  291. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  292. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  293. )
  294. flexmock(module.environment).should_receive('make_environment')
  295. flexmock(module).should_receive('execute_command').with_args(
  296. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
  297. output_log_level=logging.INFO,
  298. output_file=None,
  299. borg_local_path='borg',
  300. working_directory=None,
  301. extra_environment=None,
  302. )
  303. module.create_archive(
  304. dry_run=False,
  305. repository='repo',
  306. location_config={
  307. 'source_directories': ['foo', 'bar'],
  308. 'repositories': ['repo'],
  309. 'exclude_patterns': None,
  310. },
  311. storage_config={},
  312. local_borg_version='1.2.3',
  313. )
  314. def test_create_archive_calls_borg_with_environment():
  315. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  316. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  317. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  318. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  319. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  320. flexmock(module).should_receive('expand_directories').and_return(())
  321. flexmock(module).should_receive('pattern_root_directories').and_return([])
  322. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  323. flexmock(module).should_receive('expand_home_directories').and_return(())
  324. flexmock(module).should_receive('write_pattern_file').and_return(None)
  325. flexmock(module.feature).should_receive('available').and_return(True)
  326. flexmock(module).should_receive('ensure_files_readable')
  327. flexmock(module).should_receive('make_pattern_flags').and_return(())
  328. flexmock(module).should_receive('make_exclude_flags').and_return(())
  329. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  330. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  331. )
  332. environment = {'BORG_THINGY': 'YUP'}
  333. flexmock(module.environment).should_receive('make_environment').and_return(environment)
  334. flexmock(module).should_receive('execute_command').with_args(
  335. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
  336. output_log_level=logging.INFO,
  337. output_file=None,
  338. borg_local_path='borg',
  339. working_directory=None,
  340. extra_environment=environment,
  341. )
  342. module.create_archive(
  343. dry_run=False,
  344. repository='repo',
  345. location_config={
  346. 'source_directories': ['foo', 'bar'],
  347. 'repositories': ['repo'],
  348. 'exclude_patterns': None,
  349. },
  350. storage_config={},
  351. local_borg_version='1.2.3',
  352. )
  353. def test_create_archive_with_patterns_calls_borg_with_patterns_including_converted_source_directories():
  354. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  355. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  356. pattern_flags = ('--patterns-from', 'patterns')
  357. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  358. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  359. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  360. flexmock(module).should_receive('expand_directories').and_return(())
  361. flexmock(module).should_receive('pattern_root_directories').and_return([])
  362. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  363. flexmock(module).should_receive('expand_home_directories').and_return(())
  364. flexmock(module).should_receive('write_pattern_file').and_return(
  365. flexmock(name='/tmp/patterns')
  366. ).and_return(None)
  367. flexmock(module.feature).should_receive('available').and_return(True)
  368. flexmock(module).should_receive('ensure_files_readable')
  369. flexmock(module).should_receive('make_pattern_flags').and_return(pattern_flags)
  370. flexmock(module).should_receive('make_exclude_flags').and_return(())
  371. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  372. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  373. )
  374. flexmock(module.environment).should_receive('make_environment')
  375. flexmock(module).should_receive('execute_command').with_args(
  376. ('borg', 'create') + pattern_flags + (f'repo::{DEFAULT_ARCHIVE_NAME}',),
  377. output_log_level=logging.INFO,
  378. output_file=None,
  379. borg_local_path='borg',
  380. working_directory=None,
  381. extra_environment=None,
  382. )
  383. module.create_archive(
  384. dry_run=False,
  385. repository='repo',
  386. location_config={
  387. 'source_directories': ['foo', 'bar'],
  388. 'repositories': ['repo'],
  389. 'patterns': ['pattern'],
  390. },
  391. storage_config={},
  392. local_borg_version='1.2.3',
  393. )
  394. def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
  395. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  396. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  397. exclude_flags = ('--exclude-from', 'excludes')
  398. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  399. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  400. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  401. flexmock(module).should_receive('expand_directories').and_return(())
  402. flexmock(module).should_receive('pattern_root_directories').and_return([])
  403. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  404. flexmock(module).should_receive('expand_home_directories').and_return(('exclude',))
  405. flexmock(module).should_receive('write_pattern_file').and_return(None).and_return(
  406. flexmock(name='/tmp/excludes')
  407. )
  408. flexmock(module.feature).should_receive('available').and_return(True)
  409. flexmock(module).should_receive('ensure_files_readable')
  410. flexmock(module).should_receive('make_pattern_flags').and_return(())
  411. flexmock(module).should_receive('make_exclude_flags').and_return(exclude_flags)
  412. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  413. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  414. )
  415. flexmock(module.environment).should_receive('make_environment')
  416. flexmock(module).should_receive('execute_command').with_args(
  417. ('borg', 'create') + exclude_flags + REPO_ARCHIVE_WITH_PATHS,
  418. output_log_level=logging.INFO,
  419. output_file=None,
  420. borg_local_path='borg',
  421. working_directory=None,
  422. extra_environment=None,
  423. )
  424. module.create_archive(
  425. dry_run=False,
  426. repository='repo',
  427. location_config={
  428. 'source_directories': ['foo', 'bar'],
  429. 'repositories': ['repo'],
  430. 'exclude_patterns': ['exclude'],
  431. },
  432. storage_config={},
  433. local_borg_version='1.2.3',
  434. )
  435. def test_create_archive_with_log_info_calls_borg_with_info_parameter():
  436. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  437. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  438. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  439. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  440. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  441. flexmock(module).should_receive('expand_directories').and_return(())
  442. flexmock(module).should_receive('pattern_root_directories').and_return([])
  443. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  444. flexmock(module).should_receive('expand_home_directories').and_return(())
  445. flexmock(module).should_receive('write_pattern_file').and_return(None)
  446. flexmock(module.feature).should_receive('available').and_return(True)
  447. flexmock(module).should_receive('ensure_files_readable')
  448. flexmock(module).should_receive('make_pattern_flags').and_return(())
  449. flexmock(module).should_receive('make_exclude_flags').and_return(())
  450. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  451. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  452. )
  453. flexmock(module.environment).should_receive('make_environment')
  454. flexmock(module).should_receive('execute_command').with_args(
  455. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--info',),
  456. output_log_level=logging.INFO,
  457. output_file=None,
  458. borg_local_path='borg',
  459. working_directory=None,
  460. extra_environment=None,
  461. )
  462. insert_logging_mock(logging.INFO)
  463. module.create_archive(
  464. dry_run=False,
  465. repository='repo',
  466. location_config={
  467. 'source_directories': ['foo', 'bar'],
  468. 'repositories': ['repo'],
  469. 'exclude_patterns': None,
  470. },
  471. storage_config={},
  472. local_borg_version='1.2.3',
  473. )
  474. def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
  475. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  476. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  477. flexmock(module).should_receive('collect_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('pattern_root_directories').and_return([])
  482. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  483. flexmock(module).should_receive('expand_home_directories').and_return(())
  484. flexmock(module).should_receive('write_pattern_file').and_return(None)
  485. flexmock(module.feature).should_receive('available').and_return(True)
  486. flexmock(module).should_receive('ensure_files_readable')
  487. flexmock(module).should_receive('make_pattern_flags').and_return(())
  488. flexmock(module).should_receive('make_exclude_flags').and_return(())
  489. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  490. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  491. )
  492. flexmock(module.environment).should_receive('make_environment')
  493. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  494. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',),
  495. working_directory=None,
  496. extra_environment=None,
  497. )
  498. insert_logging_mock(logging.INFO)
  499. module.create_archive(
  500. dry_run=False,
  501. repository='repo',
  502. location_config={
  503. 'source_directories': ['foo', 'bar'],
  504. 'repositories': ['repo'],
  505. 'exclude_patterns': None,
  506. },
  507. storage_config={},
  508. local_borg_version='1.2.3',
  509. json=True,
  510. )
  511. def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
  512. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  513. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  514. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  515. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  516. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  517. flexmock(module).should_receive('expand_directories').and_return(())
  518. flexmock(module).should_receive('pattern_root_directories').and_return([])
  519. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  520. flexmock(module).should_receive('expand_home_directories').and_return(())
  521. flexmock(module).should_receive('write_pattern_file').and_return(None)
  522. flexmock(module.feature).should_receive('available').and_return(True)
  523. flexmock(module).should_receive('ensure_files_readable')
  524. flexmock(module).should_receive('make_pattern_flags').and_return(())
  525. flexmock(module).should_receive('make_exclude_flags').and_return(())
  526. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  527. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  528. )
  529. flexmock(module.environment).should_receive('make_environment')
  530. flexmock(module).should_receive('execute_command').with_args(
  531. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--debug', '--show-rc'),
  532. output_log_level=logging.INFO,
  533. output_file=None,
  534. borg_local_path='borg',
  535. working_directory=None,
  536. extra_environment=None,
  537. )
  538. insert_logging_mock(logging.DEBUG)
  539. module.create_archive(
  540. dry_run=False,
  541. repository='repo',
  542. location_config={
  543. 'source_directories': ['foo', 'bar'],
  544. 'repositories': ['repo'],
  545. 'exclude_patterns': None,
  546. },
  547. storage_config={},
  548. local_borg_version='1.2.3',
  549. )
  550. def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
  551. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  552. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  553. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  554. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  555. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  556. flexmock(module).should_receive('expand_directories').and_return(())
  557. flexmock(module).should_receive('pattern_root_directories').and_return([])
  558. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  559. flexmock(module).should_receive('expand_home_directories').and_return(())
  560. flexmock(module).should_receive('write_pattern_file').and_return(None)
  561. flexmock(module.feature).should_receive('available').and_return(True)
  562. flexmock(module).should_receive('ensure_files_readable')
  563. flexmock(module).should_receive('make_pattern_flags').and_return(())
  564. flexmock(module).should_receive('make_exclude_flags').and_return(())
  565. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  566. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  567. )
  568. flexmock(module.environment).should_receive('make_environment')
  569. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  570. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',),
  571. working_directory=None,
  572. extra_environment=None,
  573. )
  574. insert_logging_mock(logging.DEBUG)
  575. module.create_archive(
  576. dry_run=False,
  577. repository='repo',
  578. location_config={
  579. 'source_directories': ['foo', 'bar'],
  580. 'repositories': ['repo'],
  581. 'exclude_patterns': None,
  582. },
  583. storage_config={},
  584. local_borg_version='1.2.3',
  585. json=True,
  586. )
  587. def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
  588. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  589. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  590. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  591. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  592. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  593. flexmock(module).should_receive('expand_directories').and_return(())
  594. flexmock(module).should_receive('pattern_root_directories').and_return([])
  595. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  596. flexmock(module).should_receive('expand_home_directories').and_return(())
  597. flexmock(module).should_receive('write_pattern_file').and_return(None)
  598. flexmock(module.feature).should_receive('available').and_return(True)
  599. flexmock(module).should_receive('ensure_files_readable')
  600. flexmock(module).should_receive('make_pattern_flags').and_return(())
  601. flexmock(module).should_receive('make_exclude_flags').and_return(())
  602. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  603. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  604. )
  605. flexmock(module.environment).should_receive('make_environment')
  606. flexmock(module).should_receive('execute_command').with_args(
  607. ('borg', 'create', '--dry-run') + REPO_ARCHIVE_WITH_PATHS,
  608. output_log_level=logging.INFO,
  609. output_file=None,
  610. borg_local_path='borg',
  611. working_directory=None,
  612. extra_environment=None,
  613. )
  614. module.create_archive(
  615. dry_run=True,
  616. repository='repo',
  617. location_config={
  618. 'source_directories': ['foo', 'bar'],
  619. 'repositories': ['repo'],
  620. 'exclude_patterns': None,
  621. },
  622. storage_config={},
  623. local_borg_version='1.2.3',
  624. )
  625. def test_create_archive_with_stats_and_dry_run_calls_borg_without_stats_parameter():
  626. # --dry-run and --stats are mutually exclusive, see:
  627. # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
  628. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  629. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  630. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  631. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  632. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  633. flexmock(module).should_receive('expand_directories').and_return(())
  634. flexmock(module).should_receive('pattern_root_directories').and_return([])
  635. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  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('ensure_files_readable')
  640. flexmock(module).should_receive('make_pattern_flags').and_return(())
  641. flexmock(module).should_receive('make_exclude_flags').and_return(())
  642. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  643. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  644. )
  645. flexmock(module.environment).should_receive('make_environment')
  646. flexmock(module).should_receive('execute_command').with_args(
  647. ('borg', 'create', '--dry-run') + REPO_ARCHIVE_WITH_PATHS + ('--info',),
  648. output_log_level=logging.INFO,
  649. output_file=None,
  650. borg_local_path='borg',
  651. working_directory=None,
  652. extra_environment=None,
  653. )
  654. insert_logging_mock(logging.INFO)
  655. module.create_archive(
  656. dry_run=True,
  657. repository='repo',
  658. location_config={
  659. 'source_directories': ['foo', 'bar'],
  660. 'repositories': ['repo'],
  661. 'exclude_patterns': None,
  662. },
  663. storage_config={},
  664. local_borg_version='1.2.3',
  665. stats=True,
  666. )
  667. def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
  668. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  669. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  670. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  671. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  672. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  673. flexmock(module).should_receive('expand_directories').and_return(())
  674. flexmock(module).should_receive('pattern_root_directories').and_return([])
  675. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  676. flexmock(module).should_receive('expand_home_directories').and_return(())
  677. flexmock(module).should_receive('write_pattern_file').and_return(None)
  678. flexmock(module.feature).should_receive('available').and_return(True)
  679. flexmock(module).should_receive('ensure_files_readable')
  680. flexmock(module).should_receive('make_pattern_flags').and_return(())
  681. flexmock(module).should_receive('make_exclude_flags').and_return(())
  682. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  683. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  684. )
  685. flexmock(module.environment).should_receive('make_environment')
  686. flexmock(module).should_receive('execute_command').with_args(
  687. ('borg', 'create', '--checkpoint-interval', '600') + REPO_ARCHIVE_WITH_PATHS,
  688. output_log_level=logging.INFO,
  689. output_file=None,
  690. borg_local_path='borg',
  691. working_directory=None,
  692. extra_environment=None,
  693. )
  694. module.create_archive(
  695. dry_run=False,
  696. repository='repo',
  697. location_config={
  698. 'source_directories': ['foo', 'bar'],
  699. 'repositories': ['repo'],
  700. 'exclude_patterns': None,
  701. },
  702. storage_config={'checkpoint_interval': 600},
  703. local_borg_version='1.2.3',
  704. )
  705. def test_create_archive_with_checkpoint_volume_calls_borg_with_checkpoint_volume_parameters():
  706. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  707. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  708. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  709. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  710. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  711. flexmock(module).should_receive('expand_directories').and_return(())
  712. flexmock(module).should_receive('pattern_root_directories').and_return([])
  713. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  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(True)
  717. flexmock(module).should_receive('ensure_files_readable')
  718. flexmock(module).should_receive('make_pattern_flags').and_return(())
  719. flexmock(module).should_receive('make_exclude_flags').and_return(())
  720. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  721. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  722. )
  723. flexmock(module.environment).should_receive('make_environment')
  724. flexmock(module).should_receive('execute_command').with_args(
  725. ('borg', 'create', '--checkpoint-volume', '1024') + REPO_ARCHIVE_WITH_PATHS,
  726. output_log_level=logging.INFO,
  727. output_file=None,
  728. borg_local_path='borg',
  729. working_directory=None,
  730. extra_environment=None,
  731. )
  732. module.create_archive(
  733. dry_run=False,
  734. repository='repo',
  735. location_config={
  736. 'source_directories': ['foo', 'bar'],
  737. 'repositories': ['repo'],
  738. 'exclude_patterns': None,
  739. },
  740. storage_config={'checkpoint_volume': 1024},
  741. local_borg_version='1.2.3',
  742. )
  743. def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_parameters():
  744. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  745. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  746. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  747. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  748. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  749. flexmock(module).should_receive('expand_directories').and_return(())
  750. flexmock(module).should_receive('pattern_root_directories').and_return([])
  751. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  752. flexmock(module).should_receive('expand_home_directories').and_return(())
  753. flexmock(module).should_receive('write_pattern_file').and_return(None)
  754. flexmock(module.feature).should_receive('available').and_return(True)
  755. flexmock(module).should_receive('ensure_files_readable')
  756. flexmock(module).should_receive('make_pattern_flags').and_return(())
  757. flexmock(module).should_receive('make_exclude_flags').and_return(())
  758. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  759. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  760. )
  761. flexmock(module.environment).should_receive('make_environment')
  762. flexmock(module).should_receive('execute_command').with_args(
  763. ('borg', 'create', '--chunker-params', '1,2,3,4') + REPO_ARCHIVE_WITH_PATHS,
  764. output_log_level=logging.INFO,
  765. output_file=None,
  766. borg_local_path='borg',
  767. working_directory=None,
  768. extra_environment=None,
  769. )
  770. module.create_archive(
  771. dry_run=False,
  772. repository='repo',
  773. location_config={
  774. 'source_directories': ['foo', 'bar'],
  775. 'repositories': ['repo'],
  776. 'exclude_patterns': None,
  777. },
  778. storage_config={'chunker_params': '1,2,3,4'},
  779. local_borg_version='1.2.3',
  780. )
  781. def test_create_archive_with_compression_calls_borg_with_compression_parameters():
  782. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  783. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  784. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  785. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  786. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  787. flexmock(module).should_receive('expand_directories').and_return(())
  788. flexmock(module).should_receive('pattern_root_directories').and_return([])
  789. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  790. flexmock(module).should_receive('expand_home_directories').and_return(())
  791. flexmock(module).should_receive('write_pattern_file').and_return(None)
  792. flexmock(module.feature).should_receive('available').and_return(True)
  793. flexmock(module).should_receive('ensure_files_readable')
  794. flexmock(module).should_receive('make_pattern_flags').and_return(())
  795. flexmock(module).should_receive('make_exclude_flags').and_return(())
  796. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  797. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  798. )
  799. flexmock(module.environment).should_receive('make_environment')
  800. flexmock(module).should_receive('execute_command').with_args(
  801. ('borg', 'create', '--compression', 'rle') + REPO_ARCHIVE_WITH_PATHS,
  802. output_log_level=logging.INFO,
  803. output_file=None,
  804. borg_local_path='borg',
  805. working_directory=None,
  806. extra_environment=None,
  807. )
  808. module.create_archive(
  809. dry_run=False,
  810. repository='repo',
  811. location_config={
  812. 'source_directories': ['foo', 'bar'],
  813. 'repositories': ['repo'],
  814. 'exclude_patterns': None,
  815. },
  816. storage_config={'compression': 'rle'},
  817. local_borg_version='1.2.3',
  818. )
  819. @pytest.mark.parametrize(
  820. 'feature_available,option_flag', ((True, '--upload-ratelimit'), (False, '--remote-ratelimit')),
  821. )
  822. def test_create_archive_with_upload_rate_limit_calls_borg_with_upload_ratelimit_parameters(
  823. feature_available, option_flag
  824. ):
  825. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  826. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  827. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  828. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  829. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  830. flexmock(module).should_receive('expand_directories').and_return(())
  831. flexmock(module).should_receive('pattern_root_directories').and_return([])
  832. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  833. flexmock(module).should_receive('expand_home_directories').and_return(())
  834. flexmock(module).should_receive('write_pattern_file').and_return(None)
  835. flexmock(module.feature).should_receive('available').and_return(feature_available)
  836. flexmock(module).should_receive('ensure_files_readable')
  837. flexmock(module).should_receive('make_pattern_flags').and_return(())
  838. flexmock(module).should_receive('make_exclude_flags').and_return(())
  839. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  840. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  841. )
  842. flexmock(module.environment).should_receive('make_environment')
  843. flexmock(module).should_receive('execute_command').with_args(
  844. ('borg', 'create', option_flag, '100') + REPO_ARCHIVE_WITH_PATHS,
  845. output_log_level=logging.INFO,
  846. output_file=None,
  847. borg_local_path='borg',
  848. working_directory=None,
  849. extra_environment=None,
  850. )
  851. module.create_archive(
  852. dry_run=False,
  853. repository='repo',
  854. location_config={
  855. 'source_directories': ['foo', 'bar'],
  856. 'repositories': ['repo'],
  857. 'exclude_patterns': None,
  858. },
  859. storage_config={'upload_rate_limit': 100},
  860. local_borg_version='1.2.3',
  861. )
  862. def test_create_archive_with_working_directory_calls_borg_with_working_directory():
  863. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  864. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  865. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  866. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  867. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  868. flexmock(module).should_receive('expand_directories').and_return(())
  869. flexmock(module).should_receive('pattern_root_directories').and_return([])
  870. flexmock(module.os.path).should_receive('expanduser').with_args('/working/dir').and_return(
  871. '/working/dir'
  872. )
  873. flexmock(module).should_receive('expand_home_directories').and_return(())
  874. flexmock(module).should_receive('write_pattern_file').and_return(None)
  875. flexmock(module.feature).should_receive('available').and_return(True)
  876. flexmock(module).should_receive('ensure_files_readable')
  877. flexmock(module).should_receive('make_pattern_flags').and_return(())
  878. flexmock(module).should_receive('make_exclude_flags').and_return(())
  879. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  880. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  881. )
  882. flexmock(module.environment).should_receive('make_environment')
  883. flexmock(module).should_receive('execute_command').with_args(
  884. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS,
  885. output_log_level=logging.INFO,
  886. output_file=None,
  887. borg_local_path='borg',
  888. working_directory='/working/dir',
  889. extra_environment=None,
  890. )
  891. module.create_archive(
  892. dry_run=False,
  893. repository='repo',
  894. location_config={
  895. 'source_directories': ['foo', 'bar'],
  896. 'repositories': ['repo'],
  897. 'working_directory': '/working/dir',
  898. 'exclude_patterns': None,
  899. },
  900. storage_config={},
  901. local_borg_version='1.2.3',
  902. )
  903. def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
  904. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  905. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  906. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  907. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  908. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  909. flexmock(module).should_receive('expand_directories').and_return(())
  910. flexmock(module).should_receive('pattern_root_directories').and_return([])
  911. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  912. flexmock(module).should_receive('expand_home_directories').and_return(())
  913. flexmock(module).should_receive('write_pattern_file').and_return(None)
  914. flexmock(module.feature).should_receive('available').and_return(True)
  915. flexmock(module).should_receive('ensure_files_readable')
  916. flexmock(module).should_receive('make_pattern_flags').and_return(())
  917. flexmock(module).should_receive('make_exclude_flags').and_return(())
  918. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  919. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  920. )
  921. flexmock(module.environment).should_receive('make_environment')
  922. flexmock(module).should_receive('execute_command').with_args(
  923. ('borg', 'create', '--one-file-system') + REPO_ARCHIVE_WITH_PATHS,
  924. output_log_level=logging.INFO,
  925. output_file=None,
  926. borg_local_path='borg',
  927. working_directory=None,
  928. extra_environment=None,
  929. )
  930. module.create_archive(
  931. dry_run=False,
  932. repository='repo',
  933. location_config={
  934. 'source_directories': ['foo', 'bar'],
  935. 'repositories': ['repo'],
  936. 'one_file_system': True,
  937. 'exclude_patterns': None,
  938. },
  939. storage_config={},
  940. local_borg_version='1.2.3',
  941. )
  942. @pytest.mark.parametrize(
  943. 'feature_available,option_flag', ((True, '--numeric-ids'), (False, '--numeric-owner')),
  944. )
  945. def test_create_archive_with_numeric_ids_calls_borg_with_numeric_ids_parameter(
  946. feature_available, option_flag
  947. ):
  948. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  949. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  950. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  951. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  952. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  953. flexmock(module).should_receive('expand_directories').and_return(())
  954. flexmock(module).should_receive('pattern_root_directories').and_return([])
  955. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  956. flexmock(module).should_receive('expand_home_directories').and_return(())
  957. flexmock(module).should_receive('write_pattern_file').and_return(None)
  958. flexmock(module.feature).should_receive('available').and_return(feature_available)
  959. flexmock(module).should_receive('ensure_files_readable')
  960. flexmock(module).should_receive('make_pattern_flags').and_return(())
  961. flexmock(module).should_receive('make_exclude_flags').and_return(())
  962. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  963. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  964. )
  965. flexmock(module.environment).should_receive('make_environment')
  966. flexmock(module).should_receive('execute_command').with_args(
  967. ('borg', 'create', option_flag) + REPO_ARCHIVE_WITH_PATHS,
  968. output_log_level=logging.INFO,
  969. output_file=None,
  970. borg_local_path='borg',
  971. working_directory=None,
  972. extra_environment=None,
  973. )
  974. module.create_archive(
  975. dry_run=False,
  976. repository='repo',
  977. location_config={
  978. 'source_directories': ['foo', 'bar'],
  979. 'repositories': ['repo'],
  980. 'numeric_ids': True,
  981. 'exclude_patterns': None,
  982. },
  983. storage_config={},
  984. local_borg_version='1.2.3',
  985. )
  986. def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
  987. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  988. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  989. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  990. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  991. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  992. flexmock(module).should_receive('expand_directories').and_return(())
  993. flexmock(module).should_receive('pattern_root_directories').and_return([])
  994. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  995. flexmock(module).should_receive('expand_home_directories').and_return(())
  996. flexmock(module).should_receive('write_pattern_file').and_return(None)
  997. flexmock(module.feature).should_receive('available').and_return(True)
  998. flexmock(module).should_receive('ensure_files_readable')
  999. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1000. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1001. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1002. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1003. )
  1004. flexmock(module.environment).should_receive('make_environment')
  1005. flexmock(module).should_receive('collect_special_file_paths').and_return(())
  1006. create_command = ('borg', 'create', '--read-special') + REPO_ARCHIVE_WITH_PATHS
  1007. flexmock(module).should_receive('execute_command').with_args(
  1008. create_command + ('--dry-run', '--list'),
  1009. output_log_level=logging.INFO,
  1010. output_file=None,
  1011. borg_local_path='borg',
  1012. working_directory=None,
  1013. extra_environment=None,
  1014. )
  1015. flexmock(module).should_receive('execute_command').with_args(
  1016. create_command,
  1017. output_log_level=logging.INFO,
  1018. output_file=None,
  1019. borg_local_path='borg',
  1020. working_directory=None,
  1021. extra_environment=None,
  1022. )
  1023. module.create_archive(
  1024. dry_run=False,
  1025. repository='repo',
  1026. location_config={
  1027. 'source_directories': ['foo', 'bar'],
  1028. 'repositories': ['repo'],
  1029. 'read_special': True,
  1030. 'exclude_patterns': None,
  1031. },
  1032. storage_config={},
  1033. local_borg_version='1.2.3',
  1034. )
  1035. @pytest.mark.parametrize(
  1036. 'option_name,option_value',
  1037. (('ctime', True), ('ctime', False), ('birthtime', True), ('birthtime', False),),
  1038. )
  1039. def test_create_archive_with_basic_option_calls_borg_with_corresponding_parameter(
  1040. option_name, option_value
  1041. ):
  1042. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1043. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1044. option_flag = '--no' + option_name.replace('', '') if option_value is False else None
  1045. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1046. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1047. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1048. flexmock(module).should_receive('expand_directories').and_return(())
  1049. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1050. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1051. flexmock(module).should_receive('expand_home_directories').and_return(())
  1052. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1053. flexmock(module.feature).should_receive('available').and_return(True)
  1054. flexmock(module).should_receive('ensure_files_readable')
  1055. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1056. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1057. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1058. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1059. )
  1060. flexmock(module.environment).should_receive('make_environment')
  1061. flexmock(module).should_receive('execute_command').with_args(
  1062. ('borg', 'create') + ((option_flag,) if option_flag else ()) + REPO_ARCHIVE_WITH_PATHS,
  1063. output_log_level=logging.INFO,
  1064. output_file=None,
  1065. borg_local_path='borg',
  1066. working_directory=None,
  1067. extra_environment=None,
  1068. )
  1069. module.create_archive(
  1070. dry_run=False,
  1071. repository='repo',
  1072. location_config={
  1073. 'source_directories': ['foo', 'bar'],
  1074. 'repositories': ['repo'],
  1075. option_name: option_value,
  1076. 'exclude_patterns': None,
  1077. },
  1078. storage_config={},
  1079. local_borg_version='1.2.3',
  1080. )
  1081. @pytest.mark.parametrize(
  1082. 'option_value,feature_available,option_flag',
  1083. (
  1084. (True, True, '--atime'),
  1085. (True, False, None),
  1086. (False, True, None),
  1087. (False, False, '--noatime'),
  1088. ),
  1089. )
  1090. def test_create_archive_with_atime_option_calls_borg_with_corresponding_parameter(
  1091. option_value, feature_available, option_flag
  1092. ):
  1093. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1094. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1095. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1096. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1097. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1098. flexmock(module).should_receive('expand_directories').and_return(())
  1099. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1100. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1101. flexmock(module).should_receive('expand_home_directories').and_return(())
  1102. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1103. flexmock(module.feature).should_receive('available').and_return(feature_available)
  1104. flexmock(module).should_receive('ensure_files_readable')
  1105. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1106. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1107. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1108. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1109. )
  1110. flexmock(module.environment).should_receive('make_environment')
  1111. flexmock(module).should_receive('execute_command').with_args(
  1112. ('borg', 'create') + ((option_flag,) if option_flag else ()) + REPO_ARCHIVE_WITH_PATHS,
  1113. output_log_level=logging.INFO,
  1114. output_file=None,
  1115. borg_local_path='borg',
  1116. working_directory=None,
  1117. extra_environment=None,
  1118. )
  1119. module.create_archive(
  1120. dry_run=False,
  1121. repository='repo',
  1122. location_config={
  1123. 'source_directories': ['foo', 'bar'],
  1124. 'repositories': ['repo'],
  1125. 'atime': option_value,
  1126. 'exclude_patterns': None,
  1127. },
  1128. storage_config={},
  1129. local_borg_version='1.2.3',
  1130. )
  1131. @pytest.mark.parametrize(
  1132. 'option_value,feature_available,option_flag',
  1133. (
  1134. (True, True, None),
  1135. (True, False, None),
  1136. (False, True, '--noflags'),
  1137. (False, False, '--nobsdflags'),
  1138. ),
  1139. )
  1140. def test_create_archive_with_flags_option_calls_borg_with_corresponding_parameter(
  1141. option_value, feature_available, option_flag
  1142. ):
  1143. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1144. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1145. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1146. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1147. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1148. flexmock(module).should_receive('expand_directories').and_return(())
  1149. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1150. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1151. flexmock(module).should_receive('expand_home_directories').and_return(())
  1152. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1153. flexmock(module.feature).should_receive('available').and_return(feature_available)
  1154. flexmock(module).should_receive('ensure_files_readable')
  1155. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1156. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1157. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1158. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1159. )
  1160. flexmock(module.environment).should_receive('make_environment')
  1161. flexmock(module).should_receive('execute_command').with_args(
  1162. ('borg', 'create') + ((option_flag,) if option_flag else ()) + REPO_ARCHIVE_WITH_PATHS,
  1163. output_log_level=logging.INFO,
  1164. output_file=None,
  1165. borg_local_path='borg',
  1166. working_directory=None,
  1167. extra_environment=None,
  1168. )
  1169. module.create_archive(
  1170. dry_run=False,
  1171. repository='repo',
  1172. location_config={
  1173. 'source_directories': ['foo', 'bar'],
  1174. 'repositories': ['repo'],
  1175. 'flags': option_value,
  1176. 'exclude_patterns': None,
  1177. },
  1178. storage_config={},
  1179. local_borg_version='1.2.3',
  1180. )
  1181. def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
  1182. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1183. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1184. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1185. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1186. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1187. flexmock(module).should_receive('expand_directories').and_return(())
  1188. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1189. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1190. flexmock(module).should_receive('expand_home_directories').and_return(())
  1191. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1192. flexmock(module.feature).should_receive('available').and_return(True)
  1193. flexmock(module).should_receive('ensure_files_readable')
  1194. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1195. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1196. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1197. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1198. )
  1199. flexmock(module.environment).should_receive('make_environment')
  1200. flexmock(module).should_receive('execute_command').with_args(
  1201. ('borg', 'create', '--files-cache', 'ctime,size') + REPO_ARCHIVE_WITH_PATHS,
  1202. output_log_level=logging.INFO,
  1203. output_file=None,
  1204. borg_local_path='borg',
  1205. working_directory=None,
  1206. extra_environment=None,
  1207. )
  1208. module.create_archive(
  1209. dry_run=False,
  1210. repository='repo',
  1211. location_config={
  1212. 'source_directories': ['foo', 'bar'],
  1213. 'repositories': ['repo'],
  1214. 'files_cache': 'ctime,size',
  1215. 'exclude_patterns': None,
  1216. },
  1217. storage_config={},
  1218. local_borg_version='1.2.3',
  1219. )
  1220. def test_create_archive_with_local_path_calls_borg_via_local_path():
  1221. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1222. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1223. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1224. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1225. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1226. flexmock(module).should_receive('expand_directories').and_return(())
  1227. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1228. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1229. flexmock(module).should_receive('expand_home_directories').and_return(())
  1230. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1231. flexmock(module.feature).should_receive('available').and_return(True)
  1232. flexmock(module).should_receive('ensure_files_readable')
  1233. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1234. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1235. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1236. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1237. )
  1238. flexmock(module.environment).should_receive('make_environment')
  1239. flexmock(module).should_receive('execute_command').with_args(
  1240. ('borg1', 'create') + REPO_ARCHIVE_WITH_PATHS,
  1241. output_log_level=logging.INFO,
  1242. output_file=None,
  1243. borg_local_path='borg1',
  1244. working_directory=None,
  1245. extra_environment=None,
  1246. )
  1247. module.create_archive(
  1248. dry_run=False,
  1249. repository='repo',
  1250. location_config={
  1251. 'source_directories': ['foo', 'bar'],
  1252. 'repositories': ['repo'],
  1253. 'exclude_patterns': None,
  1254. },
  1255. storage_config={},
  1256. local_borg_version='1.2.3',
  1257. local_path='borg1',
  1258. )
  1259. def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
  1260. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1261. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1262. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1263. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1264. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1265. flexmock(module).should_receive('expand_directories').and_return(())
  1266. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1267. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1268. flexmock(module).should_receive('expand_home_directories').and_return(())
  1269. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1270. flexmock(module.feature).should_receive('available').and_return(True)
  1271. flexmock(module).should_receive('ensure_files_readable')
  1272. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1273. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1274. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1275. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1276. )
  1277. flexmock(module.environment).should_receive('make_environment')
  1278. flexmock(module).should_receive('execute_command').with_args(
  1279. ('borg', 'create', '--remote-path', 'borg1') + REPO_ARCHIVE_WITH_PATHS,
  1280. output_log_level=logging.INFO,
  1281. output_file=None,
  1282. borg_local_path='borg',
  1283. working_directory=None,
  1284. extra_environment=None,
  1285. )
  1286. module.create_archive(
  1287. dry_run=False,
  1288. repository='repo',
  1289. location_config={
  1290. 'source_directories': ['foo', 'bar'],
  1291. 'repositories': ['repo'],
  1292. 'exclude_patterns': None,
  1293. },
  1294. storage_config={},
  1295. local_borg_version='1.2.3',
  1296. remote_path='borg1',
  1297. )
  1298. def test_create_archive_with_umask_calls_borg_with_umask_parameters():
  1299. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1300. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1301. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1302. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1303. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1304. flexmock(module).should_receive('expand_directories').and_return(())
  1305. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1306. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1307. flexmock(module).should_receive('expand_home_directories').and_return(())
  1308. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1309. flexmock(module.feature).should_receive('available').and_return(True)
  1310. flexmock(module).should_receive('ensure_files_readable')
  1311. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1312. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1313. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1314. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1315. )
  1316. flexmock(module.environment).should_receive('make_environment')
  1317. flexmock(module).should_receive('execute_command').with_args(
  1318. ('borg', 'create', '--umask', '740') + REPO_ARCHIVE_WITH_PATHS,
  1319. output_log_level=logging.INFO,
  1320. output_file=None,
  1321. borg_local_path='borg',
  1322. working_directory=None,
  1323. extra_environment=None,
  1324. )
  1325. module.create_archive(
  1326. dry_run=False,
  1327. repository='repo',
  1328. location_config={
  1329. 'source_directories': ['foo', 'bar'],
  1330. 'repositories': ['repo'],
  1331. 'exclude_patterns': None,
  1332. },
  1333. storage_config={'umask': 740},
  1334. local_borg_version='1.2.3',
  1335. )
  1336. def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
  1337. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1338. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1339. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1340. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1341. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1342. flexmock(module).should_receive('expand_directories').and_return(())
  1343. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1344. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1345. flexmock(module).should_receive('expand_home_directories').and_return(())
  1346. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1347. flexmock(module.feature).should_receive('available').and_return(True)
  1348. flexmock(module).should_receive('ensure_files_readable')
  1349. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1350. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1351. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1352. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1353. )
  1354. flexmock(module.environment).should_receive('make_environment')
  1355. flexmock(module).should_receive('execute_command').with_args(
  1356. ('borg', 'create', '--lock-wait', '5') + REPO_ARCHIVE_WITH_PATHS,
  1357. output_log_level=logging.INFO,
  1358. output_file=None,
  1359. borg_local_path='borg',
  1360. working_directory=None,
  1361. extra_environment=None,
  1362. )
  1363. module.create_archive(
  1364. dry_run=False,
  1365. repository='repo',
  1366. location_config={
  1367. 'source_directories': ['foo', 'bar'],
  1368. 'repositories': ['repo'],
  1369. 'exclude_patterns': None,
  1370. },
  1371. storage_config={'lock_wait': 5},
  1372. local_borg_version='1.2.3',
  1373. )
  1374. def test_create_archive_with_stats_calls_borg_with_stats_parameter_and_answer_output_log_level():
  1375. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1376. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1377. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1378. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1379. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1380. flexmock(module).should_receive('expand_directories').and_return(())
  1381. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1382. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1383. flexmock(module).should_receive('expand_home_directories').and_return(())
  1384. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1385. flexmock(module.feature).should_receive('available').and_return(True)
  1386. flexmock(module).should_receive('ensure_files_readable')
  1387. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1388. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1389. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1390. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1391. )
  1392. flexmock(module.environment).should_receive('make_environment')
  1393. flexmock(module).should_receive('execute_command').with_args(
  1394. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--stats',),
  1395. output_log_level=module.borgmatic.logger.ANSWER,
  1396. output_file=None,
  1397. borg_local_path='borg',
  1398. working_directory=None,
  1399. extra_environment=None,
  1400. )
  1401. module.create_archive(
  1402. dry_run=False,
  1403. repository='repo',
  1404. location_config={
  1405. 'source_directories': ['foo', 'bar'],
  1406. 'repositories': ['repo'],
  1407. 'exclude_patterns': None,
  1408. },
  1409. storage_config={},
  1410. local_borg_version='1.2.3',
  1411. stats=True,
  1412. )
  1413. def test_create_archive_with_files_calls_borg_with_list_parameter_and_answer_output_log_level():
  1414. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1415. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1416. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1417. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1418. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1419. flexmock(module).should_receive('expand_directories').and_return(())
  1420. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1421. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1422. flexmock(module).should_receive('expand_home_directories').and_return(())
  1423. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1424. flexmock(module.feature).should_receive('available').and_return(True)
  1425. flexmock(module).should_receive('ensure_files_readable')
  1426. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1427. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1428. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1429. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1430. )
  1431. flexmock(module.environment).should_receive('make_environment')
  1432. flexmock(module).should_receive('execute_command').with_args(
  1433. ('borg', 'create', '--list', '--filter', 'AMEx+-') + REPO_ARCHIVE_WITH_PATHS,
  1434. output_log_level=module.borgmatic.logger.ANSWER,
  1435. output_file=None,
  1436. borg_local_path='borg',
  1437. working_directory=None,
  1438. extra_environment=None,
  1439. )
  1440. module.create_archive(
  1441. dry_run=False,
  1442. repository='repo',
  1443. location_config={
  1444. 'source_directories': ['foo', 'bar'],
  1445. 'repositories': ['repo'],
  1446. 'exclude_patterns': None,
  1447. },
  1448. storage_config={},
  1449. local_borg_version='1.2.3',
  1450. list_files=True,
  1451. )
  1452. def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_parameter_and_no_list():
  1453. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1454. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1455. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1456. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1457. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1458. flexmock(module).should_receive('expand_directories').and_return(())
  1459. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1460. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1461. flexmock(module).should_receive('expand_home_directories').and_return(())
  1462. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1463. flexmock(module.feature).should_receive('available').and_return(True)
  1464. flexmock(module).should_receive('ensure_files_readable')
  1465. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1466. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1467. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1468. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1469. )
  1470. flexmock(module.environment).should_receive('make_environment')
  1471. flexmock(module).should_receive('execute_command').with_args(
  1472. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--info', '--progress',),
  1473. output_log_level=logging.INFO,
  1474. output_file=module.DO_NOT_CAPTURE,
  1475. borg_local_path='borg',
  1476. working_directory=None,
  1477. extra_environment=None,
  1478. )
  1479. insert_logging_mock(logging.INFO)
  1480. module.create_archive(
  1481. dry_run=False,
  1482. repository='repo',
  1483. location_config={
  1484. 'source_directories': ['foo', 'bar'],
  1485. 'repositories': ['repo'],
  1486. 'exclude_patterns': None,
  1487. },
  1488. storage_config={},
  1489. local_borg_version='1.2.3',
  1490. progress=True,
  1491. )
  1492. def test_create_archive_with_progress_calls_borg_with_progress_parameter():
  1493. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1494. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1495. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1496. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1497. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1498. flexmock(module).should_receive('expand_directories').and_return(())
  1499. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1500. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1501. flexmock(module).should_receive('expand_home_directories').and_return(())
  1502. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1503. flexmock(module.feature).should_receive('available').and_return(True)
  1504. flexmock(module).should_receive('ensure_files_readable')
  1505. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1506. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1507. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1508. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1509. )
  1510. flexmock(module.environment).should_receive('make_environment')
  1511. flexmock(module).should_receive('execute_command').with_args(
  1512. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--progress',),
  1513. output_log_level=logging.INFO,
  1514. output_file=module.DO_NOT_CAPTURE,
  1515. borg_local_path='borg',
  1516. working_directory=None,
  1517. extra_environment=None,
  1518. )
  1519. module.create_archive(
  1520. dry_run=False,
  1521. repository='repo',
  1522. location_config={
  1523. 'source_directories': ['foo', 'bar'],
  1524. 'repositories': ['repo'],
  1525. 'exclude_patterns': None,
  1526. },
  1527. storage_config={},
  1528. local_borg_version='1.2.3',
  1529. progress=True,
  1530. )
  1531. def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progress_parameter():
  1532. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1533. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1534. processes = flexmock()
  1535. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1536. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1537. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1538. flexmock(module).should_receive('expand_directories').and_return(())
  1539. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1540. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1541. flexmock(module).should_receive('expand_home_directories').and_return(())
  1542. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1543. flexmock(module.feature).should_receive('available').and_return(True)
  1544. flexmock(module).should_receive('ensure_files_readable')
  1545. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1546. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1547. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1548. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1549. )
  1550. flexmock(module.environment).should_receive('make_environment')
  1551. flexmock(module).should_receive('collect_special_file_paths').and_return(())
  1552. create_command = (
  1553. ('borg', 'create', '--one-file-system', '--read-special')
  1554. + REPO_ARCHIVE_WITH_PATHS
  1555. + ('--progress',)
  1556. )
  1557. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1558. create_command + ('--dry-run', '--list'),
  1559. processes=processes,
  1560. output_log_level=logging.INFO,
  1561. output_file=module.DO_NOT_CAPTURE,
  1562. borg_local_path='borg',
  1563. working_directory=None,
  1564. extra_environment=None,
  1565. )
  1566. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1567. create_command,
  1568. processes=processes,
  1569. output_log_level=logging.INFO,
  1570. output_file=module.DO_NOT_CAPTURE,
  1571. borg_local_path='borg',
  1572. working_directory=None,
  1573. extra_environment=None,
  1574. )
  1575. module.create_archive(
  1576. dry_run=False,
  1577. repository='repo',
  1578. location_config={
  1579. 'source_directories': ['foo', 'bar'],
  1580. 'repositories': ['repo'],
  1581. 'exclude_patterns': None,
  1582. },
  1583. storage_config={},
  1584. local_borg_version='1.2.3',
  1585. progress=True,
  1586. stream_processes=processes,
  1587. )
  1588. def test_create_archive_with_stream_processes_ignores_read_special_false_and_logs_warnings():
  1589. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1590. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1591. processes = flexmock()
  1592. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1593. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1594. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1595. flexmock(module).should_receive('expand_directories').and_return(())
  1596. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1597. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1598. flexmock(module).should_receive('expand_home_directories').and_return(())
  1599. flexmock(module).should_receive('write_pattern_file').and_return(flexmock(name='/tmp/excludes'))
  1600. flexmock(module.feature).should_receive('available').and_return(True)
  1601. flexmock(module).should_receive('ensure_files_readable')
  1602. flexmock(module.logger).should_receive('warning').twice()
  1603. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1604. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1605. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1606. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1607. )
  1608. flexmock(module.environment).should_receive('make_environment')
  1609. flexmock(module).should_receive('collect_special_file_paths').and_return(("/dev/null",))
  1610. create_command = (
  1611. 'borg',
  1612. 'create',
  1613. '--one-file-system',
  1614. '--read-special',
  1615. ) + REPO_ARCHIVE_WITH_PATHS
  1616. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1617. create_command + ('--dry-run', '--list'),
  1618. processes=processes,
  1619. output_log_level=logging.INFO,
  1620. output_file=None,
  1621. borg_local_path='borg',
  1622. working_directory=None,
  1623. extra_environment=None,
  1624. )
  1625. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1626. create_command,
  1627. processes=processes,
  1628. output_log_level=logging.INFO,
  1629. output_file=None,
  1630. borg_local_path='borg',
  1631. working_directory=None,
  1632. extra_environment=None,
  1633. )
  1634. module.create_archive(
  1635. dry_run=False,
  1636. repository='repo',
  1637. location_config={
  1638. 'source_directories': ['foo', 'bar'],
  1639. 'repositories': ['repo'],
  1640. 'exclude_patterns': None,
  1641. 'read_special': False,
  1642. },
  1643. storage_config={},
  1644. local_borg_version='1.2.3',
  1645. stream_processes=processes,
  1646. )
  1647. def test_create_archive_with_stream_processes_adds_special_files_to_excludes():
  1648. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1649. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1650. processes = flexmock()
  1651. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1652. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1653. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1654. flexmock(module).should_receive('expand_directories').and_return(())
  1655. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1656. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1657. flexmock(module).should_receive('expand_home_directories').and_return(()).and_return(
  1658. ('special',)
  1659. )
  1660. flexmock(module).should_receive('write_pattern_file').and_return(None).and_return(
  1661. flexmock(name='/excludes')
  1662. )
  1663. flexmock(module.feature).should_receive('available').and_return(True)
  1664. flexmock(module).should_receive('ensure_files_readable')
  1665. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1666. flexmock(module).should_receive('make_exclude_flags').and_return(()).and_return(
  1667. '--exclude-from', '/excludes'
  1668. )
  1669. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1670. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1671. )
  1672. flexmock(module.environment).should_receive('make_environment')
  1673. flexmock(module).should_receive('collect_special_file_paths').and_return(('special',))
  1674. create_command = (
  1675. 'borg',
  1676. 'create',
  1677. '--one-file-system',
  1678. '--read-special',
  1679. ) + REPO_ARCHIVE_WITH_PATHS
  1680. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1681. create_command + ('--dry-run', '--list'),
  1682. processes=processes,
  1683. output_log_level=logging.INFO,
  1684. output_file=None,
  1685. borg_local_path='borg',
  1686. working_directory=None,
  1687. extra_environment=None,
  1688. )
  1689. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1690. create_command + ('--exclude-from', '/excludes'),
  1691. processes=processes,
  1692. output_log_level=logging.INFO,
  1693. output_file=None,
  1694. borg_local_path='borg',
  1695. working_directory=None,
  1696. extra_environment=None,
  1697. )
  1698. module.create_archive(
  1699. dry_run=False,
  1700. repository='repo',
  1701. location_config={
  1702. 'source_directories': ['foo', 'bar'],
  1703. 'repositories': ['repo'],
  1704. 'exclude_patterns': None,
  1705. },
  1706. storage_config={},
  1707. local_borg_version='1.2.3',
  1708. stream_processes=processes,
  1709. )
  1710. def test_create_archive_with_stream_processes_and_read_special_does_not_add_special_files_to_excludes():
  1711. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1712. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1713. processes = flexmock()
  1714. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1715. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1716. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1717. flexmock(module).should_receive('expand_directories').and_return(())
  1718. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1719. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1720. flexmock(module).should_receive('expand_home_directories').and_return(()).and_return(
  1721. ('special',)
  1722. )
  1723. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1724. flexmock(module.feature).should_receive('available').and_return(True)
  1725. flexmock(module).should_receive('ensure_files_readable')
  1726. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1727. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1728. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1729. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1730. )
  1731. flexmock(module.environment).should_receive('make_environment')
  1732. flexmock(module).should_receive('collect_special_file_paths').and_return(('special',))
  1733. create_command = (
  1734. 'borg',
  1735. 'create',
  1736. '--one-file-system',
  1737. '--read-special',
  1738. ) + REPO_ARCHIVE_WITH_PATHS
  1739. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1740. create_command + ('--dry-run', '--list'),
  1741. processes=processes,
  1742. output_log_level=logging.INFO,
  1743. output_file=None,
  1744. borg_local_path='borg',
  1745. working_directory=None,
  1746. extra_environment=None,
  1747. )
  1748. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1749. create_command,
  1750. processes=processes,
  1751. output_log_level=logging.INFO,
  1752. output_file=None,
  1753. borg_local_path='borg',
  1754. working_directory=None,
  1755. extra_environment=None,
  1756. )
  1757. module.create_archive(
  1758. dry_run=False,
  1759. repository='repo',
  1760. location_config={
  1761. 'source_directories': ['foo', 'bar'],
  1762. 'repositories': ['repo'],
  1763. 'exclude_patterns': None,
  1764. 'read_special': True,
  1765. },
  1766. storage_config={},
  1767. local_borg_version='1.2.3',
  1768. stream_processes=processes,
  1769. )
  1770. def test_create_archive_with_json_calls_borg_with_json_parameter():
  1771. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1772. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1773. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1774. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1775. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1776. flexmock(module).should_receive('expand_directories').and_return(())
  1777. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1778. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1779. flexmock(module).should_receive('expand_home_directories').and_return(())
  1780. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1781. flexmock(module.feature).should_receive('available').and_return(True)
  1782. flexmock(module).should_receive('ensure_files_readable')
  1783. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1784. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1785. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1786. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1787. )
  1788. flexmock(module.environment).should_receive('make_environment')
  1789. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  1790. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',),
  1791. working_directory=None,
  1792. extra_environment=None,
  1793. ).and_return('[]')
  1794. json_output = module.create_archive(
  1795. dry_run=False,
  1796. repository='repo',
  1797. location_config={
  1798. 'source_directories': ['foo', 'bar'],
  1799. 'repositories': ['repo'],
  1800. 'exclude_patterns': None,
  1801. },
  1802. storage_config={},
  1803. local_borg_version='1.2.3',
  1804. json=True,
  1805. )
  1806. assert json_output == '[]'
  1807. def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter():
  1808. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1809. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1810. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1811. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1812. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1813. flexmock(module).should_receive('expand_directories').and_return(())
  1814. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1815. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1816. flexmock(module).should_receive('expand_home_directories').and_return(())
  1817. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1818. flexmock(module.feature).should_receive('available').and_return(True)
  1819. flexmock(module).should_receive('ensure_files_readable')
  1820. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1821. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1822. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1823. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1824. )
  1825. flexmock(module.environment).should_receive('make_environment')
  1826. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  1827. ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',),
  1828. working_directory=None,
  1829. extra_environment=None,
  1830. ).and_return('[]')
  1831. json_output = module.create_archive(
  1832. dry_run=False,
  1833. repository='repo',
  1834. location_config={
  1835. 'source_directories': ['foo', 'bar'],
  1836. 'repositories': ['repo'],
  1837. 'exclude_patterns': None,
  1838. },
  1839. storage_config={},
  1840. local_borg_version='1.2.3',
  1841. json=True,
  1842. stats=True,
  1843. )
  1844. assert json_output == '[]'
  1845. def test_create_archive_with_source_directories_glob_expands():
  1846. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1847. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1848. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1849. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
  1850. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1851. flexmock(module).should_receive('expand_directories').and_return(())
  1852. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1853. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1854. flexmock(module).should_receive('expand_home_directories').and_return(())
  1855. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1856. flexmock(module.feature).should_receive('available').and_return(True)
  1857. flexmock(module).should_receive('ensure_files_readable')
  1858. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1859. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1860. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1861. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1862. )
  1863. flexmock(module.environment).should_receive('make_environment')
  1864. flexmock(module).should_receive('execute_command').with_args(
  1865. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  1866. output_log_level=logging.INFO,
  1867. output_file=None,
  1868. borg_local_path='borg',
  1869. working_directory=None,
  1870. extra_environment=None,
  1871. )
  1872. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
  1873. module.create_archive(
  1874. dry_run=False,
  1875. repository='repo',
  1876. location_config={
  1877. 'source_directories': ['foo*'],
  1878. 'repositories': ['repo'],
  1879. 'exclude_patterns': None,
  1880. },
  1881. storage_config={},
  1882. local_borg_version='1.2.3',
  1883. )
  1884. def test_create_archive_with_non_matching_source_directories_glob_passes_through():
  1885. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1886. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1887. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1888. flexmock(module).should_receive('deduplicate_directories').and_return(('foo*',))
  1889. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1890. flexmock(module).should_receive('expand_directories').and_return(())
  1891. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1892. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1893. flexmock(module).should_receive('expand_home_directories').and_return(())
  1894. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1895. flexmock(module.feature).should_receive('available').and_return(True)
  1896. flexmock(module).should_receive('ensure_files_readable')
  1897. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1898. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1899. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1900. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1901. )
  1902. flexmock(module.environment).should_receive('make_environment')
  1903. flexmock(module).should_receive('execute_command').with_args(
  1904. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'),
  1905. output_log_level=logging.INFO,
  1906. output_file=None,
  1907. borg_local_path='borg',
  1908. working_directory=None,
  1909. extra_environment=None,
  1910. )
  1911. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
  1912. module.create_archive(
  1913. dry_run=False,
  1914. repository='repo',
  1915. location_config={
  1916. 'source_directories': ['foo*'],
  1917. 'repositories': ['repo'],
  1918. 'exclude_patterns': None,
  1919. },
  1920. storage_config={},
  1921. local_borg_version='1.2.3',
  1922. )
  1923. def test_create_archive_with_glob_calls_borg_with_expanded_directories():
  1924. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1925. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1926. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1927. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
  1928. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1929. flexmock(module).should_receive('expand_directories').and_return(())
  1930. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1931. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1932. flexmock(module).should_receive('expand_home_directories').and_return(())
  1933. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1934. flexmock(module.feature).should_receive('available').and_return(True)
  1935. flexmock(module).should_receive('ensure_files_readable')
  1936. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1937. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1938. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1939. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  1940. )
  1941. flexmock(module.environment).should_receive('make_environment')
  1942. flexmock(module).should_receive('execute_command').with_args(
  1943. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  1944. output_log_level=logging.INFO,
  1945. output_file=None,
  1946. borg_local_path='borg',
  1947. working_directory=None,
  1948. extra_environment=None,
  1949. )
  1950. module.create_archive(
  1951. dry_run=False,
  1952. repository='repo',
  1953. location_config={
  1954. 'source_directories': ['foo*'],
  1955. 'repositories': ['repo'],
  1956. 'exclude_patterns': None,
  1957. },
  1958. storage_config={},
  1959. local_borg_version='1.2.3',
  1960. )
  1961. def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
  1962. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  1963. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  1964. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  1965. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1966. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1967. flexmock(module).should_receive('expand_directories').and_return(())
  1968. flexmock(module).should_receive('pattern_root_directories').and_return([])
  1969. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  1970. flexmock(module).should_receive('expand_home_directories').and_return(())
  1971. flexmock(module).should_receive('write_pattern_file').and_return(None)
  1972. flexmock(module.feature).should_receive('available').and_return(True)
  1973. flexmock(module).should_receive('ensure_files_readable')
  1974. flexmock(module).should_receive('make_pattern_flags').and_return(())
  1975. flexmock(module).should_receive('make_exclude_flags').and_return(())
  1976. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  1977. ('repo::ARCHIVE_NAME',)
  1978. )
  1979. flexmock(module.environment).should_receive('make_environment')
  1980. flexmock(module).should_receive('execute_command').with_args(
  1981. ('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'),
  1982. output_log_level=logging.INFO,
  1983. output_file=None,
  1984. borg_local_path='borg',
  1985. working_directory=None,
  1986. extra_environment=None,
  1987. )
  1988. module.create_archive(
  1989. dry_run=False,
  1990. repository='repo',
  1991. location_config={
  1992. 'source_directories': ['foo', 'bar'],
  1993. 'repositories': ['repo'],
  1994. 'exclude_patterns': None,
  1995. },
  1996. storage_config={'archive_name_format': 'ARCHIVE_NAME'},
  1997. local_borg_version='1.2.3',
  1998. )
  1999. def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
  2000. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  2001. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  2002. repository_archive_pattern = 'repo::Documents_{hostname}-{now}'
  2003. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  2004. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  2005. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  2006. flexmock(module).should_receive('expand_directories').and_return(())
  2007. flexmock(module).should_receive('pattern_root_directories').and_return([])
  2008. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  2009. flexmock(module).should_receive('expand_home_directories').and_return(())
  2010. flexmock(module).should_receive('write_pattern_file').and_return(None)
  2011. flexmock(module.feature).should_receive('available').and_return(True)
  2012. flexmock(module).should_receive('ensure_files_readable')
  2013. flexmock(module).should_receive('make_pattern_flags').and_return(())
  2014. flexmock(module).should_receive('make_exclude_flags').and_return(())
  2015. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  2016. (repository_archive_pattern,)
  2017. )
  2018. flexmock(module.environment).should_receive('make_environment')
  2019. flexmock(module).should_receive('execute_command').with_args(
  2020. ('borg', 'create', repository_archive_pattern, 'foo', 'bar'),
  2021. output_log_level=logging.INFO,
  2022. output_file=None,
  2023. borg_local_path='borg',
  2024. working_directory=None,
  2025. extra_environment=None,
  2026. )
  2027. module.create_archive(
  2028. dry_run=False,
  2029. repository='repo',
  2030. location_config={
  2031. 'source_directories': ['foo', 'bar'],
  2032. 'repositories': ['repo'],
  2033. 'exclude_patterns': None,
  2034. },
  2035. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  2036. local_borg_version='1.2.3',
  2037. )
  2038. def test_create_archive_with_repository_accepts_borg_placeholders():
  2039. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  2040. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  2041. repository_archive_pattern = '{fqdn}::Documents_{hostname}-{now}'
  2042. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  2043. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  2044. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  2045. flexmock(module).should_receive('expand_directories').and_return(())
  2046. flexmock(module).should_receive('pattern_root_directories').and_return([])
  2047. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  2048. flexmock(module).should_receive('expand_home_directories').and_return(())
  2049. flexmock(module).should_receive('write_pattern_file').and_return(None)
  2050. flexmock(module.feature).should_receive('available').and_return(True)
  2051. flexmock(module).should_receive('ensure_files_readable')
  2052. flexmock(module).should_receive('make_pattern_flags').and_return(())
  2053. flexmock(module).should_receive('make_exclude_flags').and_return(())
  2054. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  2055. (repository_archive_pattern,)
  2056. )
  2057. flexmock(module.environment).should_receive('make_environment')
  2058. flexmock(module).should_receive('execute_command').with_args(
  2059. ('borg', 'create', repository_archive_pattern, 'foo', 'bar'),
  2060. output_log_level=logging.INFO,
  2061. output_file=None,
  2062. borg_local_path='borg',
  2063. working_directory=None,
  2064. extra_environment=None,
  2065. )
  2066. module.create_archive(
  2067. dry_run=False,
  2068. repository='{fqdn}',
  2069. location_config={
  2070. 'source_directories': ['foo', 'bar'],
  2071. 'repositories': ['{fqdn}'],
  2072. 'exclude_patterns': None,
  2073. },
  2074. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  2075. local_borg_version='1.2.3',
  2076. )
  2077. def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
  2078. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  2079. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  2080. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  2081. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  2082. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  2083. flexmock(module).should_receive('expand_directories').and_return(())
  2084. flexmock(module).should_receive('pattern_root_directories').and_return([])
  2085. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  2086. flexmock(module).should_receive('expand_home_directories').and_return(())
  2087. flexmock(module).should_receive('write_pattern_file').and_return(None)
  2088. flexmock(module.feature).should_receive('available').and_return(True)
  2089. flexmock(module).should_receive('ensure_files_readable')
  2090. flexmock(module).should_receive('make_pattern_flags').and_return(())
  2091. flexmock(module).should_receive('make_exclude_flags').and_return(())
  2092. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  2093. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  2094. )
  2095. flexmock(module.environment).should_receive('make_environment')
  2096. flexmock(module).should_receive('execute_command').with_args(
  2097. ('borg', 'create', '--extra', '--options') + REPO_ARCHIVE_WITH_PATHS,
  2098. output_log_level=logging.INFO,
  2099. output_file=None,
  2100. borg_local_path='borg',
  2101. working_directory=None,
  2102. extra_environment=None,
  2103. )
  2104. module.create_archive(
  2105. dry_run=False,
  2106. repository='repo',
  2107. location_config={
  2108. 'source_directories': ['foo', 'bar'],
  2109. 'repositories': ['repo'],
  2110. 'exclude_patterns': None,
  2111. },
  2112. storage_config={'extra_borg_options': {'create': '--extra --options'}},
  2113. local_borg_version='1.2.3',
  2114. )
  2115. def test_create_archive_with_stream_processes_calls_borg_with_processes_and_read_special():
  2116. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  2117. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  2118. processes = flexmock()
  2119. flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
  2120. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  2121. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  2122. flexmock(module).should_receive('expand_directories').and_return(())
  2123. flexmock(module).should_receive('pattern_root_directories').and_return([])
  2124. flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
  2125. flexmock(module).should_receive('expand_home_directories').and_return(())
  2126. flexmock(module).should_receive('write_pattern_file').and_return(None)
  2127. flexmock(module.feature).should_receive('available').and_return(True)
  2128. flexmock(module).should_receive('ensure_files_readable')
  2129. flexmock(module).should_receive('make_pattern_flags').and_return(())
  2130. flexmock(module).should_receive('make_exclude_flags').and_return(())
  2131. flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
  2132. (f'repo::{DEFAULT_ARCHIVE_NAME}',)
  2133. )
  2134. flexmock(module.environment).should_receive('make_environment')
  2135. flexmock(module).should_receive('collect_special_file_paths').and_return(())
  2136. create_command = (
  2137. 'borg',
  2138. 'create',
  2139. '--one-file-system',
  2140. '--read-special',
  2141. ) + REPO_ARCHIVE_WITH_PATHS
  2142. flexmock(module).should_receive('execute_command_with_processes').with_args(
  2143. create_command + ('--dry-run', 'list'),
  2144. processes=processes,
  2145. output_log_level=logging.INFO,
  2146. output_file=None,
  2147. borg_local_path='borg',
  2148. working_directory=None,
  2149. extra_environment=None,
  2150. )
  2151. flexmock(module).should_receive('execute_command_with_processes').with_args(
  2152. create_command,
  2153. processes=processes,
  2154. output_log_level=logging.INFO,
  2155. output_file=None,
  2156. borg_local_path='borg',
  2157. working_directory=None,
  2158. extra_environment=None,
  2159. )
  2160. module.create_archive(
  2161. dry_run=False,
  2162. repository='repo',
  2163. location_config={
  2164. 'source_directories': ['foo', 'bar'],
  2165. 'repositories': ['repo'],
  2166. 'exclude_patterns': None,
  2167. },
  2168. storage_config={},
  2169. local_borg_version='1.2.3',
  2170. stream_processes=processes,
  2171. )