test_create.py 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. import logging
  2. import pytest
  3. from flexmock import flexmock
  4. from borgmatic.borg import create as module
  5. from ..test_verbosity import insert_logging_mock
  6. def test_expand_directory_with_basic_path_passes_it_through():
  7. flexmock(module.os.path).should_receive('expanduser').and_return('foo')
  8. flexmock(module.glob).should_receive('glob').and_return([])
  9. paths = module._expand_directory('foo')
  10. assert paths == ['foo']
  11. def test_expand_directory_with_glob_expands():
  12. flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
  13. flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
  14. paths = module._expand_directory('foo*')
  15. assert paths == ['foo', 'food']
  16. def test_expand_directories_flattens_expanded_directories():
  17. flexmock(module).should_receive('_expand_directory').with_args('~/foo').and_return(
  18. ['/root/foo']
  19. )
  20. flexmock(module).should_receive('_expand_directory').with_args('bar*').and_return(
  21. ['bar', 'barf']
  22. )
  23. paths = module._expand_directories(('~/foo', 'bar*'))
  24. assert paths == ('/root/foo', 'bar', 'barf')
  25. def test_expand_directories_considers_none_as_no_directories():
  26. paths = module._expand_directories(None)
  27. assert paths == ()
  28. def test_expand_home_directories_expands_tildes():
  29. flexmock(module.os.path).should_receive('expanduser').with_args('~/bar').and_return('/foo/bar')
  30. flexmock(module.os.path).should_receive('expanduser').with_args('baz').and_return('baz')
  31. paths = module._expand_home_directories(('~/bar', 'baz'))
  32. assert paths == ('/foo/bar', 'baz')
  33. def test_expand_home_directories_considers_none_as_no_directories():
  34. paths = module._expand_home_directories(None)
  35. assert paths == ()
  36. def test_write_pattern_file_does_not_raise():
  37. temporary_file = flexmock(name='filename', write=lambda mode: None, flush=lambda: None)
  38. flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
  39. module._write_pattern_file(['exclude'])
  40. def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
  41. module._write_pattern_file([])
  42. def test_make_pattern_flags_includes_pattern_filename_when_given():
  43. pattern_flags = module._make_pattern_flags(
  44. location_config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
  45. )
  46. assert pattern_flags == ('--patterns-from', '/tmp/patterns')
  47. def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
  48. pattern_flags = module._make_pattern_flags(
  49. location_config={'patterns_from': ['patterns', 'other']}
  50. )
  51. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
  52. def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
  53. pattern_flags = module._make_pattern_flags(
  54. location_config={'patterns_from': ['patterns']}, pattern_filename='/tmp/patterns'
  55. )
  56. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
  57. def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
  58. pattern_flags = module._make_pattern_flags(location_config={'patterns_from': None})
  59. assert pattern_flags == ()
  60. def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
  61. exclude_flags = module._make_exclude_flags(
  62. location_config={'exclude_patterns': ['*.pyc', '/var']}, exclude_filename='/tmp/excludes'
  63. )
  64. assert exclude_flags == ('--exclude-from', '/tmp/excludes')
  65. def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
  66. exclude_flags = module._make_exclude_flags(
  67. location_config={'exclude_from': ['excludes', 'other']}
  68. )
  69. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
  70. def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
  71. exclude_flags = module._make_exclude_flags(
  72. location_config={'exclude_from': ['excludes']}, exclude_filename='/tmp/excludes'
  73. )
  74. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
  75. def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
  76. exclude_flags = module._make_exclude_flags(location_config={'exclude_from': None})
  77. assert exclude_flags == ()
  78. def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
  79. exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': True})
  80. assert exclude_flags == ('--exclude-caches',)
  81. def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
  82. exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': False})
  83. assert exclude_flags == ()
  84. def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
  85. exclude_flags = module._make_exclude_flags(location_config={'exclude_if_present': 'exclude_me'})
  86. assert exclude_flags == ('--exclude-if-present', 'exclude_me')
  87. def test_make_exclude_flags_includes_keep_exclude_tags_when_true_in_config():
  88. exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': True})
  89. assert exclude_flags == ('--keep-exclude-tags',)
  90. def test_make_exclude_flags_does_not_include_keep_exclude_tags_when_false_in_config():
  91. exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': False})
  92. assert exclude_flags == ()
  93. def test_make_exclude_flags_includes_exclude_nodump_when_true_in_config():
  94. exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': True})
  95. assert exclude_flags == ('--exclude-nodump',)
  96. def test_make_exclude_flags_does_not_include_exclude_nodump_when_false_in_config():
  97. exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': False})
  98. assert exclude_flags == ()
  99. def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
  100. exclude_flags = module._make_exclude_flags(location_config={})
  101. assert exclude_flags == ()
  102. def test_borgmatic_source_directories_set_when_directory_exists():
  103. flexmock(module.os.path).should_receive('exists').and_return(True)
  104. flexmock(module.os.path).should_receive('expanduser')
  105. assert module.borgmatic_source_directories() == [module.BORGMATIC_SOURCE_DIRECTORY]
  106. def test_borgmatic_source_directories_empty_when_directory_does_not_exist():
  107. flexmock(module.os.path).should_receive('exists').and_return(False)
  108. flexmock(module.os.path).should_receive('expanduser')
  109. assert module.borgmatic_source_directories() == []
  110. DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
  111. ARCHIVE_WITH_PATHS = ('repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar')
  112. def test_create_archive_calls_borg_with_parameters():
  113. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  114. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  115. flexmock(module).should_receive('_expand_home_directories').and_return(())
  116. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  117. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  118. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  119. flexmock(module).should_receive('execute_command').with_args(
  120. ('borg', 'create') + ARCHIVE_WITH_PATHS,
  121. output_log_level=logging.INFO,
  122. error_on_warnings=False,
  123. )
  124. module.create_archive(
  125. dry_run=False,
  126. repository='repo',
  127. location_config={
  128. 'source_directories': ['foo', 'bar'],
  129. 'repositories': ['repo'],
  130. 'exclude_patterns': None,
  131. },
  132. storage_config={},
  133. )
  134. def test_create_archive_with_patterns_calls_borg_with_patterns():
  135. pattern_flags = ('--patterns-from', 'patterns')
  136. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  137. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  138. flexmock(module).should_receive('_expand_home_directories').and_return(())
  139. flexmock(module).should_receive('_write_pattern_file').and_return(
  140. flexmock(name='/tmp/patterns')
  141. ).and_return(None)
  142. flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
  143. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  144. flexmock(module).should_receive('execute_command').with_args(
  145. ('borg', 'create') + pattern_flags + ARCHIVE_WITH_PATHS,
  146. output_log_level=logging.INFO,
  147. error_on_warnings=False,
  148. )
  149. module.create_archive(
  150. dry_run=False,
  151. repository='repo',
  152. location_config={
  153. 'source_directories': ['foo', 'bar'],
  154. 'repositories': ['repo'],
  155. 'patterns': ['pattern'],
  156. },
  157. storage_config={},
  158. )
  159. def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
  160. exclude_flags = ('--exclude-from', 'excludes')
  161. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  162. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  163. flexmock(module).should_receive('_expand_home_directories').and_return(('exclude',))
  164. flexmock(module).should_receive('_write_pattern_file').and_return(None).and_return(
  165. flexmock(name='/tmp/excludes')
  166. )
  167. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  168. flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
  169. flexmock(module).should_receive('execute_command').with_args(
  170. ('borg', 'create') + exclude_flags + ARCHIVE_WITH_PATHS,
  171. output_log_level=logging.INFO,
  172. error_on_warnings=False,
  173. )
  174. module.create_archive(
  175. dry_run=False,
  176. repository='repo',
  177. location_config={
  178. 'source_directories': ['foo', 'bar'],
  179. 'repositories': ['repo'],
  180. 'exclude_patterns': ['exclude'],
  181. },
  182. storage_config={},
  183. )
  184. def test_create_archive_with_log_info_calls_borg_with_info_parameter():
  185. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  186. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  187. flexmock(module).should_receive('_expand_home_directories').and_return(())
  188. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  189. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  190. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  191. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  192. flexmock(module).should_receive('execute_command').with_args(
  193. ('borg', 'create', '--list', '--filter', 'AME-', '--info', '--stats') + ARCHIVE_WITH_PATHS,
  194. output_log_level=logging.INFO,
  195. error_on_warnings=False,
  196. )
  197. insert_logging_mock(logging.INFO)
  198. module.create_archive(
  199. dry_run=False,
  200. repository='repo',
  201. location_config={
  202. 'source_directories': ['foo', 'bar'],
  203. 'repositories': ['repo'],
  204. 'exclude_patterns': None,
  205. },
  206. storage_config={},
  207. )
  208. def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
  209. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  210. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  211. flexmock(module).should_receive('_expand_home_directories').and_return(())
  212. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  213. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  214. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  215. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  216. flexmock(module).should_receive('execute_command').with_args(
  217. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  218. output_log_level=None,
  219. error_on_warnings=False,
  220. )
  221. insert_logging_mock(logging.INFO)
  222. module.create_archive(
  223. dry_run=False,
  224. repository='repo',
  225. location_config={
  226. 'source_directories': ['foo', 'bar'],
  227. 'repositories': ['repo'],
  228. 'exclude_patterns': None,
  229. },
  230. storage_config={},
  231. json=True,
  232. )
  233. def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
  234. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  235. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  236. flexmock(module).should_receive('_expand_home_directories').and_return(())
  237. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  238. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  239. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  240. flexmock(module).should_receive('execute_command').with_args(
  241. ('borg', 'create', '--list', '--filter', 'AME-', '--stats', '--debug', '--show-rc')
  242. + ARCHIVE_WITH_PATHS,
  243. output_log_level=logging.INFO,
  244. error_on_warnings=False,
  245. )
  246. insert_logging_mock(logging.DEBUG)
  247. module.create_archive(
  248. dry_run=False,
  249. repository='repo',
  250. location_config={
  251. 'source_directories': ['foo', 'bar'],
  252. 'repositories': ['repo'],
  253. 'exclude_patterns': None,
  254. },
  255. storage_config={},
  256. )
  257. def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
  258. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  259. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  260. flexmock(module).should_receive('_expand_home_directories').and_return(())
  261. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  262. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  263. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  264. flexmock(module).should_receive('execute_command').with_args(
  265. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  266. output_log_level=None,
  267. error_on_warnings=False,
  268. )
  269. insert_logging_mock(logging.DEBUG)
  270. module.create_archive(
  271. dry_run=False,
  272. repository='repo',
  273. location_config={
  274. 'source_directories': ['foo', 'bar'],
  275. 'repositories': ['repo'],
  276. 'exclude_patterns': None,
  277. },
  278. storage_config={},
  279. json=True,
  280. )
  281. def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
  282. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  283. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  284. flexmock(module).should_receive('_expand_home_directories').and_return(())
  285. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  286. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  287. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  288. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  289. flexmock(module).should_receive('execute_command').with_args(
  290. ('borg', 'create', '--dry-run') + ARCHIVE_WITH_PATHS,
  291. output_log_level=logging.INFO,
  292. error_on_warnings=False,
  293. )
  294. module.create_archive(
  295. dry_run=True,
  296. repository='repo',
  297. location_config={
  298. 'source_directories': ['foo', 'bar'],
  299. 'repositories': ['repo'],
  300. 'exclude_patterns': None,
  301. },
  302. storage_config={},
  303. )
  304. def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_parameter():
  305. # --dry-run and --stats are mutually exclusive, see:
  306. # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
  307. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  308. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  309. flexmock(module).should_receive('_expand_home_directories').and_return(())
  310. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  311. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  312. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  313. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  314. flexmock(module).should_receive('execute_command').with_args(
  315. ('borg', 'create', '--list', '--filter', 'AME-', '--info', '--dry-run')
  316. + ARCHIVE_WITH_PATHS,
  317. output_log_level=logging.INFO,
  318. error_on_warnings=False,
  319. )
  320. insert_logging_mock(logging.INFO)
  321. module.create_archive(
  322. dry_run=True,
  323. repository='repo',
  324. location_config={
  325. 'source_directories': ['foo', 'bar'],
  326. 'repositories': ['repo'],
  327. 'exclude_patterns': None,
  328. },
  329. storage_config={},
  330. )
  331. def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_parameter():
  332. # --dry-run and --stats are mutually exclusive, see:
  333. # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
  334. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  335. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  336. flexmock(module).should_receive('_expand_home_directories').and_return(())
  337. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  338. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  339. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  340. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  341. flexmock(module).should_receive('execute_command').with_args(
  342. ('borg', 'create', '--list', '--filter', 'AME-', '--debug', '--show-rc', '--dry-run')
  343. + ARCHIVE_WITH_PATHS,
  344. output_log_level=logging.INFO,
  345. error_on_warnings=False,
  346. )
  347. insert_logging_mock(logging.DEBUG)
  348. module.create_archive(
  349. dry_run=True,
  350. repository='repo',
  351. location_config={
  352. 'source_directories': ['foo', 'bar'],
  353. 'repositories': ['repo'],
  354. 'exclude_patterns': None,
  355. },
  356. storage_config={},
  357. )
  358. def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
  359. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  360. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  361. flexmock(module).should_receive('_expand_home_directories').and_return(())
  362. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  363. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  364. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  365. flexmock(module).should_receive('execute_command').with_args(
  366. ('borg', 'create', '--checkpoint-interval', '600') + ARCHIVE_WITH_PATHS,
  367. output_log_level=logging.INFO,
  368. error_on_warnings=False,
  369. )
  370. module.create_archive(
  371. dry_run=False,
  372. repository='repo',
  373. location_config={
  374. 'source_directories': ['foo', 'bar'],
  375. 'repositories': ['repo'],
  376. 'exclude_patterns': None,
  377. },
  378. storage_config={'checkpoint_interval': 600},
  379. )
  380. def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_parameters():
  381. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  382. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  383. flexmock(module).should_receive('_expand_home_directories').and_return(())
  384. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  385. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  386. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  387. flexmock(module).should_receive('execute_command').with_args(
  388. ('borg', 'create', '--chunker-params', '1,2,3,4') + ARCHIVE_WITH_PATHS,
  389. output_log_level=logging.INFO,
  390. error_on_warnings=False,
  391. )
  392. module.create_archive(
  393. dry_run=False,
  394. repository='repo',
  395. location_config={
  396. 'source_directories': ['foo', 'bar'],
  397. 'repositories': ['repo'],
  398. 'exclude_patterns': None,
  399. },
  400. storage_config={'chunker_params': '1,2,3,4'},
  401. )
  402. def test_create_archive_with_compression_calls_borg_with_compression_parameters():
  403. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  404. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  405. flexmock(module).should_receive('_expand_home_directories').and_return(())
  406. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  407. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  408. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  409. flexmock(module).should_receive('execute_command').with_args(
  410. ('borg', 'create', '--compression', 'rle') + ARCHIVE_WITH_PATHS,
  411. output_log_level=logging.INFO,
  412. error_on_warnings=False,
  413. )
  414. module.create_archive(
  415. dry_run=False,
  416. repository='repo',
  417. location_config={
  418. 'source_directories': ['foo', 'bar'],
  419. 'repositories': ['repo'],
  420. 'exclude_patterns': None,
  421. },
  422. storage_config={'compression': 'rle'},
  423. )
  424. def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_parameters():
  425. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  426. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  427. flexmock(module).should_receive('_expand_home_directories').and_return(())
  428. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  429. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  430. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  431. flexmock(module).should_receive('execute_command').with_args(
  432. ('borg', 'create', '--remote-ratelimit', '100') + ARCHIVE_WITH_PATHS,
  433. output_log_level=logging.INFO,
  434. error_on_warnings=False,
  435. )
  436. module.create_archive(
  437. dry_run=False,
  438. repository='repo',
  439. location_config={
  440. 'source_directories': ['foo', 'bar'],
  441. 'repositories': ['repo'],
  442. 'exclude_patterns': None,
  443. },
  444. storage_config={'remote_rate_limit': 100},
  445. )
  446. def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
  447. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  448. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  449. flexmock(module).should_receive('_expand_home_directories').and_return(())
  450. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  451. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  452. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  453. flexmock(module).should_receive('execute_command').with_args(
  454. ('borg', 'create', '--one-file-system') + ARCHIVE_WITH_PATHS,
  455. output_log_level=logging.INFO,
  456. error_on_warnings=False,
  457. )
  458. module.create_archive(
  459. dry_run=False,
  460. repository='repo',
  461. location_config={
  462. 'source_directories': ['foo', 'bar'],
  463. 'repositories': ['repo'],
  464. 'one_file_system': True,
  465. 'exclude_patterns': None,
  466. },
  467. storage_config={},
  468. )
  469. def test_create_archive_with_numeric_owner_calls_borg_with_numeric_owner_parameter():
  470. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  471. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  472. flexmock(module).should_receive('_expand_home_directories').and_return(())
  473. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  474. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  475. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  476. flexmock(module).should_receive('execute_command').with_args(
  477. ('borg', 'create', '--numeric-owner') + ARCHIVE_WITH_PATHS,
  478. output_log_level=logging.INFO,
  479. error_on_warnings=False,
  480. )
  481. module.create_archive(
  482. dry_run=False,
  483. repository='repo',
  484. location_config={
  485. 'source_directories': ['foo', 'bar'],
  486. 'repositories': ['repo'],
  487. 'numeric_owner': True,
  488. 'exclude_patterns': None,
  489. },
  490. storage_config={},
  491. )
  492. def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
  493. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  494. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  495. flexmock(module).should_receive('_expand_home_directories').and_return(())
  496. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  497. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  498. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  499. flexmock(module).should_receive('execute_command').with_args(
  500. ('borg', 'create', '--read-special') + ARCHIVE_WITH_PATHS,
  501. output_log_level=logging.INFO,
  502. error_on_warnings=False,
  503. )
  504. module.create_archive(
  505. dry_run=False,
  506. repository='repo',
  507. location_config={
  508. 'source_directories': ['foo', 'bar'],
  509. 'repositories': ['repo'],
  510. 'read_special': True,
  511. 'exclude_patterns': None,
  512. },
  513. storage_config={},
  514. )
  515. @pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags'))
  516. def test_create_archive_with_option_true_calls_borg_without_corresponding_parameter(option_name):
  517. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  518. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  519. flexmock(module).should_receive('_expand_home_directories').and_return(())
  520. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  521. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  522. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  523. flexmock(module).should_receive('execute_command').with_args(
  524. ('borg', 'create') + ARCHIVE_WITH_PATHS,
  525. output_log_level=logging.INFO,
  526. error_on_warnings=False,
  527. )
  528. module.create_archive(
  529. dry_run=False,
  530. repository='repo',
  531. location_config={
  532. 'source_directories': ['foo', 'bar'],
  533. 'repositories': ['repo'],
  534. option_name: True,
  535. 'exclude_patterns': None,
  536. },
  537. storage_config={},
  538. )
  539. @pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags'))
  540. def test_create_archive_with_option_false_calls_borg_with_corresponding_parameter(option_name):
  541. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  542. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  543. flexmock(module).should_receive('_expand_home_directories').and_return(())
  544. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  545. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  546. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  547. flexmock(module).should_receive('execute_command').with_args(
  548. ('borg', 'create', '--no' + option_name.replace('_', '')) + ARCHIVE_WITH_PATHS,
  549. output_log_level=logging.INFO,
  550. error_on_warnings=False,
  551. )
  552. module.create_archive(
  553. dry_run=False,
  554. repository='repo',
  555. location_config={
  556. 'source_directories': ['foo', 'bar'],
  557. 'repositories': ['repo'],
  558. option_name: False,
  559. 'exclude_patterns': None,
  560. },
  561. storage_config={},
  562. )
  563. def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
  564. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  565. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  566. flexmock(module).should_receive('_expand_home_directories').and_return(())
  567. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  568. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  569. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  570. flexmock(module).should_receive('execute_command').with_args(
  571. ('borg', 'create', '--files-cache', 'ctime,size') + ARCHIVE_WITH_PATHS,
  572. output_log_level=logging.INFO,
  573. error_on_warnings=False,
  574. )
  575. module.create_archive(
  576. dry_run=False,
  577. repository='repo',
  578. location_config={
  579. 'source_directories': ['foo', 'bar'],
  580. 'repositories': ['repo'],
  581. 'files_cache': 'ctime,size',
  582. 'exclude_patterns': None,
  583. },
  584. storage_config={},
  585. )
  586. def test_create_archive_with_local_path_calls_borg_via_local_path():
  587. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  588. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  589. flexmock(module).should_receive('_expand_home_directories').and_return(())
  590. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  591. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  592. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  593. flexmock(module).should_receive('execute_command').with_args(
  594. ('borg1', 'create') + ARCHIVE_WITH_PATHS,
  595. output_log_level=logging.INFO,
  596. error_on_warnings=False,
  597. )
  598. module.create_archive(
  599. dry_run=False,
  600. repository='repo',
  601. location_config={
  602. 'source_directories': ['foo', 'bar'],
  603. 'repositories': ['repo'],
  604. 'exclude_patterns': None,
  605. },
  606. storage_config={},
  607. local_path='borg1',
  608. )
  609. def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
  610. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  611. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  612. flexmock(module).should_receive('_expand_home_directories').and_return(())
  613. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  614. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  615. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  616. flexmock(module).should_receive('execute_command').with_args(
  617. ('borg', 'create', '--remote-path', 'borg1') + ARCHIVE_WITH_PATHS,
  618. output_log_level=logging.INFO,
  619. error_on_warnings=False,
  620. )
  621. module.create_archive(
  622. dry_run=False,
  623. repository='repo',
  624. location_config={
  625. 'source_directories': ['foo', 'bar'],
  626. 'repositories': ['repo'],
  627. 'exclude_patterns': None,
  628. },
  629. storage_config={},
  630. remote_path='borg1',
  631. )
  632. def test_create_archive_with_umask_calls_borg_with_umask_parameters():
  633. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  634. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  635. flexmock(module).should_receive('_expand_home_directories').and_return(())
  636. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  637. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  638. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  639. flexmock(module).should_receive('execute_command').with_args(
  640. ('borg', 'create', '--umask', '740') + ARCHIVE_WITH_PATHS,
  641. output_log_level=logging.INFO,
  642. error_on_warnings=False,
  643. )
  644. module.create_archive(
  645. dry_run=False,
  646. repository='repo',
  647. location_config={
  648. 'source_directories': ['foo', 'bar'],
  649. 'repositories': ['repo'],
  650. 'exclude_patterns': None,
  651. },
  652. storage_config={'umask': 740},
  653. )
  654. def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
  655. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  656. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  657. flexmock(module).should_receive('_expand_home_directories').and_return(())
  658. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  659. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  660. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  661. flexmock(module).should_receive('execute_command').with_args(
  662. ('borg', 'create', '--lock-wait', '5') + ARCHIVE_WITH_PATHS,
  663. output_log_level=logging.INFO,
  664. error_on_warnings=False,
  665. )
  666. module.create_archive(
  667. dry_run=False,
  668. repository='repo',
  669. location_config={
  670. 'source_directories': ['foo', 'bar'],
  671. 'repositories': ['repo'],
  672. 'exclude_patterns': None,
  673. },
  674. storage_config={'lock_wait': 5},
  675. )
  676. def test_create_archive_with_stats_calls_borg_with_stats_parameter():
  677. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  678. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  679. flexmock(module).should_receive('_expand_home_directories').and_return(())
  680. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  681. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  682. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  683. flexmock(module).should_receive('execute_command').with_args(
  684. ('borg', 'create', '--stats') + ARCHIVE_WITH_PATHS,
  685. output_log_level=logging.WARNING,
  686. error_on_warnings=False,
  687. )
  688. module.create_archive(
  689. dry_run=False,
  690. repository='repo',
  691. location_config={
  692. 'source_directories': ['foo', 'bar'],
  693. 'repositories': ['repo'],
  694. 'exclude_patterns': None,
  695. },
  696. storage_config={},
  697. stats=True,
  698. )
  699. def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_parameter_and_no_list():
  700. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  701. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  702. flexmock(module).should_receive('_expand_home_directories').and_return(())
  703. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  704. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  705. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  706. flexmock(module).should_receive('execute_command_without_capture').with_args(
  707. ('borg', 'create', '--info', '--stats', '--progress') + ARCHIVE_WITH_PATHS,
  708. error_on_warnings=False,
  709. )
  710. insert_logging_mock(logging.INFO)
  711. module.create_archive(
  712. dry_run=False,
  713. repository='repo',
  714. location_config={
  715. 'source_directories': ['foo', 'bar'],
  716. 'repositories': ['repo'],
  717. 'exclude_patterns': None,
  718. },
  719. storage_config={},
  720. progress=True,
  721. )
  722. def test_create_archive_with_progress_calls_borg_with_progress_parameter():
  723. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  724. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  725. flexmock(module).should_receive('_expand_home_directories').and_return(())
  726. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  727. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  728. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  729. flexmock(module).should_receive('execute_command_without_capture').with_args(
  730. ('borg', 'create', '--progress') + ARCHIVE_WITH_PATHS, error_on_warnings=False
  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={},
  741. progress=True,
  742. )
  743. def test_create_archive_with_json_calls_borg_with_json_parameter():
  744. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  745. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  746. flexmock(module).should_receive('_expand_home_directories').and_return(())
  747. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  748. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  749. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  750. flexmock(module).should_receive('execute_command').with_args(
  751. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  752. output_log_level=None,
  753. error_on_warnings=False,
  754. ).and_return('[]')
  755. json_output = module.create_archive(
  756. dry_run=False,
  757. repository='repo',
  758. location_config={
  759. 'source_directories': ['foo', 'bar'],
  760. 'repositories': ['repo'],
  761. 'exclude_patterns': None,
  762. },
  763. storage_config={},
  764. json=True,
  765. )
  766. assert json_output == '[]'
  767. def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter():
  768. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  769. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  770. flexmock(module).should_receive('_expand_home_directories').and_return(())
  771. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  772. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  773. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  774. flexmock(module).should_receive('execute_command').with_args(
  775. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  776. output_log_level=None,
  777. error_on_warnings=False,
  778. ).and_return('[]')
  779. json_output = module.create_archive(
  780. dry_run=False,
  781. repository='repo',
  782. location_config={
  783. 'source_directories': ['foo', 'bar'],
  784. 'repositories': ['repo'],
  785. 'exclude_patterns': None,
  786. },
  787. storage_config={},
  788. json=True,
  789. stats=True,
  790. )
  791. assert json_output == '[]'
  792. def test_create_archive_with_source_directories_glob_expands():
  793. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  794. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
  795. flexmock(module).should_receive('_expand_home_directories').and_return(())
  796. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  797. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  798. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  799. flexmock(module).should_receive('execute_command').with_args(
  800. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  801. output_log_level=logging.INFO,
  802. error_on_warnings=False,
  803. )
  804. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
  805. module.create_archive(
  806. dry_run=False,
  807. repository='repo',
  808. location_config={
  809. 'source_directories': ['foo*'],
  810. 'repositories': ['repo'],
  811. 'exclude_patterns': None,
  812. },
  813. storage_config={},
  814. )
  815. def test_create_archive_with_non_matching_source_directories_glob_passes_through():
  816. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  817. flexmock(module).should_receive('_expand_directories').and_return(('foo*',))
  818. flexmock(module).should_receive('_expand_home_directories').and_return(())
  819. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  820. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  821. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  822. flexmock(module).should_receive('execute_command').with_args(
  823. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'),
  824. output_log_level=logging.INFO,
  825. error_on_warnings=False,
  826. )
  827. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
  828. module.create_archive(
  829. dry_run=False,
  830. repository='repo',
  831. location_config={
  832. 'source_directories': ['foo*'],
  833. 'repositories': ['repo'],
  834. 'exclude_patterns': None,
  835. },
  836. storage_config={},
  837. )
  838. def test_create_archive_with_glob_calls_borg_with_expanded_directories():
  839. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  840. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
  841. flexmock(module).should_receive('_expand_home_directories').and_return(())
  842. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  843. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  844. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  845. flexmock(module).should_receive('execute_command').with_args(
  846. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  847. output_log_level=logging.INFO,
  848. error_on_warnings=False,
  849. )
  850. module.create_archive(
  851. dry_run=False,
  852. repository='repo',
  853. location_config={
  854. 'source_directories': ['foo*'],
  855. 'repositories': ['repo'],
  856. 'exclude_patterns': None,
  857. },
  858. storage_config={},
  859. )
  860. def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
  861. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  862. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  863. flexmock(module).should_receive('_expand_home_directories').and_return(())
  864. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  865. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  866. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  867. flexmock(module).should_receive('execute_command').with_args(
  868. ('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'),
  869. output_log_level=logging.INFO,
  870. error_on_warnings=False,
  871. )
  872. module.create_archive(
  873. dry_run=False,
  874. repository='repo',
  875. location_config={
  876. 'source_directories': ['foo', 'bar'],
  877. 'repositories': ['repo'],
  878. 'exclude_patterns': None,
  879. },
  880. storage_config={'archive_name_format': 'ARCHIVE_NAME'},
  881. )
  882. def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
  883. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  884. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  885. flexmock(module).should_receive('_expand_home_directories').and_return(())
  886. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  887. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  888. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  889. flexmock(module).should_receive('execute_command').with_args(
  890. ('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'),
  891. output_log_level=logging.INFO,
  892. error_on_warnings=False,
  893. )
  894. module.create_archive(
  895. dry_run=False,
  896. repository='repo',
  897. location_config={
  898. 'source_directories': ['foo', 'bar'],
  899. 'repositories': ['repo'],
  900. 'exclude_patterns': None,
  901. },
  902. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  903. )
  904. def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
  905. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  906. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  907. flexmock(module).should_receive('_expand_home_directories').and_return(())
  908. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  909. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  910. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  911. flexmock(module).should_receive('execute_command').with_args(
  912. ('borg', 'create', '--extra', '--options') + ARCHIVE_WITH_PATHS,
  913. output_log_level=logging.INFO,
  914. error_on_warnings=False,
  915. )
  916. module.create_archive(
  917. dry_run=False,
  918. repository='repo',
  919. location_config={
  920. 'source_directories': ['foo', 'bar'],
  921. 'repositories': ['repo'],
  922. 'exclude_patterns': None,
  923. },
  924. storage_config={'extra_borg_options': {'create': '--extra --options'}},
  925. )