test_postgresql.py 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  1. import logging
  2. import pytest
  3. from flexmock import flexmock
  4. from borgmatic.hooks import postgresql as module
  5. def test_make_extra_environment_maps_options_to_environment():
  6. database = {
  7. 'name': 'foo',
  8. 'password': 'pass',
  9. 'ssl_mode': 'require',
  10. 'ssl_cert': 'cert.crt',
  11. 'ssl_key': 'key.key',
  12. 'ssl_root_cert': 'root.crt',
  13. 'ssl_crl': 'crl.crl',
  14. }
  15. expected = {
  16. 'PGPASSWORD': 'pass',
  17. 'PGSSLMODE': 'require',
  18. 'PGSSLCERT': 'cert.crt',
  19. 'PGSSLKEY': 'key.key',
  20. 'PGSSLROOTCERT': 'root.crt',
  21. 'PGSSLCRL': 'crl.crl',
  22. }
  23. extra_env = module.make_extra_environment(database)
  24. assert extra_env == expected
  25. def test_make_extra_environment_with_cli_password_sets_correct_password():
  26. database = {'name': 'foo', 'restore_password': 'trustsome1', 'password': 'anotherpassword'}
  27. extra = module.make_extra_environment(
  28. database, restore_connection_params={'password': 'clipassword'}
  29. )
  30. assert extra['PGPASSWORD'] == 'clipassword'
  31. def test_make_extra_environment_without_cli_password_or_configured_password_does_not_set_password():
  32. database = {'name': 'foo'}
  33. extra = module.make_extra_environment(
  34. database, restore_connection_params={'username': 'someone'}
  35. )
  36. assert 'PGPASSWORD' not in extra
  37. def test_make_extra_environment_without_ssl_mode_does_not_set_ssl_mode():
  38. database = {'name': 'foo'}
  39. extra = module.make_extra_environment(database)
  40. assert 'PGSSLMODE' not in extra
  41. def test_database_names_to_dump_passes_through_individual_database_name():
  42. database = {'name': 'foo'}
  43. assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == (
  44. 'foo',
  45. )
  46. def test_database_names_to_dump_passes_through_individual_database_name_with_format():
  47. database = {'name': 'foo', 'format': 'custom'}
  48. assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == (
  49. 'foo',
  50. )
  51. def test_database_names_to_dump_passes_through_all_without_format():
  52. database = {'name': 'all'}
  53. assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == (
  54. 'all',
  55. )
  56. def test_database_names_to_dump_with_all_and_format_and_dry_run_bails():
  57. database = {'name': 'all', 'format': 'custom'}
  58. flexmock(module).should_receive('execute_command_and_capture_output').never()
  59. assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=True) == ()
  60. def test_database_names_to_dump_with_all_and_format_lists_databases():
  61. database = {'name': 'all', 'format': 'custom'}
  62. flexmock(module).should_receive('execute_command_and_capture_output').and_return(
  63. 'foo,test,\nbar,test,"stuff and such"'
  64. )
  65. assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == (
  66. 'foo',
  67. 'bar',
  68. )
  69. def test_database_names_to_dump_with_all_and_format_lists_databases_with_hostname_and_port():
  70. database = {'name': 'all', 'format': 'custom', 'hostname': 'localhost', 'port': 1234}
  71. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  72. (
  73. 'psql',
  74. '--list',
  75. '--no-password',
  76. '--no-psqlrc',
  77. '--csv',
  78. '--tuples-only',
  79. '--host',
  80. 'localhost',
  81. '--port',
  82. '1234',
  83. ),
  84. extra_environment=object,
  85. ).and_return('foo,test,\nbar,test,"stuff and such"')
  86. assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == (
  87. 'foo',
  88. 'bar',
  89. )
  90. def test_database_names_to_dump_with_all_and_format_lists_databases_with_username():
  91. database = {'name': 'all', 'format': 'custom', 'username': 'postgres'}
  92. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  93. (
  94. 'psql',
  95. '--list',
  96. '--no-password',
  97. '--no-psqlrc',
  98. '--csv',
  99. '--tuples-only',
  100. '--username',
  101. 'postgres',
  102. ),
  103. extra_environment=object,
  104. ).and_return('foo,test,\nbar,test,"stuff and such"')
  105. assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == (
  106. 'foo',
  107. 'bar',
  108. )
  109. def test_database_names_to_dump_with_all_and_format_lists_databases_with_options():
  110. database = {'name': 'all', 'format': 'custom', 'list_options': '--harder'}
  111. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  112. ('psql', '--list', '--no-password', '--no-psqlrc', '--csv', '--tuples-only', '--harder'),
  113. extra_environment=object,
  114. ).and_return('foo,test,\nbar,test,"stuff and such"')
  115. assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == (
  116. 'foo',
  117. 'bar',
  118. )
  119. def test_database_names_to_dump_with_all_and_format_excludes_particular_databases():
  120. database = {'name': 'all', 'format': 'custom'}
  121. flexmock(module).should_receive('execute_command_and_capture_output').and_return(
  122. 'foo,test,\ntemplate0,test,blah'
  123. )
  124. assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == (
  125. 'foo',
  126. )
  127. def test_database_names_to_dump_with_all_and_psql_command_uses_custom_command():
  128. database = {
  129. 'name': 'all',
  130. 'format': 'custom',
  131. 'psql_command': 'docker exec --workdir * mycontainer psql',
  132. }
  133. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  134. (
  135. 'docker',
  136. 'exec',
  137. '--workdir',
  138. "'*'", # Should get shell escaped to prevent injection attacks.
  139. 'mycontainer',
  140. 'psql',
  141. '--list',
  142. '--no-password',
  143. '--no-psqlrc',
  144. '--csv',
  145. '--tuples-only',
  146. ),
  147. extra_environment=object,
  148. ).and_return('foo,text').once()
  149. assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == (
  150. 'foo',
  151. )
  152. def test_use_streaming_true_for_any_non_directory_format_databases():
  153. assert module.use_streaming(
  154. databases=[{'format': 'stuff'}, {'format': 'directory'}, {}],
  155. config=flexmock(),
  156. log_prefix=flexmock(),
  157. )
  158. def test_use_streaming_false_for_all_directory_format_databases():
  159. assert not module.use_streaming(
  160. databases=[{'format': 'directory'}, {'format': 'directory'}],
  161. config=flexmock(),
  162. log_prefix=flexmock(),
  163. )
  164. def test_use_streaming_false_for_no_databases():
  165. assert not module.use_streaming(databases=[], config=flexmock(), log_prefix=flexmock())
  166. def test_dump_data_sources_runs_pg_dump_for_each_database():
  167. databases = [{'name': 'foo'}, {'name': 'bar'}]
  168. processes = [flexmock(), flexmock()]
  169. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  170. flexmock(module).should_receive('make_dump_path').and_return('')
  171. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',)).and_return(
  172. ('bar',)
  173. )
  174. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  175. 'databases/localhost/foo'
  176. ).and_return('databases/localhost/bar')
  177. flexmock(module.os.path).should_receive('exists').and_return(False)
  178. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  179. for name, process in zip(('foo', 'bar'), processes):
  180. flexmock(module).should_receive('execute_command').with_args(
  181. (
  182. 'pg_dump',
  183. '--no-password',
  184. '--clean',
  185. '--if-exists',
  186. '--format',
  187. 'custom',
  188. name,
  189. '>',
  190. f'databases/localhost/{name}',
  191. ),
  192. shell=True,
  193. extra_environment={'PGSSLMODE': 'disable'},
  194. run_to_completion=False,
  195. ).and_return(process).once()
  196. assert (
  197. module.dump_data_sources(
  198. databases,
  199. {},
  200. 'test.yaml',
  201. config_paths=('test.yaml',),
  202. borgmatic_runtime_directory='/run/borgmatic',
  203. source_directories=[],
  204. dry_run=False,
  205. )
  206. == processes
  207. )
  208. def test_dump_data_sources_raises_when_no_database_names_to_dump():
  209. databases = [{'name': 'foo'}, {'name': 'bar'}]
  210. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  211. flexmock(module).should_receive('make_dump_path').and_return('')
  212. flexmock(module).should_receive('database_names_to_dump').and_return(())
  213. with pytest.raises(ValueError):
  214. module.dump_data_sources(
  215. databases,
  216. {},
  217. 'test.yaml',
  218. config_paths=('test.yaml',),
  219. borgmatic_runtime_directory='/run/borgmatic',
  220. source_directories=[],
  221. dry_run=False,
  222. )
  223. def test_dump_data_sources_does_not_raise_when_no_database_names_to_dump():
  224. databases = [{'name': 'foo'}, {'name': 'bar'}]
  225. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  226. flexmock(module).should_receive('make_dump_path').and_return('')
  227. flexmock(module).should_receive('database_names_to_dump').and_return(())
  228. module.dump_data_sources(
  229. databases,
  230. {},
  231. 'test.yaml',
  232. config_paths=('test.yaml',),
  233. borgmatic_runtime_directory='/run/borgmatic',
  234. source_directories=[],
  235. dry_run=True,
  236. ) == []
  237. def test_dump_data_sources_with_duplicate_dump_skips_pg_dump():
  238. databases = [{'name': 'foo'}, {'name': 'bar'}]
  239. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  240. flexmock(module).should_receive('make_dump_path').and_return('')
  241. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',)).and_return(
  242. ('bar',)
  243. )
  244. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  245. 'databases/localhost/foo'
  246. ).and_return('databases/localhost/bar')
  247. flexmock(module.os.path).should_receive('exists').and_return(True)
  248. flexmock(module.dump).should_receive('create_named_pipe_for_dump').never()
  249. flexmock(module).should_receive('execute_command').never()
  250. assert (
  251. module.dump_data_sources(
  252. databases,
  253. {},
  254. 'test.yaml',
  255. config_paths=('test.yaml',),
  256. borgmatic_runtime_directory='/run/borgmatic',
  257. source_directories=[],
  258. dry_run=False,
  259. )
  260. == []
  261. )
  262. def test_dump_data_sources_with_dry_run_skips_pg_dump():
  263. databases = [{'name': 'foo'}, {'name': 'bar'}]
  264. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  265. flexmock(module).should_receive('make_dump_path').and_return('')
  266. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',)).and_return(
  267. ('bar',)
  268. )
  269. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  270. 'databases/localhost/foo'
  271. ).and_return('databases/localhost/bar')
  272. flexmock(module.os.path).should_receive('exists').and_return(False)
  273. flexmock(module.dump).should_receive('create_named_pipe_for_dump').never()
  274. flexmock(module).should_receive('execute_command').never()
  275. assert (
  276. module.dump_data_sources(
  277. databases,
  278. {},
  279. 'test.yaml',
  280. config_paths=('test.yaml',),
  281. borgmatic_runtime_directory='/run/borgmatic',
  282. source_directories=[],
  283. dry_run=True,
  284. )
  285. == []
  286. )
  287. def test_dump_data_sources_runs_pg_dump_with_hostname_and_port():
  288. databases = [{'name': 'foo', 'hostname': 'database.example.org', 'port': 5433}]
  289. process = flexmock()
  290. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  291. flexmock(module).should_receive('make_dump_path').and_return('')
  292. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',))
  293. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  294. 'databases/database.example.org/foo'
  295. )
  296. flexmock(module.os.path).should_receive('exists').and_return(False)
  297. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  298. flexmock(module).should_receive('execute_command').with_args(
  299. (
  300. 'pg_dump',
  301. '--no-password',
  302. '--clean',
  303. '--if-exists',
  304. '--host',
  305. 'database.example.org',
  306. '--port',
  307. '5433',
  308. '--format',
  309. 'custom',
  310. 'foo',
  311. '>',
  312. 'databases/database.example.org/foo',
  313. ),
  314. shell=True,
  315. extra_environment={'PGSSLMODE': 'disable'},
  316. run_to_completion=False,
  317. ).and_return(process).once()
  318. assert module.dump_data_sources(
  319. databases,
  320. {},
  321. 'test.yaml',
  322. config_paths=('test.yaml',),
  323. borgmatic_runtime_directory='/run/borgmatic',
  324. source_directories=[],
  325. dry_run=False,
  326. ) == [process]
  327. def test_dump_data_sources_runs_pg_dump_with_username_and_password():
  328. databases = [{'name': 'foo', 'username': 'postgres', 'password': 'trustsome1'}]
  329. process = flexmock()
  330. flexmock(module).should_receive('make_extra_environment').and_return(
  331. {'PGPASSWORD': 'trustsome1', 'PGSSLMODE': 'disable'}
  332. )
  333. flexmock(module).should_receive('make_dump_path').and_return('')
  334. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',))
  335. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  336. 'databases/localhost/foo'
  337. )
  338. flexmock(module.os.path).should_receive('exists').and_return(False)
  339. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  340. flexmock(module).should_receive('execute_command').with_args(
  341. (
  342. 'pg_dump',
  343. '--no-password',
  344. '--clean',
  345. '--if-exists',
  346. '--username',
  347. 'postgres',
  348. '--format',
  349. 'custom',
  350. 'foo',
  351. '>',
  352. 'databases/localhost/foo',
  353. ),
  354. shell=True,
  355. extra_environment={'PGPASSWORD': 'trustsome1', 'PGSSLMODE': 'disable'},
  356. run_to_completion=False,
  357. ).and_return(process).once()
  358. assert module.dump_data_sources(
  359. databases,
  360. {},
  361. 'test.yaml',
  362. config_paths=('test.yaml',),
  363. borgmatic_runtime_directory='/run/borgmatic',
  364. source_directories=[],
  365. dry_run=False,
  366. ) == [process]
  367. def test_dump_data_sources_with_username_injection_attack_gets_escaped():
  368. databases = [{'name': 'foo', 'username': 'postgres; naughty-command', 'password': 'trustsome1'}]
  369. process = flexmock()
  370. flexmock(module).should_receive('make_extra_environment').and_return(
  371. {'PGPASSWORD': 'trustsome1', 'PGSSLMODE': 'disable'}
  372. )
  373. flexmock(module).should_receive('make_dump_path').and_return('')
  374. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',))
  375. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  376. 'databases/localhost/foo'
  377. )
  378. flexmock(module.os.path).should_receive('exists').and_return(False)
  379. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  380. flexmock(module).should_receive('execute_command').with_args(
  381. (
  382. 'pg_dump',
  383. '--no-password',
  384. '--clean',
  385. '--if-exists',
  386. '--username',
  387. "'postgres; naughty-command'",
  388. '--format',
  389. 'custom',
  390. 'foo',
  391. '>',
  392. 'databases/localhost/foo',
  393. ),
  394. shell=True,
  395. extra_environment={'PGPASSWORD': 'trustsome1', 'PGSSLMODE': 'disable'},
  396. run_to_completion=False,
  397. ).and_return(process).once()
  398. assert module.dump_data_sources(
  399. databases,
  400. {},
  401. 'test.yaml',
  402. config_paths=('test.yaml',),
  403. borgmatic_runtime_directory='/run/borgmatic',
  404. source_directories=[],
  405. dry_run=False,
  406. ) == [process]
  407. def test_dump_data_sources_runs_pg_dump_with_directory_format():
  408. databases = [{'name': 'foo', 'format': 'directory'}]
  409. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  410. flexmock(module).should_receive('make_dump_path').and_return('')
  411. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',))
  412. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  413. 'databases/localhost/foo'
  414. )
  415. flexmock(module.os.path).should_receive('exists').and_return(False)
  416. flexmock(module.dump).should_receive('create_parent_directory_for_dump')
  417. flexmock(module.dump).should_receive('create_named_pipe_for_dump').never()
  418. flexmock(module).should_receive('execute_command').with_args(
  419. (
  420. 'pg_dump',
  421. '--no-password',
  422. '--clean',
  423. '--if-exists',
  424. '--format',
  425. 'directory',
  426. '--file',
  427. 'databases/localhost/foo',
  428. 'foo',
  429. ),
  430. shell=True,
  431. extra_environment={'PGSSLMODE': 'disable'},
  432. ).and_return(flexmock()).once()
  433. assert (
  434. module.dump_data_sources(
  435. databases,
  436. {},
  437. 'test.yaml',
  438. config_paths=('test.yaml',),
  439. borgmatic_runtime_directory='/run/borgmatic',
  440. source_directories=[],
  441. dry_run=False,
  442. )
  443. == []
  444. )
  445. def test_dump_data_sources_runs_pg_dump_with_options():
  446. databases = [{'name': 'foo', 'options': '--stuff=such'}]
  447. process = flexmock()
  448. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  449. flexmock(module).should_receive('make_dump_path').and_return('')
  450. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',))
  451. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  452. 'databases/localhost/foo'
  453. )
  454. flexmock(module.os.path).should_receive('exists').and_return(False)
  455. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  456. flexmock(module).should_receive('execute_command').with_args(
  457. (
  458. 'pg_dump',
  459. '--no-password',
  460. '--clean',
  461. '--if-exists',
  462. '--format',
  463. 'custom',
  464. '--stuff=such',
  465. 'foo',
  466. '>',
  467. 'databases/localhost/foo',
  468. ),
  469. shell=True,
  470. extra_environment={'PGSSLMODE': 'disable'},
  471. run_to_completion=False,
  472. ).and_return(process).once()
  473. assert module.dump_data_sources(
  474. databases,
  475. {},
  476. 'test.yaml',
  477. config_paths=('test.yaml',),
  478. borgmatic_runtime_directory='/run/borgmatic',
  479. source_directories=[],
  480. dry_run=False,
  481. ) == [process]
  482. def test_dump_data_sources_runs_pg_dumpall_for_all_databases():
  483. databases = [{'name': 'all'}]
  484. process = flexmock()
  485. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  486. flexmock(module).should_receive('make_dump_path').and_return('')
  487. flexmock(module).should_receive('database_names_to_dump').and_return(('all',))
  488. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  489. 'databases/localhost/all'
  490. )
  491. flexmock(module.os.path).should_receive('exists').and_return(False)
  492. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  493. flexmock(module).should_receive('execute_command').with_args(
  494. ('pg_dumpall', '--no-password', '--clean', '--if-exists', '>', 'databases/localhost/all'),
  495. shell=True,
  496. extra_environment={'PGSSLMODE': 'disable'},
  497. run_to_completion=False,
  498. ).and_return(process).once()
  499. assert module.dump_data_sources(
  500. databases,
  501. {},
  502. 'test.yaml',
  503. config_paths=('test.yaml',),
  504. borgmatic_runtime_directory='/run/borgmatic',
  505. source_directories=[],
  506. dry_run=False,
  507. ) == [process]
  508. def test_dump_data_sources_runs_non_default_pg_dump():
  509. databases = [{'name': 'foo', 'pg_dump_command': 'special_pg_dump --compress *'}]
  510. process = flexmock()
  511. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  512. flexmock(module).should_receive('make_dump_path').and_return('')
  513. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',))
  514. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  515. 'databases/localhost/foo'
  516. )
  517. flexmock(module.os.path).should_receive('exists').and_return(False)
  518. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  519. flexmock(module).should_receive('execute_command').with_args(
  520. (
  521. 'special_pg_dump',
  522. '--compress',
  523. "'*'", # Should get shell escaped to prevent injection attacks.
  524. '--no-password',
  525. '--clean',
  526. '--if-exists',
  527. '--format',
  528. 'custom',
  529. 'foo',
  530. '>',
  531. 'databases/localhost/foo',
  532. ),
  533. shell=True,
  534. extra_environment={'PGSSLMODE': 'disable'},
  535. run_to_completion=False,
  536. ).and_return(process).once()
  537. assert module.dump_data_sources(
  538. databases,
  539. {},
  540. 'test.yaml',
  541. config_paths=('test.yaml',),
  542. borgmatic_runtime_directory='/run/borgmatic',
  543. source_directories=[],
  544. dry_run=False,
  545. ) == [process]
  546. def test_restore_data_source_dump_runs_pg_restore():
  547. hook_config = [{'name': 'foo', 'schemas': None}, {'name': 'bar'}]
  548. extract_process = flexmock(stdout=flexmock())
  549. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  550. flexmock(module).should_receive('make_dump_path')
  551. flexmock(module.dump).should_receive('make_data_source_dump_filename')
  552. flexmock(module).should_receive('execute_command_with_processes').with_args(
  553. (
  554. 'pg_restore',
  555. '--no-password',
  556. '--if-exists',
  557. '--exit-on-error',
  558. '--clean',
  559. '--dbname',
  560. 'foo',
  561. ),
  562. processes=[extract_process],
  563. output_log_level=logging.DEBUG,
  564. input_file=extract_process.stdout,
  565. extra_environment={'PGSSLMODE': 'disable'},
  566. ).once()
  567. flexmock(module).should_receive('execute_command').with_args(
  568. (
  569. 'psql',
  570. '--no-password',
  571. '--no-psqlrc',
  572. '--quiet',
  573. '--dbname',
  574. 'foo',
  575. '--command',
  576. 'ANALYZE',
  577. ),
  578. extra_environment={'PGSSLMODE': 'disable'},
  579. ).once()
  580. module.restore_data_source_dump(
  581. hook_config,
  582. {},
  583. 'test.yaml',
  584. data_source={'name': 'foo'},
  585. dry_run=False,
  586. extract_process=extract_process,
  587. connection_params={
  588. 'hostname': None,
  589. 'port': None,
  590. 'username': None,
  591. 'password': None,
  592. },
  593. borgmatic_runtime_directory='/run/borgmatic',
  594. )
  595. def test_restore_data_source_dump_runs_pg_restore_with_hostname_and_port():
  596. hook_config = [
  597. {'name': 'foo', 'hostname': 'database.example.org', 'port': 5433, 'schemas': None}
  598. ]
  599. extract_process = flexmock(stdout=flexmock())
  600. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  601. flexmock(module).should_receive('make_dump_path')
  602. flexmock(module.dump).should_receive('make_data_source_dump_filename')
  603. flexmock(module).should_receive('execute_command_with_processes').with_args(
  604. (
  605. 'pg_restore',
  606. '--no-password',
  607. '--if-exists',
  608. '--exit-on-error',
  609. '--clean',
  610. '--dbname',
  611. 'foo',
  612. '--host',
  613. 'database.example.org',
  614. '--port',
  615. '5433',
  616. ),
  617. processes=[extract_process],
  618. output_log_level=logging.DEBUG,
  619. input_file=extract_process.stdout,
  620. extra_environment={'PGSSLMODE': 'disable'},
  621. ).once()
  622. flexmock(module).should_receive('execute_command').with_args(
  623. (
  624. 'psql',
  625. '--no-password',
  626. '--no-psqlrc',
  627. '--quiet',
  628. '--host',
  629. 'database.example.org',
  630. '--port',
  631. '5433',
  632. '--dbname',
  633. 'foo',
  634. '--command',
  635. 'ANALYZE',
  636. ),
  637. extra_environment={'PGSSLMODE': 'disable'},
  638. ).once()
  639. module.restore_data_source_dump(
  640. hook_config,
  641. {},
  642. 'test.yaml',
  643. data_source=hook_config[0],
  644. dry_run=False,
  645. extract_process=extract_process,
  646. connection_params={
  647. 'hostname': None,
  648. 'port': None,
  649. 'username': None,
  650. 'password': None,
  651. },
  652. borgmatic_runtime_directory='/run/borgmatic',
  653. )
  654. def test_restore_data_source_dump_runs_pg_restore_with_username_and_password():
  655. hook_config = [
  656. {'name': 'foo', 'username': 'postgres', 'password': 'trustsome1', 'schemas': None}
  657. ]
  658. extract_process = flexmock(stdout=flexmock())
  659. flexmock(module).should_receive('make_extra_environment').and_return(
  660. {'PGPASSWORD': 'trustsome1', 'PGSSLMODE': 'disable'}
  661. )
  662. flexmock(module).should_receive('make_dump_path')
  663. flexmock(module.dump).should_receive('make_data_source_dump_filename')
  664. flexmock(module).should_receive('execute_command_with_processes').with_args(
  665. (
  666. 'pg_restore',
  667. '--no-password',
  668. '--if-exists',
  669. '--exit-on-error',
  670. '--clean',
  671. '--dbname',
  672. 'foo',
  673. '--username',
  674. 'postgres',
  675. ),
  676. processes=[extract_process],
  677. output_log_level=logging.DEBUG,
  678. input_file=extract_process.stdout,
  679. extra_environment={'PGPASSWORD': 'trustsome1', 'PGSSLMODE': 'disable'},
  680. ).once()
  681. flexmock(module).should_receive('execute_command').with_args(
  682. (
  683. 'psql',
  684. '--no-password',
  685. '--no-psqlrc',
  686. '--quiet',
  687. '--username',
  688. 'postgres',
  689. '--dbname',
  690. 'foo',
  691. '--command',
  692. 'ANALYZE',
  693. ),
  694. extra_environment={'PGPASSWORD': 'trustsome1', 'PGSSLMODE': 'disable'},
  695. ).once()
  696. module.restore_data_source_dump(
  697. hook_config,
  698. {},
  699. 'test.yaml',
  700. data_source=hook_config[0],
  701. dry_run=False,
  702. extract_process=extract_process,
  703. connection_params={
  704. 'hostname': None,
  705. 'port': None,
  706. 'username': None,
  707. 'password': None,
  708. },
  709. borgmatic_runtime_directory='/run/borgmatic',
  710. )
  711. def test_restore_data_source_dump_with_connection_params_uses_connection_params_for_restore():
  712. hook_config = [
  713. {
  714. 'name': 'foo',
  715. 'hostname': 'database.example.org',
  716. 'port': 5433,
  717. 'username': 'postgres',
  718. 'password': 'trustsome1',
  719. 'restore_hostname': 'restorehost',
  720. 'restore_port': 'restoreport',
  721. 'restore_username': 'restoreusername',
  722. 'restore_password': 'restorepassword',
  723. 'schemas': None,
  724. }
  725. ]
  726. extract_process = flexmock(stdout=flexmock())
  727. flexmock(module).should_receive('make_extra_environment').and_return(
  728. {'PGPASSWORD': 'clipassword', 'PGSSLMODE': 'disable'}
  729. )
  730. flexmock(module).should_receive('make_dump_path')
  731. flexmock(module.dump).should_receive('make_data_source_dump_filename')
  732. flexmock(module).should_receive('execute_command_with_processes').with_args(
  733. (
  734. 'pg_restore',
  735. '--no-password',
  736. '--if-exists',
  737. '--exit-on-error',
  738. '--clean',
  739. '--dbname',
  740. 'foo',
  741. '--host',
  742. 'clihost',
  743. '--port',
  744. 'cliport',
  745. '--username',
  746. 'cliusername',
  747. ),
  748. processes=[extract_process],
  749. output_log_level=logging.DEBUG,
  750. input_file=extract_process.stdout,
  751. extra_environment={'PGPASSWORD': 'clipassword', 'PGSSLMODE': 'disable'},
  752. ).once()
  753. flexmock(module).should_receive('execute_command').with_args(
  754. (
  755. 'psql',
  756. '--no-password',
  757. '--no-psqlrc',
  758. '--quiet',
  759. '--host',
  760. 'clihost',
  761. '--port',
  762. 'cliport',
  763. '--username',
  764. 'cliusername',
  765. '--dbname',
  766. 'foo',
  767. '--command',
  768. 'ANALYZE',
  769. ),
  770. extra_environment={'PGPASSWORD': 'clipassword', 'PGSSLMODE': 'disable'},
  771. ).once()
  772. module.restore_data_source_dump(
  773. hook_config,
  774. {},
  775. 'test.yaml',
  776. data_source={'name': 'foo'},
  777. dry_run=False,
  778. extract_process=extract_process,
  779. connection_params={
  780. 'hostname': 'clihost',
  781. 'port': 'cliport',
  782. 'username': 'cliusername',
  783. 'password': 'clipassword',
  784. },
  785. borgmatic_runtime_directory='/run/borgmatic',
  786. )
  787. def test_restore_data_source_dump_without_connection_params_uses_restore_params_in_config_for_restore():
  788. hook_config = [
  789. {
  790. 'name': 'foo',
  791. 'hostname': 'database.example.org',
  792. 'port': 5433,
  793. 'username': 'postgres',
  794. 'password': 'trustsome1',
  795. 'schemas': None,
  796. 'restore_hostname': 'restorehost',
  797. 'restore_port': 'restoreport',
  798. 'restore_username': 'restoreusername',
  799. 'restore_password': 'restorepassword',
  800. }
  801. ]
  802. extract_process = flexmock(stdout=flexmock())
  803. flexmock(module).should_receive('make_extra_environment').and_return(
  804. {'PGPASSWORD': 'restorepassword', 'PGSSLMODE': 'disable'}
  805. )
  806. flexmock(module).should_receive('make_dump_path')
  807. flexmock(module.dump).should_receive('make_data_source_dump_filename')
  808. flexmock(module).should_receive('execute_command_with_processes').with_args(
  809. (
  810. 'pg_restore',
  811. '--no-password',
  812. '--if-exists',
  813. '--exit-on-error',
  814. '--clean',
  815. '--dbname',
  816. 'foo',
  817. '--host',
  818. 'restorehost',
  819. '--port',
  820. 'restoreport',
  821. '--username',
  822. 'restoreusername',
  823. ),
  824. processes=[extract_process],
  825. output_log_level=logging.DEBUG,
  826. input_file=extract_process.stdout,
  827. extra_environment={'PGPASSWORD': 'restorepassword', 'PGSSLMODE': 'disable'},
  828. ).once()
  829. flexmock(module).should_receive('execute_command').with_args(
  830. (
  831. 'psql',
  832. '--no-password',
  833. '--no-psqlrc',
  834. '--quiet',
  835. '--host',
  836. 'restorehost',
  837. '--port',
  838. 'restoreport',
  839. '--username',
  840. 'restoreusername',
  841. '--dbname',
  842. 'foo',
  843. '--command',
  844. 'ANALYZE',
  845. ),
  846. extra_environment={'PGPASSWORD': 'restorepassword', 'PGSSLMODE': 'disable'},
  847. ).once()
  848. module.restore_data_source_dump(
  849. hook_config,
  850. {},
  851. 'test.yaml',
  852. data_source=hook_config[0],
  853. dry_run=False,
  854. extract_process=extract_process,
  855. connection_params={
  856. 'hostname': None,
  857. 'port': None,
  858. 'username': None,
  859. 'password': None,
  860. },
  861. borgmatic_runtime_directory='/run/borgmatic',
  862. )
  863. def test_restore_data_source_dump_runs_pg_restore_with_options():
  864. hook_config = [
  865. {
  866. 'name': 'foo',
  867. 'restore_options': '--harder',
  868. 'analyze_options': '--smarter',
  869. 'schemas': None,
  870. }
  871. ]
  872. extract_process = flexmock(stdout=flexmock())
  873. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  874. flexmock(module).should_receive('make_dump_path')
  875. flexmock(module.dump).should_receive('make_data_source_dump_filename')
  876. flexmock(module).should_receive('execute_command_with_processes').with_args(
  877. (
  878. 'pg_restore',
  879. '--no-password',
  880. '--if-exists',
  881. '--exit-on-error',
  882. '--clean',
  883. '--dbname',
  884. 'foo',
  885. '--harder',
  886. ),
  887. processes=[extract_process],
  888. output_log_level=logging.DEBUG,
  889. input_file=extract_process.stdout,
  890. extra_environment={'PGSSLMODE': 'disable'},
  891. ).once()
  892. flexmock(module).should_receive('execute_command').with_args(
  893. (
  894. 'psql',
  895. '--no-password',
  896. '--no-psqlrc',
  897. '--quiet',
  898. '--dbname',
  899. 'foo',
  900. '--smarter',
  901. '--command',
  902. 'ANALYZE',
  903. ),
  904. extra_environment={'PGSSLMODE': 'disable'},
  905. ).once()
  906. module.restore_data_source_dump(
  907. hook_config,
  908. {},
  909. 'test.yaml',
  910. data_source=hook_config[0],
  911. dry_run=False,
  912. extract_process=extract_process,
  913. connection_params={
  914. 'hostname': None,
  915. 'port': None,
  916. 'username': None,
  917. 'password': None,
  918. },
  919. borgmatic_runtime_directory='/run/borgmatic',
  920. )
  921. def test_restore_data_source_dump_runs_psql_for_all_database_dump():
  922. hook_config = [{'name': 'all', 'schemas': None}]
  923. extract_process = flexmock(stdout=flexmock())
  924. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  925. flexmock(module).should_receive('make_dump_path')
  926. flexmock(module.dump).should_receive('make_data_source_dump_filename')
  927. flexmock(module).should_receive('execute_command_with_processes').with_args(
  928. (
  929. 'psql',
  930. '--no-password',
  931. '--no-psqlrc',
  932. ),
  933. processes=[extract_process],
  934. output_log_level=logging.DEBUG,
  935. input_file=extract_process.stdout,
  936. extra_environment={'PGSSLMODE': 'disable'},
  937. ).once()
  938. flexmock(module).should_receive('execute_command').with_args(
  939. ('psql', '--no-password', '--no-psqlrc', '--quiet', '--command', 'ANALYZE'),
  940. extra_environment={'PGSSLMODE': 'disable'},
  941. ).once()
  942. module.restore_data_source_dump(
  943. hook_config,
  944. {},
  945. 'test.yaml',
  946. data_source={'name': 'all'},
  947. dry_run=False,
  948. extract_process=extract_process,
  949. connection_params={
  950. 'hostname': None,
  951. 'port': None,
  952. 'username': None,
  953. 'password': None,
  954. },
  955. borgmatic_runtime_directory='/run/borgmatic',
  956. )
  957. def test_restore_data_source_dump_runs_psql_for_plain_database_dump():
  958. hook_config = [{'name': 'foo', 'format': 'plain', 'schemas': None}]
  959. extract_process = flexmock(stdout=flexmock())
  960. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  961. flexmock(module).should_receive('make_dump_path')
  962. flexmock(module.dump).should_receive('make_data_source_dump_filename')
  963. flexmock(module).should_receive('execute_command_with_processes').with_args(
  964. ('psql', '--no-password', '--no-psqlrc', '--dbname', 'foo'),
  965. processes=[extract_process],
  966. output_log_level=logging.DEBUG,
  967. input_file=extract_process.stdout,
  968. extra_environment={'PGSSLMODE': 'disable'},
  969. ).once()
  970. flexmock(module).should_receive('execute_command').with_args(
  971. (
  972. 'psql',
  973. '--no-password',
  974. '--no-psqlrc',
  975. '--quiet',
  976. '--dbname',
  977. 'foo',
  978. '--command',
  979. 'ANALYZE',
  980. ),
  981. extra_environment={'PGSSLMODE': 'disable'},
  982. ).once()
  983. module.restore_data_source_dump(
  984. hook_config,
  985. {},
  986. 'test.yaml',
  987. data_source=hook_config[0],
  988. dry_run=False,
  989. extract_process=extract_process,
  990. connection_params={
  991. 'hostname': None,
  992. 'port': None,
  993. 'username': None,
  994. 'password': None,
  995. },
  996. borgmatic_runtime_directory='/run/borgmatic',
  997. )
  998. def test_restore_data_source_dump_runs_non_default_pg_restore_and_psql():
  999. hook_config = [
  1000. {
  1001. 'name': 'foo',
  1002. 'pg_restore_command': 'docker exec --workdir * mycontainer pg_restore',
  1003. 'psql_command': 'docker exec --workdir * mycontainer psql',
  1004. 'schemas': None,
  1005. }
  1006. ]
  1007. extract_process = flexmock(stdout=flexmock())
  1008. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  1009. flexmock(module).should_receive('make_dump_path')
  1010. flexmock(module.dump).should_receive('make_data_source_dump_filename')
  1011. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1012. (
  1013. 'docker',
  1014. 'exec',
  1015. '--workdir',
  1016. "'*'", # Should get shell escaped to prevent injection attacks.
  1017. 'mycontainer',
  1018. 'pg_restore',
  1019. '--no-password',
  1020. '--if-exists',
  1021. '--exit-on-error',
  1022. '--clean',
  1023. '--dbname',
  1024. 'foo',
  1025. ),
  1026. processes=[extract_process],
  1027. output_log_level=logging.DEBUG,
  1028. input_file=extract_process.stdout,
  1029. extra_environment={'PGSSLMODE': 'disable'},
  1030. ).once()
  1031. flexmock(module).should_receive('execute_command').with_args(
  1032. (
  1033. 'docker',
  1034. 'exec',
  1035. '--workdir',
  1036. "'*'", # Should get shell escaped to prevent injection attacks.
  1037. 'mycontainer',
  1038. 'psql',
  1039. '--no-password',
  1040. '--no-psqlrc',
  1041. '--quiet',
  1042. '--dbname',
  1043. 'foo',
  1044. '--command',
  1045. 'ANALYZE',
  1046. ),
  1047. extra_environment={'PGSSLMODE': 'disable'},
  1048. ).once()
  1049. module.restore_data_source_dump(
  1050. hook_config,
  1051. {},
  1052. 'test.yaml',
  1053. data_source=hook_config[0],
  1054. dry_run=False,
  1055. extract_process=extract_process,
  1056. connection_params={
  1057. 'hostname': None,
  1058. 'port': None,
  1059. 'username': None,
  1060. 'password': None,
  1061. },
  1062. borgmatic_runtime_directory='/run/borgmatic',
  1063. )
  1064. def test_restore_data_source_dump_with_dry_run_skips_restore():
  1065. hook_config = [{'name': 'foo', 'schemas': None}]
  1066. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  1067. flexmock(module).should_receive('make_dump_path')
  1068. flexmock(module.dump).should_receive('make_data_source_dump_filename')
  1069. flexmock(module).should_receive('execute_command_with_processes').never()
  1070. module.restore_data_source_dump(
  1071. hook_config,
  1072. {},
  1073. 'test.yaml',
  1074. data_source={'name': 'foo'},
  1075. dry_run=True,
  1076. extract_process=flexmock(),
  1077. connection_params={
  1078. 'hostname': None,
  1079. 'port': None,
  1080. 'username': None,
  1081. 'password': None,
  1082. },
  1083. borgmatic_runtime_directory='/run/borgmatic',
  1084. )
  1085. def test_restore_data_source_dump_without_extract_process_restores_from_disk():
  1086. hook_config = [{'name': 'foo', 'schemas': None}]
  1087. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  1088. flexmock(module).should_receive('make_dump_path')
  1089. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('/dump/path')
  1090. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1091. (
  1092. 'pg_restore',
  1093. '--no-password',
  1094. '--if-exists',
  1095. '--exit-on-error',
  1096. '--clean',
  1097. '--dbname',
  1098. 'foo',
  1099. '/dump/path',
  1100. ),
  1101. processes=[],
  1102. output_log_level=logging.DEBUG,
  1103. input_file=None,
  1104. extra_environment={'PGSSLMODE': 'disable'},
  1105. ).once()
  1106. flexmock(module).should_receive('execute_command').with_args(
  1107. (
  1108. 'psql',
  1109. '--no-password',
  1110. '--no-psqlrc',
  1111. '--quiet',
  1112. '--dbname',
  1113. 'foo',
  1114. '--command',
  1115. 'ANALYZE',
  1116. ),
  1117. extra_environment={'PGSSLMODE': 'disable'},
  1118. ).once()
  1119. module.restore_data_source_dump(
  1120. hook_config,
  1121. {},
  1122. 'test.yaml',
  1123. data_source={'name': 'foo'},
  1124. dry_run=False,
  1125. extract_process=None,
  1126. connection_params={
  1127. 'hostname': None,
  1128. 'port': None,
  1129. 'username': None,
  1130. 'password': None,
  1131. },
  1132. borgmatic_runtime_directory='/run/borgmatic',
  1133. )
  1134. def test_restore_data_source_dump_with_schemas_restores_schemas():
  1135. hook_config = [{'name': 'foo', 'schemas': ['bar', 'baz']}]
  1136. flexmock(module).should_receive('make_extra_environment').and_return({'PGSSLMODE': 'disable'})
  1137. flexmock(module).should_receive('make_dump_path')
  1138. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('/dump/path')
  1139. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1140. (
  1141. 'pg_restore',
  1142. '--no-password',
  1143. '--if-exists',
  1144. '--exit-on-error',
  1145. '--clean',
  1146. '--dbname',
  1147. 'foo',
  1148. '/dump/path',
  1149. '--schema',
  1150. 'bar',
  1151. '--schema',
  1152. 'baz',
  1153. ),
  1154. processes=[],
  1155. output_log_level=logging.DEBUG,
  1156. input_file=None,
  1157. extra_environment={'PGSSLMODE': 'disable'},
  1158. ).once()
  1159. flexmock(module).should_receive('execute_command').with_args(
  1160. (
  1161. 'psql',
  1162. '--no-password',
  1163. '--no-psqlrc',
  1164. '--quiet',
  1165. '--dbname',
  1166. 'foo',
  1167. '--command',
  1168. 'ANALYZE',
  1169. ),
  1170. extra_environment={'PGSSLMODE': 'disable'},
  1171. ).once()
  1172. module.restore_data_source_dump(
  1173. hook_config,
  1174. {},
  1175. 'test.yaml',
  1176. data_source=hook_config[0],
  1177. dry_run=False,
  1178. extract_process=None,
  1179. connection_params={
  1180. 'hostname': None,
  1181. 'port': None,
  1182. 'username': None,
  1183. 'password': None,
  1184. },
  1185. borgmatic_runtime_directory='/run/borgmatic',
  1186. )