Compare commits
723 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a897ffd514 | |||
| a472735616 | |||
| b3fec03cf4 | |||
| 89dccc25c3 | |||
| 3846155d62 | |||
| 386979ebb4 | |||
| 07222cd984 | |||
| cf4c6c274d | |||
| 340bd72176 | |||
| 1a1bb71af1 | |||
| ae45dfe63a | |||
| d6ac7a9192 | |||
| d959fdbf8d | |||
| 81739791e0 | |||
| 4cdff74e9b | |||
| 11e830bb1d | |||
| cba00a9c4e | |||
| f2198de151 | |||
|
0c439c0c02 |
|||
| f11a9bb4aa | |||
| ee6f390910 | |||
|
9a5117db14 |
|||
| 9585c8f908 | |||
| 3495484ddd | |||
| 67ab2acb82 | |||
| c085bacccf | |||
| 896401088e | |||
| ef3dda9213 | |||
| c9f5d9b048 | |||
| ccbd0b608b | |||
| a7cc2ea803 | |||
| 9ec75ccf3f | |||
| 7c890be76d | |||
| 39e5aac479 | |||
| e25f2c4e6c | |||
| 7ad8f9ac6f | |||
| 2add3ff7ad | |||
| 0602ca1862 | |||
| e973802fc1 | |||
| 2bdf6dfd70 | |||
| f894c49540 | |||
| 7900e5ea53 | |||
| 5587f48bda | |||
| de3ee07566 | |||
| fe39453598 | |||
| 9c75063c05 | |||
| 5cf2ef1732 | |||
| f35e6ea7ad | |||
| 90595e9c18 | |||
| 032d4adee3 | |||
| 4444219e17 | |||
| 56fd78089d | |||
| 86dbc00cbe | |||
| c644270599 | |||
| 1676a98c51 | |||
| 358ed53da0 | |||
| 90925c9428 | |||
| cd192a6909 | |||
| 7185146481 | |||
| c15e6c5fe5 | |||
| 79c2b9df06 | |||
| acd6772148 | |||
| cd91dbd4f7 | |||
| 8fc4efff88 | |||
| 4bf3e906a1 | |||
| 0ca43ef67a | |||
| 603e055a39 | |||
| 75c04611dc | |||
| 881dc9b01e | |||
| 8c72e909a7 | |||
| 74ac148747 | |||
| be7887c071 | |||
| da459d95b8 | |||
| b3aa6af859 | |||
| b816af1b13 | |||
| 276aeb9875 | |||
| de94001508 | |||
| 7cfab3620b | |||
| 6c136ebbf1 | |||
| eaa5eb4174 | |||
| acc2a39454 | |||
| a10c7a8496 | |||
| de82919e39 | |||
| 1ba56d5262 | |||
| 1c825b5d84 | |||
| d6d66de251 | |||
| 76d79f0331 | |||
| dc43c38e29 | |||
| 7d7308a80d | |||
| b43ef9d76d | |||
| 28cdd67743 | |||
| 7f126ce127 | |||
| a6c4debf78 | |||
| a74ad5475e | |||
| fa293828df | |||
| f5582b1754 | |||
| 1af95714c2 | |||
| 0406d18cfd | |||
| 66e9ec9c3c | |||
| 899a7c8318 | |||
| 7c01b69498 | |||
| 4f0d3bf4ed | |||
| 9a5e7a3abb | |||
| 02eb6c7e09 | |||
| 418c09398c | |||
| cdbd4c55e8 | |||
| 2374410891 | |||
| d2c46e91fe | |||
| 12441331e6 | |||
| 9ceeae2de0 | |||
| e0e493c2f1 | |||
| 0f05f7ad93 | |||
| 9bc1b71017 | |||
| b3776871b5 | |||
| 308cb31bf9 | |||
| e1f4643215 | |||
| bc4fb322b5 | |||
| 2c4f192e43 | |||
| fb7a6dccaa | |||
| 2826b7bd7c | |||
| 932848f6c1 | |||
| 9255940c6b | |||
| 3eadd16856 | |||
| 61f46c5ad5 | |||
| aad47d1741 | |||
| 079dd3fe4c | |||
| d47f1bff4d | |||
| 53967f6324 | |||
| f5a70dc2a5 | |||
| 31ae1013d7 | |||
| 071945e558 | |||
| 5c4d6a6e83 | |||
| 9c9be65b2b | |||
| c164684703 | |||
| 842c9001ba | |||
| 481e47076e | |||
|
917a0dd0a0 |
|||
|
358aed7c31 |
|||
| 9893834e85 | |||
| 32cf3225c5 | |||
| 2bfd7518c5 | |||
| 4ba56684d1 | |||
| 0b1e38e5f6 | |||
|
7974219389 |
|||
|
8424e443a9 |
|||
|
85251cf5d4 |
|||
| 8f882ea3ea | |||
| 7a2bcc96bb | |||
| 8b41e58e1f | |||
| 9417359da3 | |||
| 1cf0e1bd84 | |||
| 223f803e87 | |||
| 6cb901d083 | |||
| 096be14230 | |||
| bb8b1e58e8 | |||
| 06261d8c86 | |||
| 869cccf884 | |||
| 0defaf9cb5 | |||
| 60b1f9921d | |||
| f61bc91b0f | |||
| ed2c6053de | |||
| 2cffa8deaa | |||
| f0581271f6 | |||
| 99522234ea | |||
| 67f2862fb1 | |||
|
1c0dc3f904 |
|||
|
b94dbff216 |
|||
| 7388c723cd | |||
| 128be3c17d | |||
|
4c30c94258 |
|||
|
20b8b45aeb |
|||
| 2dd899f287 | |||
| a13cc0ab17 | |||
| 620f9e64d6 | |||
| 25c320b281 | |||
| f19eec56ac | |||
| 7cbcff2e9b | |||
| 9f6407ada6 | |||
| e933ecf046 | |||
|
4010a2ed77 |
|||
|
2f36096e1a |
|||
|
82ec45e375 |
|||
| 37362150fe | |||
| a7ba97803f | |||
| 31dc903877 | |||
| 8943867433 | |||
| d9cb110563 | |||
| 32113cee67 | |||
|
a621ce199a |
|||
|
1f524d6c87 |
|||
|
0320d449ec |
|||
|
30f007687a |
|||
|
adf7856162 |
|||
|
f9dce8b2d3 |
|||
|
15cb6270ef |
|||
|
ed14fdbac9 |
|||
| 8650a15db1 | |||
| 6a10022543 | |||
|
52e4f48eb9 |
|||
| f5e1e8bec9 | |||
| a291477c19 | |||
| 1c88dda76a | |||
| 0b59c22c23 | |||
| 576377e2b2 | |||
| 6ff1867312 | |||
| 3cb52423d2 | |||
| 5a5b6491ac | |||
| 4272c6b077 | |||
| 26071de2e7 | |||
| fe92d9e838 | |||
| 5ea2d644a2 | |||
| c35f90154f | |||
| 36305c50b1 | |||
| 2b3b8eab71 | |||
| aa7c7651e5 | |||
| c41ffb5ceb | |||
| 766a03375a | |||
| 2a4d4247e3 | |||
| 9de5083a7e | |||
| d0557b2bcd | |||
| 1a980d6321 | |||
| fb21d4e645 | |||
| 5933a4d778 | |||
| 8cf16c7831 | |||
|
fcf4e03c2f |
|||
| d1b29e82da | |||
| 290e969a22 | |||
| 18ae91ea6e | |||
| 0bce77a2ac | |||
| 19155607af | |||
| f357c37e2c | |||
| 2980c14728 | |||
| 7e0e00d45d | |||
| 8b4ac0017b | |||
| 8ec1ec527e | |||
| 6096a7181c | |||
| fa9dfb8ff7 | |||
| 2dc006aab4 | |||
| 031b9d6faf | |||
|
d9018a47f6 |
|||
|
|
e893a20dfd |
||
| 09d521661f | |||
| fd46efb193 | |||
| 426f54c9cc | |||
| 45a537b6b1 | |||
| d6feca169c | |||
| 05e2900ab0 | |||
| 30b52e5523 | |||
| 14aeddc11f | |||
| 066399ecdb | |||
| d4bbac4467 | |||
| 7516443a89 | |||
| 73d67e29b4 | |||
| c3e7425f4c | |||
| cc9dbb1def | |||
| 2045edc11b | |||
| 1dcac44d6c | |||
| 300ead65d3 | |||
| 6a0219a7a4 | |||
| 80c69aac05 | |||
| 7417a3cd00 | |||
| 9ca80a54d8 | |||
| 5c0b17ef39 | |||
| 1697d8aaef | |||
| fef441a8ff | |||
| c1ddc4268b | |||
| e323290e61 | |||
| 1ab44d4201 | |||
| 71b1c3dfb0 | |||
| 695930a607 | |||
| eb2a4ff1f0 | |||
| 531d5c80c0 | |||
| 067ed27689 | |||
| fa38de2de7 | |||
| e4d1b49c39 | |||
| af7caec509 | |||
| 90c1f899fc | |||
| a0691ae4cd | |||
| 2f20e6f808 | |||
| 7a4636ae0f | |||
| 53435dcc3e | |||
| 4d01278037 | |||
| 2299e5d41e | |||
| d16f5d5df3 | |||
| da8e9638f4 | |||
| 900ea80a42 | |||
| 4b92d0f685 | |||
| 3ce5533103 | |||
| 4a1ee8c911 | |||
| 3f22a99412 | |||
| caf95cc913 | |||
| fd3130b4d9 | |||
| 65bb5a49e2 | |||
| 4bcc517326 | |||
| 0b164973e0 | |||
| a125df991b | |||
| f9a9b42c58 | |||
| 56ad1d164a | |||
| 3cce18919c | |||
| 76d6a69f5a | |||
| 3db17277b4 | |||
| ece49eb500 | |||
| 746428ed44 | |||
| 984702b3b2 | |||
| 1bc71e1c5d | |||
| 47efa88c9d | |||
| 3821636b77 | |||
| 596f6f9dac | |||
|
7ecdaea83a |
|||
|
|
98cb2644db |
||
| 31db6faa19 | |||
| 872d8b695a | |||
| 6db3e1dda5 | |||
|
|
9aaf78b9dd | ||
| 5d8ac158ce | |||
| d32a53d58f | |||
| a836ec944f | |||
| e7b128e735 | |||
| ff3cb1d80f | |||
| c5ff08ee25 | |||
| 856db29180 | |||
|
|
20e09b4ea8 | ||
| 1dd0682661 | |||
| 7252b8d614 | |||
|
|
e5870a169b | ||
| 94795a3560 | |||
| 7705debab0 | |||
| f87df0527f | |||
| e4512a40e0 | |||
| 1d4a9510b8 | |||
| 2648f07e7a | |||
| 459bf1fcf6 | |||
| 3930e63320 | |||
| acecb1e397 | |||
| 9b48eb5a61 | |||
| 7d40a448cb | |||
| da7aed3814 | |||
| c7f4200417 | |||
| 5e2a5494af | |||
| 7b77fd2510 | |||
| ece5608677 | |||
| 4644f613b2 | |||
| 3afa5ac76d | |||
| 27f8a1df04 | |||
| 8e5b0bbf17 | |||
| 282e9565c9 | |||
| b714ffd48b | |||
| 9968a15ef8 | |||
| d93da55ce9 | |||
| 789bcd402a | |||
| cf6ab60d2e | |||
| 64364b20ff | |||
| d29c7956bc | |||
| e5ef485d6b | |||
| fc8046edc4 | |||
| 4538017206 | |||
| d664b6d253 | |||
| f42aa0a6f2 | |||
| 9d4ba66f6e | |||
| cf846ab8ac | |||
| 219e287c6c | |||
| dede8f9d4b | |||
| 7a1e3f5639 | |||
|
|
9bd77292ff | ||
| f1a143de5b | |||
| 765e343c71 | |||
| af4b91a048 | |||
| cc9044487b | |||
| 11c30001c3 | |||
| ac9161035a | |||
| 007ec0644c | |||
| 1db808fb3d | |||
| 76656275c3 | |||
|
|
64bdbc4bf0 | ||
| 61033bb4e5 | |||
| e608b7924a | |||
| f7f852a28b | |||
| 9b9c4c4abb | |||
| 1b59f5b190 | |||
| 65ab230961 | |||
|
|
c64d0100d5 | ||
| 0112407250 | |||
| 2d3f5fa05d | |||
| a87036ee46 | |||
| a72f5ff69a | |||
|
|
bb99009191 | ||
| 4c45d60529 | |||
| 2211f959ae | |||
| cc1d6f53a0 | |||
| 389778c716 | |||
|
|
e55e9e8139 | ||
| ef76e87477 | |||
| 62526038d6 | |||
| bf2f39623e | |||
| 28c890a52d | |||
| cd189c4fe4 | |||
| b8f6bab12d | |||
| 50b3240c4f | |||
| 18fbc75e16 | |||
| 0881da4a82 | |||
|
|
fa210766a2 | ||
|
|
d4f52e3137 | ||
|
|
8b2ebdc5f7 | ||
| a00407256d | |||
| 24b5eccefc | |||
|
|
815fb39a05 | ||
|
|
24c196d2a4 | ||
|
|
3e26e70d0c | ||
|
|
5ce25e2790 | ||
|
|
8243552c8c | ||
|
|
425e27dee5 | ||
|
|
9ec9269a18 | ||
|
|
bf5cbd1deb | ||
|
|
4c09cbf1a4 | ||
|
|
fc077af4ce | ||
|
|
ca4312bb85 | ||
|
|
fc3b1fccba | ||
|
|
f83346b9b3 | ||
|
|
63c7241aec | ||
|
|
fd77dc579e | ||
|
|
f017ed648f | ||
|
|
27a6745743 | ||
|
|
95be0c8e46 | ||
|
|
17a774ba7e | ||
|
|
a1d2bd173b | ||
|
|
f495550ad7 | ||
|
|
43d0e597a2 | ||
|
|
f1c07b5cf5 | ||
|
|
f2782426d5 | ||
|
|
f13ed92b0e | ||
|
|
6e9e7c45d7 | ||
|
|
c1ca4b9421 | ||
|
|
469feadbc0 | ||
|
|
a5403a4373 | ||
|
|
56c902258d | ||
|
|
9c1660f467 | ||
|
|
dd926b5762 | ||
|
|
9d03351b5d | ||
|
|
719d9a9835 | ||
|
|
731c8c9ad9 | ||
| 2ae8ac2947 | |||
| cc94e5f52f | |||
| a09c9f248e | |||
| 16f0a3976c | |||
| cc78223164 | |||
| 30f56235c1 | |||
| 7458769cb3 | |||
| a5aa9355f5 | |||
| 5c229639f0 | |||
| 059322b7f8 | |||
|
|
f1a98d82c6 | ||
|
|
80e2c023dd | ||
|
|
86511deac4 | ||
|
|
bb3475b3f8 | ||
| bd196c1fb9 | |||
| 873fc22cfb | |||
| f3d6d7c0a3 | |||
| 86cc6ca869 | |||
| d30caa422e | |||
| 84c148fb3b | |||
| 6c4f641c1e | |||
| b44bc57548 | |||
| bb18a9a3f2 | |||
| f7dcbe40d4 | |||
|
|
95533d2b31 | ||
|
|
867d3fceb0 | ||
| 3af92f8b92 | |||
| 7c048d1989 | |||
| d127e73590 | |||
| 13ba5c84de | |||
| 50c4f6f2a1 | |||
| 9588e111c4 | |||
| 37ae34a432 | |||
| e3a559e13b | |||
| 3664ac7418 | |||
| 3f83788858 | |||
| 10cac46f4c | |||
| b1f429f4b5 | |||
| 51095cd419 | |||
| ddd56bf2a7 | |||
| 674a6153f3 | |||
| 793ffbd048 | |||
| aa04473521 | |||
| 247d36a309 | |||
| 77d3c66fb9 | |||
| 9f5b808042 | |||
| 9bea7ae5ed | |||
| e85d487c3a | |||
| 23679a6edd | |||
| 525ffa6a28 | |||
| 0f44fbedf4 | |||
| ac47301a64 | |||
| ae15e0f404 | |||
| 9347c02268 | |||
| a2e8abc537 | |||
| ceeaf25443 | |||
| 10404143c6 | |||
| 62d2b267da | |||
| 94aaf4554f | |||
| 03d50d74ca | |||
| 0c8816e6cc | |||
| 7ed5b33db5 | |||
| e3e4aeff94 | |||
| 57b3066987 | |||
| 89cd879529 | |||
| 1527ff7898 | |||
| 2c61c0bc08 | |||
| 3967e1b5f0 | |||
| bcd8b9982d | |||
| 8cbd51512b | |||
| b36b923c5d | |||
| c38f7a3693 | |||
| f44a7884e6 | |||
| 7c77a5a8a5 | |||
| b61b09f55c | |||
| 9caaee18b5 | |||
| 588955a467 | |||
| 7c0407ed22 | |||
| ee3edeaac2 | |||
| 499f8aa0a4 | |||
| 90a0d3b1e0 | |||
| 548212274f | |||
| cd8ceccfaf | |||
| 1292dd2162 | |||
| e5c12fc81c | |||
| b02ac44cfc | |||
| f5abe05ce9 | |||
| 52963adfc9 | |||
| 6af53d1163 | |||
| 2274cfe480 | |||
| 3cccac8cb1 | |||
| 8cf52651fe | |||
| 919d7573c3 | |||
| 166ef8faae | |||
| 8bfffd8cf7 | |||
| ac2a63763f | |||
| edb54b300b | |||
| 8b2b41eefc | |||
| 41d202c2e7 | |||
| fb172f018a | |||
| 8ef6c6fcbe | |||
| b1355e75c4 | |||
| 0691cda46f | |||
| d2c143d39c | |||
| 8bf07e4766 | |||
| ef32b292a8 | |||
| b3d0fb0cee | |||
| 61f88228b0 | |||
| ff28be7724 | |||
| f98558546c | |||
| 5ff016238e | |||
| 9cc7c77ba9 | |||
| 618e56b2a5 | |||
| 3b1b058ffe | |||
| 338b80903c | |||
| 9a3b52e1fd | |||
| fea97b5149 | |||
| 0dfc935af6 | |||
| 17c87f8758 | |||
| 2f7527a333 | |||
| d49be19544 | |||
| 263891f414 | |||
| d4ae7814a0 | |||
| 644c2e6612 | |||
| dc9b075d5a | |||
| 999feb81ca | |||
| 1bcb2a8be4 | |||
| f581f4b8d9 | |||
| a16d90ff46 | |||
| c7803a2814 | |||
| e50fd04750 | |||
| f4e5dc8382 | |||
| 745de200df | |||
| f19a40ef9c | |||
| bff6980eee | |||
| 483bd50bdf | |||
| 1dc60d2856 | |||
| 5110e64e63 | |||
| 6e85940d63 | |||
| 4d7556f68b | |||
| e00f74ddf7 | |||
| 9212f87735 | |||
| 1aaf27dfb2 | |||
| ebd34f1695 | |||
| 87c65fb723 | |||
| a34dccbd27 | |||
| abb6bed459 | |||
| 49c4f483fd | |||
| 5bd1cc5580 | |||
| 4447956da7 | |||
| f6d2e983d9 | |||
| 9a96a277e6 | |||
| 6bfe524bac | |||
| a45d7bec81 | |||
| ead991dcd1 | |||
| 63c4bf3bf9 | |||
| b22b552bf3 | |||
| ed0127df91 | |||
| 938392b25b | |||
| 17e9f21fb9 | |||
| 481dbc14c3 | |||
| 16cc77fd9d | |||
| 600c438951 | |||
| 5d9bb13410 | |||
| 2e3e68d2cb | |||
| da513c1089 | |||
| 331adca23e | |||
| e1e5db22f8 | |||
| 377e3948ff | |||
| 4533fec167 | |||
| 633700c0af | |||
| 007b3e6d4e | |||
|
|
175761c757 | ||
| c7e23fe9ed | |||
| 9e45da75cb | |||
| 0ea5824427 | |||
| 5b66dc69a1 | |||
| 8210172d7f | |||
| 82e8dae948 | |||
| fa87aed263 | |||
| c3b4cb21ed | |||
| 030b321e39 | |||
|
|
15bf273e6e | ||
| cf545ae93a | |||
| 45a2b9cded | |||
|
953d08ba63 |
|||
|
88da0c3039 |
|||
| 0012e0cdea | |||
| 049f9c8853 | |||
| 31482ee559 | |||
| 1ffff3255a | |||
|
9e52be6ffd |
|||
|
978096b402 |
|||
| cc6aa7af05 | |||
|
32858fb0b4 |
|||
| e59845d4e1 | |||
| 9437e95849 | |||
| 3a3851d2a5 | |||
| 80318e6e30 | |||
| 6756ca8311 | |||
|
|
fa7955b8cf | ||
| 944c0212c3 | |||
| 2456fc67f1 | |||
| 8a58b72934 | |||
| 6dc0173b74 | |||
| 5c58f85be1 | |||
| 3a9e32a411 | |||
| 30f6ec4f7d | |||
| c67ab09e4d | |||
| 5299046b6b | |||
| 204e515bf7 | |||
| 1334da99e2 | |||
| 996ca19dac | |||
| 61969d17a2 | |||
| d041e23d35 | |||
|
|
e996e09657 | ||
|
|
9c06874073 | ||
|
|
f5e0e10143 | ||
|
|
952a691f60 | ||
|
|
f94181480c | ||
|
|
c27b4a3497 | ||
|
|
58d33503a1 | ||
|
|
38322a3f6f | ||
| 52ab7cb881 | |||
| 17ac63aae6 | |||
| 1f1c8fdaba | |||
|
|
ce6196a5c6 | ||
|
|
6b0aa13856 | ||
|
|
d25db4cd0d | ||
|
|
7097ed67a6 | ||
|
|
52d5240fa0 | ||
|
|
5bf3a4875c | ||
|
|
d9125451f5 | ||
|
|
c3613e0637 | ||
|
|
c8f1af635f | ||
|
|
cfd61dc1d1 | ||
| 7750d2568c | |||
| 4e4f8c2670 | |||
| cb402d6846 | |||
| aa1178dc49 | |||
| 3506819511 | |||
| ac6c927a23 | |||
| bda6451c1d | |||
| d9e396e264 | |||
| 66286f92df | |||
| 715b240589 | |||
| ee5697ac37 | |||
| aa48b95ee7 | |||
| 2639b7105a | |||
| 02df59e964 | |||
| f23810f19a | |||
| 9f5dd6c10d | |||
| eaf2bd22c1 | |||
| b1113d57ae | |||
| dbd312981e | |||
| 511314a54a | |||
| 18267b9677 | |||
| 056ed7184b | |||
| b94c106a36 | |||
| 965dd1aabe | |||
| 626dd66254 | |||
| d46e370950 | |||
| 126bb279cd | |||
| d0eae19556 | |||
| 69971cd7e2 | |||
| 45c6541266 | |||
| 65c837c828 | |||
| 8a4167b7a3 | |||
| 814770c2a9 | |||
| f862eda7d6 | |||
| 5472424d5a | |||
| 10a449fe1a | |||
| f557e2cbbd | |||
|
|
704b97a636 | ||
| 200a1bd63e | |||
| cf4c262226 | |||
| 7b5363ce14 | |||
| 42d9e2bfd8 | |||
| d182509771 | |||
| e567158246 | |||
| db0f057b54 | |||
| 84922c7232 | |||
|
|
16bebe9832 |
134 changed files with 9906 additions and 1146 deletions
2
.dockerignore
Normal file
2
.dockerignore
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
.git
|
||||
.tox
|
||||
57
.drone.yml
Normal file
57
.drone.yml
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
---
|
||||
kind: pipeline
|
||||
name: python-3-5-alpine-3-10
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: python:3.5-alpine3.10
|
||||
pull: always
|
||||
commands:
|
||||
- scripts/run-tests
|
||||
---
|
||||
kind: pipeline
|
||||
name: python-3-6-alpine-3-10
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: python:3.6-alpine3.10
|
||||
pull: always
|
||||
commands:
|
||||
- scripts/run-tests
|
||||
---
|
||||
kind: pipeline
|
||||
name: python-3-7-alpine-3-10
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: python:3.7-alpine3.10
|
||||
pull: always
|
||||
commands:
|
||||
- scripts/run-tests
|
||||
---
|
||||
kind: pipeline
|
||||
name: python-3-7-alpine-3-7
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: python:3.7-alpine3.7
|
||||
pull: always
|
||||
commands:
|
||||
- scripts/run-tests
|
||||
---
|
||||
kind: pipeline
|
||||
name: documentation
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: witten/borgmatic-docs
|
||||
dockerfile: docs/Dockerfile
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
41
.eleventy.js
Normal file
41
.eleventy.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
|
||||
const inclusiveLangPlugin = require("@11ty/eleventy-plugin-inclusive-language");
|
||||
|
||||
module.exports = function(eleventyConfig) {
|
||||
eleventyConfig.addPlugin(pluginSyntaxHighlight);
|
||||
eleventyConfig.addPlugin(inclusiveLangPlugin);
|
||||
|
||||
let markdownIt = require("markdown-it");
|
||||
let markdownItAnchor = require("markdown-it-anchor");
|
||||
let markdownItReplaceLink = require("markdown-it-replace-link");
|
||||
|
||||
let markdownItOptions = {
|
||||
html: true,
|
||||
breaks: false,
|
||||
linkify: true,
|
||||
// Replace links to .md files with links to directories. This allows unparsed Markdown links
|
||||
// to work on GitHub, while rendered links elsewhere also work.
|
||||
replaceLink: function (link, env) {
|
||||
return link.replace(/\.md$/, '/');
|
||||
}
|
||||
};
|
||||
let markdownItAnchorOptions = {
|
||||
permalink: true,
|
||||
permalinkClass: "direct-link"
|
||||
};
|
||||
|
||||
eleventyConfig.setLibrary(
|
||||
"md",
|
||||
markdownIt(markdownItOptions)
|
||||
.use(markdownItAnchor, markdownItAnchorOptions)
|
||||
.use(markdownItReplaceLink)
|
||||
);
|
||||
|
||||
return {
|
||||
templateFormats: [
|
||||
"md",
|
||||
"txt"
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
31
.gitea/issue_template.md
Normal file
31
.gitea/issue_template.md
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#### What I'm trying to do and why
|
||||
|
||||
#### Steps to reproduce (if a bug)
|
||||
|
||||
Include (sanitized) borgmatic configuration files if applicable.
|
||||
|
||||
#### Actual behavior (if a bug)
|
||||
|
||||
Include (sanitized) `--verbosity 2` output if applicable.
|
||||
|
||||
#### Expected behavior (if a bug)
|
||||
|
||||
#### Other notes / implementation ideas
|
||||
|
||||
#### Environment
|
||||
|
||||
**borgmatic version:** [version here]
|
||||
|
||||
Use `sudo borgmatic --version` or `sudo pip show borgmatic | grep ^Version`
|
||||
|
||||
**borgmatic installation method:** [e.g., Debian package, Docker container, etc.]
|
||||
|
||||
**Borg version:** [version here]
|
||||
|
||||
Use `sudo borg --version`
|
||||
|
||||
**Python version:** [version here]
|
||||
|
||||
Use `python3 --version`
|
||||
|
||||
**operating system and version:** [OS here]
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -1,6 +1,10 @@
|
|||
*.egg-info
|
||||
*.pyc
|
||||
*.swp
|
||||
.cache
|
||||
.coverage
|
||||
.pytest_cache
|
||||
.tox
|
||||
build
|
||||
dist
|
||||
build/
|
||||
dist/
|
||||
pip-wheel-metadata/
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
syntax: glob
|
||||
*.egg-info
|
||||
*.pyc
|
||||
*.swp
|
||||
.tox
|
||||
build
|
||||
dist
|
||||
29
.hgtags
29
.hgtags
|
|
@ -1,29 +0,0 @@
|
|||
467d3a3ce9185e84ee51ca9156499162efd94f9a 0.0.2
|
||||
7730ae34665c0dedf46deab90b32780abf6dbaff 0.0.3
|
||||
4bb2e81fc77038be4499b7ea6797ab7d109460e0 0.0.4
|
||||
b31d51b633701554e84f996cc0c73bad2990780b 0.0.5
|
||||
b31d51b633701554e84f996cc0c73bad2990780b 0.0.5
|
||||
aa8a807f4ba28f0652764ed14713ffea2fd6922d 0.0.5
|
||||
aa8a807f4ba28f0652764ed14713ffea2fd6922d 0.0.5
|
||||
569aef47a9b25c55b13753f94706f5d330219995 0.0.5
|
||||
569aef47a9b25c55b13753f94706f5d330219995 0.0.5
|
||||
a03495a8e8b471da63b5e2ae79d3ff9065839c2a 0.0.5
|
||||
7ea93ca83f426ec0a608a68580c72c0775b81f86 0.0.6
|
||||
cf4c7065f0711deda1cba878398bc05390e2c3f9 0.0.7
|
||||
38d72677343f0a5d6845f4ac50d6778397083d45 0.1.0
|
||||
ac5dfa01e9d14d09845f5e94c2c679e21c5eb2f9 0.1.1
|
||||
ac5dfa01e9d14d09845f5e94c2c679e21c5eb2f9 0.1.1
|
||||
7b6c87dca7ea312b2257ac1b46857b3f8c56b39c 0.1.1
|
||||
83067f995dd391e38544a7722dc3b254b59c5521 0.1.2
|
||||
acc7fb61566fe8028c179f43ecc735c851220b06 0.1.3
|
||||
6dda59c12de88f060eb7244e6d330173985a9639 0.1.4
|
||||
6dda59c12de88f060eb7244e6d330173985a9639 0.1.4
|
||||
e58246fc92bb22c2b2fd8b86a1227de69d2d0315 0.1.4
|
||||
0afff209b902698c2266986129d6dc9f5f913101 0.1.5
|
||||
4c63f3d90ec2bf6af1714a3acec84654a7c9edf3 0.1.6
|
||||
5a458ebef804be14e30d7375e3e9fbc26aedb80d 0.1.7
|
||||
977f19c2f6a515be6c5ef69cf17b0e0989532209 github/yaml_config_files
|
||||
0000000000000000000000000000000000000000 github/yaml_config_files
|
||||
28434dd0440cc8da44c2f3e9bd7e9402a59c3b40 github/master
|
||||
dbc96d3f83bd5570b6826537616d4160b3374836 0.1.8
|
||||
0e1fbee9358de4f062fa9539e1355db83db70caa 1.0.0
|
||||
9
AUTHORS
9
AUTHORS
|
|
@ -1,5 +1,12 @@
|
|||
Dan Helfman <witten@torsion.org>: Main developer
|
||||
|
||||
Alexander Görtz: Python 3 compatibility
|
||||
Florian Lindner: Logging rewrite
|
||||
Henning Schroeder: Copy editing
|
||||
Robin `ypid` Schneider: Support additional options of Borg
|
||||
Johannes Feichtner: Support for user hooks
|
||||
Michele Lazzeri: Custom archive names
|
||||
Nick Whyte: Support prefix filtering for archive consistency checks
|
||||
newtonne: Read encryption password from external file
|
||||
Robin `ypid` Schneider: Support additional options of Borg and add validate-borgmatic-config command
|
||||
Scott Squires: Custom archive names
|
||||
Thomas LÉVEIL: Support for a keep_minutely prune option. Support for the --json option
|
||||
|
|
|
|||
2
MANIFEST.in
Normal file
2
MANIFEST.in
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
include borgmatic/config/schema.yaml
|
||||
graft sample/systemd
|
||||
353
NEWS
353
NEWS
|
|
@ -1,6 +1,349 @@
|
|||
1.3.20
|
||||
* #205: More robust sample systemd service: boot delay, network dependency, lowered CPU/IO
|
||||
priority, etc.
|
||||
* #221: Fix "borgmatic create --progress" output so that it updates on the console in real-time.
|
||||
|
||||
1.3.19
|
||||
* #219: Fix visibility of "borgmatic prune --stats" output.
|
||||
|
||||
1.3.18
|
||||
* #220: Fix regression of argument parsing for default actions.
|
||||
|
||||
1.3.17
|
||||
* #217: Fix error with "borgmatic check --only" command-line flag with "extract" consistency check.
|
||||
|
||||
1.3.16
|
||||
* #210: Support for Borg check --verify-data flag via borgmatic "data" consistency check.
|
||||
* #210: Override configured consistency checks via "borgmatic check --only" command-line flag.
|
||||
* When generating sample configuration with generate-borgmatic-config, add a space after each "#"
|
||||
comment indicator.
|
||||
|
||||
1.3.15
|
||||
* #208: Fix for traceback when the "checks" option has an empty value.
|
||||
* #209: Bypass Borg error about a moved repository via "relocated_repo_access_is_ok" option in
|
||||
borgmatic storage configuration section.
|
||||
* #213: Reorder arguments passed to Borg to fix duplicate directories when using Borg patterns.
|
||||
* #214: Fix for hook erroring with exit code 1 not being interpreted as an error.
|
||||
|
||||
1.3.14
|
||||
* #204: Do not treat Borg warnings (exit code 1) as failures.
|
||||
* When validating configuration files, require strings instead of allowing any scalar type.
|
||||
|
||||
1.3.13
|
||||
* #199: Add note to documentation about using spaces instead of tabs for indentation, as YAML does
|
||||
not allow tabs.
|
||||
* #203: Fix compatibility with ruamel.yaml 0.16.x.
|
||||
* If a "prefix" option in borgmatic's configuration has an empty value (blank or ""), then disable
|
||||
default prefix.
|
||||
|
||||
1.3.12
|
||||
* Only log to syslog when run from a non-interactive console (e.g. a cron job).
|
||||
* Remove unicode byte order mark from syslog output so it doesn't show up as a literal in rsyslog
|
||||
output. See discussion on #197.
|
||||
|
||||
1.3.11
|
||||
* #193: Pass through several "borg list" and "borg info" flags like --short, --format, --sort-by,
|
||||
--first, --last, etc. via borgmatic command-line flags.
|
||||
* Add borgmatic info --repository and --archive command-line flags to display info for individual
|
||||
repositories or archives.
|
||||
* Support for Borg --noatime, --noctime, and --nobirthtime flags via corresponding options in
|
||||
borgmatic configuration location section.
|
||||
|
||||
1.3.10
|
||||
* #198: Fix for Borg create error output not showing up at borgmatic verbosity level zero.
|
||||
|
||||
1.3.9
|
||||
* #195: Switch to command-line actions as more traditional sub-commands, e.g. "borgmatic create",
|
||||
"borgmatic prune", etc. However, the classic dashed options like "--create" still work!
|
||||
|
||||
1.3.8
|
||||
* #191: Disable console color via "color" option in borgmatic configuration output section.
|
||||
|
||||
1.3.7
|
||||
* #196: Fix for unclear error message for invalid YAML merge include.
|
||||
* #197: Don't color syslog output.
|
||||
* Change default syslog verbosity to show errors only.
|
||||
|
||||
1.3.6
|
||||
* #53: Log to syslog in addition to existing console logging. Add --syslog-verbosity flag to
|
||||
customize the log level. See the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/inspect-your-backups/
|
||||
* #178: Look for .yml configuration file extension in addition to .yaml.
|
||||
* #189: Set umask used when executing hooks via "umask" option in borgmatic hooks section.
|
||||
* Remove Python cache files before each Tox run.
|
||||
* Add #borgmatic Freenode IRC channel to documentation.
|
||||
* Add Borg/borgmatic hosting providers section to documentation.
|
||||
* Add files for building documentation into a Docker image for web serving.
|
||||
* Upgrade project build server from Drone 0.8 to 1.1.
|
||||
* Build borgmatic documentation during continuous integration.
|
||||
* We're nearly at 500 ★s on GitHub. We can do this!
|
||||
|
||||
1.3.5
|
||||
* #153: Support for various Borg directory environment variables (BORG_CONFIG_DIR, BORG_CACHE_DIR,
|
||||
etc.) via options in borgmatic's storage configuration.
|
||||
* #177: Fix for regression with missing verbose log entries.
|
||||
|
||||
1.3.4
|
||||
* Part of #125: Color borgmatic (but not Borg) output when using an interactive terminal.
|
||||
* #166: Run tests for all installed versions of Python.
|
||||
* #168: Update README with continuous integration badge.
|
||||
* #169: Automatically sort Python imports in code.
|
||||
* Document installing borgmatic with pip install --user instead of a system Python install.
|
||||
* Get more reproducible builds by pinning the versions of pip and tox used to run tests.
|
||||
* Factor out build/test configuration from tox.ini file.
|
||||
|
||||
1.3.3
|
||||
* Add validate-borgmatic-config command, useful for validating borgmatic config generated by
|
||||
configuration management or even edited by hand.
|
||||
|
||||
1.3.2
|
||||
* #160: Fix for hooks executing when using --dry-run. Now hooks are skipped during a dry run.
|
||||
|
||||
1.3.1
|
||||
* #155: Fix for invalid JSON output when using multiple borgmatic configuration files.
|
||||
* #157: Fix for seemingly random filename ordering when running through a directory of
|
||||
configuration files.
|
||||
* Fix for empty JSON output when using --create --json.
|
||||
* Now capturing Borg output only when --json flag is used. Previously, borgmatic delayed Borg
|
||||
output even without the --json flag.
|
||||
|
||||
1.3.0
|
||||
* #148: Configuration file includes and merging via "!include" tag to support reuse of common
|
||||
options across configuration files.
|
||||
|
||||
1.2.18
|
||||
* #147: Support for Borg create/extract --numeric-owner flag via "numeric_owner" option in
|
||||
borgmatic's location section.
|
||||
|
||||
1.2.17
|
||||
* #140: List the files within an archive via --list --archive option.
|
||||
|
||||
1.2.16
|
||||
* #119: Include a sample borgmatic configuration file in the documentation.
|
||||
* #123: Support for Borg archive restoration via borgmatic --extract command-line flag.
|
||||
* Refactor documentation into multiple separate pages for clarity and findability.
|
||||
* Organize options within command-line help into logical groups.
|
||||
* Exclude tests from distribution packages.
|
||||
|
||||
1.2.15
|
||||
* #127: Remove date echo from schema example, as it's not a substitute for real logging.
|
||||
* #132: Leave exclude_patterns glob expansion to Borg, since doing it in borgmatic leads to
|
||||
confusing behavior.
|
||||
* #136: Handle and format validation errors raised during argument parsing.
|
||||
* #138: Allow use of --stats flag when --create or --prune flags are implied.
|
||||
|
||||
1.2.14
|
||||
* #103: When generating sample configuration with generate-borgmatic-config, document the defaults
|
||||
for each option.
|
||||
* #116: When running multiple configuration files, attempt all configuration files even if one of
|
||||
them errors. Log a summary of results at the end.
|
||||
* Add borgmatic --version command-line flag to get the current installed version number.
|
||||
|
||||
1.2.13
|
||||
* #100: Support for --stats command-line flag independent of --verbosity.
|
||||
* #117: With borgmatic --init command-line flag, proceed without erroring if a repository already
|
||||
exists.
|
||||
|
||||
1.2.12
|
||||
* #110: Support for Borg repository initialization via borgmatic --init command-line flag.
|
||||
* #111: Update Borg create --filter values so a dry run lists files to back up.
|
||||
* #113: Update README with link to a new/forked Docker image.
|
||||
* Prevent deprecated --excludes command-line option from being used.
|
||||
* Refactor README a bit to flow better for first-time users.
|
||||
* Update README with a few additional borgmatic packages (Debian and Ubuntu).
|
||||
|
||||
1.2.11
|
||||
* #108: Support for Borg create --progress via borgmatic command-line flag.
|
||||
|
||||
1.2.10
|
||||
* #105: Support for Borg --chunker-params create option via "chunker_params" option in borgmatic's
|
||||
storage section.
|
||||
|
||||
1.2.9
|
||||
* #102: Fix for syntax error that occurred in Python 3.5 and below.
|
||||
* Make automated tests support running in Python 3.5.
|
||||
|
||||
1.2.8
|
||||
* #73: Enable consistency checks for only certain repositories via "check_repositories" option in
|
||||
borgmatic's consistency configuration. Handy for large repositories that take forever to check.
|
||||
* Include link to issue tracker within various command output.
|
||||
* Run continuous integration tests on a matrix of Python and Borg versions.
|
||||
|
||||
1.2.7
|
||||
* #98: Support for Borg --keep-secondly prune option.
|
||||
* Use Black code formatter and Flake8 code checker as part of running automated tests.
|
||||
* Add an end-to-end automated test that actually integrates with Borg.
|
||||
* Set up continuous integration for borgmatic automated tests on projects.evoworx.org.
|
||||
|
||||
1.2.6
|
||||
* Fix generated configuration to also include a "keep_daily" value so pruning works out of the
|
||||
box.
|
||||
|
||||
1.2.5
|
||||
* #57: When generating sample configuration with generate-borgmatic-config, comment out all
|
||||
optional configuration so as to streamline the initial configuration process.
|
||||
|
||||
1.2.4
|
||||
* Fix for archive checking traceback due to parameter mismatch.
|
||||
|
||||
1.2.3
|
||||
* #64, #90, #92: Rewrite of logging system. Now verbosity flags passed to Borg are derived from
|
||||
borgmatic's log level. Note that the output of borgmatic might slightly change.
|
||||
* Part of #80: Support for Borg create --read-special via "read_special" option in borgmatic's
|
||||
location configuration.
|
||||
* #87: Support for Borg create --checkpoint-interval via "checkpoint_interval" option in
|
||||
borgmatic's storage configuration.
|
||||
* #88: Fix declared pykwalify compatibility version range in setup.py to prevent use of ancient
|
||||
versions of pykwalify with large version numbers.
|
||||
* #89: Pass --show-rc option to Borg when at highest verbosity level.
|
||||
* #94: Support for Borg --json option via borgmatic command-line to --create archives.
|
||||
|
||||
1.2.2
|
||||
* #85: Fix compatibility issue between pykwalify and ruamel.yaml 0.15.52, which manifested in
|
||||
borgmatic as a pykwalify RuleError.
|
||||
|
||||
1.2.1
|
||||
* Skip before/after backup hooks when only doing --prune, --check, --list, and/or --info.
|
||||
* #71: Support for XDG_CONFIG_HOME environment variable for specifying alternate user ~/.config/
|
||||
path.
|
||||
* #74, #83: Support for Borg --json option via borgmatic command-line to --list archives or show
|
||||
archive --info in JSON format, ideal for programmatic consumption.
|
||||
* #38, #76: Upgrade ruamel.yaml compatibility version range and fix support for Python 3.7.
|
||||
* #77: Skip non-"*.yaml" config filenames in /etc/borgmatic.d/ so as not to parse backup files,
|
||||
editor swap files, etc.
|
||||
* #81: Document user-defined hooks run before/after backup, or on error.
|
||||
* Add code style guidelines to the documention.
|
||||
|
||||
1.2.0
|
||||
* #61: Support for Borg --list option via borgmatic command-line to list all archives.
|
||||
* #61: Support for Borg --info option via borgmatic command-line to display summary information.
|
||||
* #62: Update README to mention other ways of installing borgmatic.
|
||||
* Support for Borg --prefix option for consistency checks via "prefix" option in borgmatic's
|
||||
consistency configuration.
|
||||
* Add introductory screencast link to documentation.
|
||||
* #59: Ignore "check_last" and consistency "prefix" when "archives" not in consistency checks.
|
||||
* #60: Add "Persistent" flag to systemd timer example.
|
||||
* #63: Support for Borg --nobsdflags option to skip recording bsdflags (e.g. NODUMP, IMMUTABLE) in
|
||||
archive.
|
||||
* #69: Support for Borg prune --umask option using value of existing "umask" option in borgmatic's
|
||||
storage configuration.
|
||||
* Update tox.ini to only assume Python 3.x instead of Python 3.4 specifically.
|
||||
* Add ~/.config/borgmatic/config.yaml to default configuration path probing.
|
||||
* Document how to develop on and contribute to borgmatic.
|
||||
|
||||
1.1.15
|
||||
* Support for Borg BORG_PASSCOMMAND environment variable to read a password from an external file.
|
||||
* Fix for Borg create error when using borgmatic's --dry-run and --verbosity options together.
|
||||
Work-around for behavior introduced in Borg 1.1.3: https://github.com/borgbackup/borg/issues/3298
|
||||
* #55: Fix for missing tags/releases on Gitea and GitHub project hosting.
|
||||
* #56: Support for Borg --lock-wait option for the maximum wait for a repository/cache lock.
|
||||
* #58: Support for using tilde in exclude_patterns to reference home directory.
|
||||
|
||||
1.1.14
|
||||
* #49: Fix for typo in --patterns-from option.
|
||||
* #47: Support for Borg --dry-run option via borgmatic command-line.
|
||||
|
||||
1.1.13
|
||||
* #54: Fix for incorrect consistency check flags passed to Borg when all three checks ("repository",
|
||||
"archives", and "extract") are specified in borgmatic configuration.
|
||||
* #48: Add "local_path" to configuration for specifying an alternative Borg executable path.
|
||||
* #49: Support for Borg experimental --patterns-from and --patterns options for specifying mixed
|
||||
includes/excludes.
|
||||
* Moved issue tracker from Taiga to integrated Gitea tracker at
|
||||
https://projects.torsion.org/witten/borgmatic/issues
|
||||
|
||||
1.1.12
|
||||
* #46: Declare dependency on pykwalify 1.6 or above, as older versions yield "Unknown key: version"
|
||||
rule errors.
|
||||
* Support for Borg --keep-minutely prune option.
|
||||
|
||||
1.1.11
|
||||
* #26: Add "ssh_command" to configuration for specifying a custom SSH command or options.
|
||||
* Fix for incorrect /etc/borgmatic.d/ configuration path probing on macOS. This problem manifested
|
||||
as an error on startup: "[Errno 2] No such file or directory: '/etc/borgmatic.d'".
|
||||
|
||||
1.1.10
|
||||
* Pass several Unix signals through to child processes like Borg. This means that Borg now properly
|
||||
shuts down if borgmatic is terminated (e.g. due to a system suspend).
|
||||
* #30: Support for using tilde in repository paths to reference home directory.
|
||||
* #43: Support for Borg --files-cache option for setting the files cache operation mode.
|
||||
* #45: Support for Borg --remote-ratelimit option for limiting upload rate.
|
||||
* Log invoked Borg commands when at highest verbosity level.
|
||||
|
||||
1.1.9
|
||||
* #17, #39: Support for user-defined hooks before/after backup, or on error.
|
||||
* #34: Improve clarity of logging spew at high verbosity levels.
|
||||
* #30: Support for using tilde in source directory path to reference home directory.
|
||||
* Require "prefix" in retention section when "archive_name_format" is set. This is to avoid
|
||||
accidental pruning of archives with a different archive name format. For similar reasons, default
|
||||
"prefix" to "{hostname}-" if not specified.
|
||||
* Convert main source repository from Mercurial to Git.
|
||||
* Update dead links to Borg documentation.
|
||||
|
||||
1.1.8
|
||||
* #40: Fix to make /etc/borgmatic/config.yaml optional rather than required when using the default
|
||||
config paths.
|
||||
|
||||
1.1.7
|
||||
|
||||
* #29: Add "archive_name_format" to configuration for customizing archive names.
|
||||
* Fix for traceback when "exclude_from" value is empty in configuration file.
|
||||
* When pruning, make highest verbosity level list archives kept and pruned.
|
||||
* Clarification of Python 3 pip usage in documentation.
|
||||
|
||||
1.1.6
|
||||
|
||||
* #13, #36: Support for Borg --exclude-from, --exclude-caches, and --exclude-if-present options.
|
||||
|
||||
1.1.5
|
||||
|
||||
* #35: New "extract" consistency check that performs a dry-run extraction of the most recent
|
||||
archive.
|
||||
|
||||
1.1.4
|
||||
|
||||
* #18: Added command-line flags for performing a borgmatic run with only pruning, creating, or
|
||||
checking enabled. This supports use cases like running consistency checks from a different cron
|
||||
job with a different frequency, or running pruning with a different verbosity level.
|
||||
|
||||
1.1.3
|
||||
|
||||
* #15: Support for running multiple config files in /etc/borgmatic.d/ from a single borgmatic run.
|
||||
* Fix for generate-borgmatic-config writing config with invalid one_file_system value.
|
||||
|
||||
1.1.2
|
||||
|
||||
* #33: Fix for passing check_last as integer to subprocess when calling Borg.
|
||||
|
||||
1.1.1
|
||||
|
||||
* Part of #33: Fix for upgrade-borgmatic-config converting check_last option as a string instead of
|
||||
an integer.
|
||||
* Fix for upgrade-borgmatic-config erroring when consistency checks option is not present.
|
||||
|
||||
1.1.0
|
||||
|
||||
* Switched config file format to YAML. Run upgrade-borgmatic-config to upgrade.
|
||||
* Added generate-borgmatic-config command for initial config creation.
|
||||
* Dropped Python 2 support. Now Python 3 only.
|
||||
* #19: Fix for README mention of sample files not included in package.
|
||||
* #23: Sample files for triggering borgmatic from a systemd timer.
|
||||
* Support for backing up to multiple repositories.
|
||||
* To free up space, now pruning backups prior to creating a new backup.
|
||||
* Enabled test coverage output during tox runs.
|
||||
* Added logo.
|
||||
|
||||
1.0.3
|
||||
|
||||
* #22: Fix for verbosity flag not actually causing verbose output.
|
||||
|
||||
1.0.2
|
||||
|
||||
* #21: Fix for traceback when remote_path option is missing.
|
||||
|
||||
1.0.1
|
||||
|
||||
* #19: Support for Borg's --remote-path option to use an alternate Borg
|
||||
* #20: Support for Borg's --remote-path option to use an alternate Borg
|
||||
executable. See sample/config.
|
||||
|
||||
1.0.0
|
||||
|
|
@ -22,13 +365,13 @@
|
|||
|
||||
0.1.7
|
||||
|
||||
* #11: Fixed parsing of punctuation in configuration file.
|
||||
* #12: Fixed parsing of punctuation in configuration file.
|
||||
* Better error message when configuration file is missing.
|
||||
|
||||
0.1.6
|
||||
|
||||
* #9: New configuration option for the encryption passphrase.
|
||||
* #10: Support for Borg's new archive compression feature.
|
||||
* #10: New configuration option for the encryption passphrase.
|
||||
* #11: Support for Borg's new archive compression feature.
|
||||
|
||||
0.1.5
|
||||
|
||||
|
|
@ -40,7 +383,7 @@
|
|||
|
||||
0.1.3
|
||||
|
||||
* #1: Add support for "borg check --last N" to Borg backend.
|
||||
* #2: Add support for "borg check --last N" to Borg backend.
|
||||
|
||||
0.1.2
|
||||
|
||||
|
|
|
|||
220
README.md
220
README.md
|
|
@ -1,153 +1,123 @@
|
|||
title: Borgmatic
|
||||
---
|
||||
title: borgmatic
|
||||
permalink: index.html
|
||||
---
|
||||
<a href="https://build.torsion.org/witten/borgmatic" alt="build status"></a>
|
||||
|
||||
## Overview
|
||||
|
||||
borgmatic (formerly atticmatic) is a simple Python wrapper script for the
|
||||
[Borg](https://borgbackup.readthedocs.org/en/stable/) backup software that
|
||||
initiates a backup, prunes any old backups according to a retention policy,
|
||||
and validates backups for consistency. The script supports specifying your
|
||||
settings in a declarative configuration file rather than having to put them
|
||||
all on the command-line, and handles common errors.
|
||||
<img src="https://projects.torsion.org/witten/borgmatic/raw/branch/master/static/borgmatic.png" alt="borgmatic logo" width="150px" style="float: right; padding-left: 1em;">
|
||||
|
||||
borgmatic is simple, configuration-driven backup software for servers and
|
||||
workstations. Backup all of your machines from the command-line or scheduled
|
||||
jobs. No GUI required. Built atop [Borg Backup](https://www.borgbackup.org/),
|
||||
borgmatic initiates a backup, prunes any old backups according to a retention
|
||||
policy, and validates backups for consistency. borgmatic supports specifying
|
||||
your settings in a declarative configuration file, rather than having to put
|
||||
them all on the command-line, and handles common errors.
|
||||
|
||||
Here's an example config file:
|
||||
|
||||
```INI
|
||||
[location]
|
||||
# Space-separated list of source directories to backup.
|
||||
# Globs are expanded.
|
||||
source_directories: /home /etc /var/log/syslog*
|
||||
```yaml
|
||||
location:
|
||||
# List of source directories to backup. Globs are expanded.
|
||||
source_directories:
|
||||
- /home
|
||||
- /etc
|
||||
- /var/log/syslog*
|
||||
|
||||
# Path to local or remote backup repository.
|
||||
repository: user@backupserver:sourcehostname.borg
|
||||
# Paths to local or remote repositories.
|
||||
repositories:
|
||||
- user@backupserver:sourcehostname.borg
|
||||
|
||||
[retention]
|
||||
# Retention policy for how many backups to keep in each category.
|
||||
keep_daily: 7
|
||||
keep_weekly: 4
|
||||
keep_monthly: 6
|
||||
# Any paths matching these patterns are excluded from backups.
|
||||
exclude_patterns:
|
||||
- /home/*/.cache
|
||||
|
||||
[consistency]
|
||||
# Consistency checks to run, or "disabled" to prevent checks.
|
||||
checks: repository archives
|
||||
retention:
|
||||
# Retention policy for how many backups to keep in each category.
|
||||
keep_daily: 7
|
||||
keep_weekly: 4
|
||||
keep_monthly: 6
|
||||
|
||||
consistency:
|
||||
# List of consistency checks to run: "repository", "archives", or both.
|
||||
checks:
|
||||
- repository
|
||||
- archives
|
||||
```
|
||||
|
||||
Additionally, exclude patterns can be specified in a separate excludes config
|
||||
file, one pattern per line.
|
||||
|
||||
borgmatic is hosted at <https://torsion.org/borgmatic> with [source code
|
||||
available](https://torsion.org/hg/borgmatic). It's also mirrored on
|
||||
[GitHub](https://github.com/witten/borgmatic) and
|
||||
[BitBucket](https://bitbucket.org/dhelfman/borgmatic) for convenience.
|
||||
available](https://projects.torsion.org/witten/borgmatic). It's also mirrored
|
||||
on [GitHub](https://github.com/witten/borgmatic) for convenience.
|
||||
|
||||
Want to see borgmatic in action? Check out the <a
|
||||
href="https://asciinema.org/a/203761" target="_blank">screencast</a>.
|
||||
|
||||
<script src="https://asciinema.org/a/203761.js" id="asciicast-203761" async></script>
|
||||
|
||||
|
||||
## Setup
|
||||
## How-to guides
|
||||
|
||||
To get up and running, follow the [Borg Quick
|
||||
Start](https://borgbackup.readthedocs.org/en/latest/quickstart.html) to create
|
||||
a repository on a local or remote host. Note that if you plan to run
|
||||
borgmatic on a schedule with cron, and you encrypt your Borg repository with
|
||||
a passphrase instead of a key file, you'll need to set the borgmatic
|
||||
`encryption_passphrase` configuration variable. See the repository encryption
|
||||
section of the Quick Start for more info.
|
||||
|
||||
If the repository is on a remote host, make sure that your local root user has
|
||||
key-based ssh access to the desired user account on the remote host.
|
||||
|
||||
To install borgmatic, run the following command to download and install it:
|
||||
|
||||
sudo pip install --upgrade borgmatic
|
||||
|
||||
Then, copy the following configuration files:
|
||||
|
||||
sudo cp sample/borgmatic.cron /etc/cron.d/borgmatic
|
||||
sudo mkdir /etc/borgmatic/
|
||||
sudo cp sample/config sample/excludes /etc/borgmatic/
|
||||
|
||||
Lastly, modify the /etc files with your desired configuration.
|
||||
* [Set up backups with borgmatic](https://torsion.org/borgmatic/docs/how-to/set-up-backups/) ⬅ *Start here!*
|
||||
* [Make per-application backups](https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/)
|
||||
* [Deal with very large backups](https://torsion.org/borgmatic/docs/how-to/deal-with-very-large-backups/)
|
||||
* [Inspect your backups](https://torsion.org/borgmatic/docs/how-to/inspect-your-backups/)
|
||||
* [Restore a backup](https://torsion.org/borgmatic/docs/how-to/restore-a-backup/)
|
||||
* [Add preparation and cleanup steps to backups](https://torsion.org/borgmatic/docs/how-to/add-preparation-and-cleanup-steps-to-backups/)
|
||||
* [Upgrade borgmatic](https://torsion.org/borgmatic/docs/how-to/upgrade/)
|
||||
* [Develop on borgmatic](https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/)
|
||||
|
||||
|
||||
## Upgrading from atticmatic
|
||||
## Reference guides
|
||||
|
||||
You can ignore this section if you're not an atticmatic user (the former name
|
||||
of borgmatic).
|
||||
|
||||
borgmatic only supports Borg now and no longer supports Attic. So if you're
|
||||
an Attic user, consider switching to Borg. See the [Borg upgrade
|
||||
command](https://borgbackup.readthedocs.io/en/stable/usage.html#borg-upgrade)
|
||||
for more information. Then, follow the instructions above about setting up
|
||||
your borgmatic configuration files.
|
||||
|
||||
If you were already using Borg with atticmatic, then you can easily upgrade
|
||||
from atticmatic to borgmatic. Simply run the following commands:
|
||||
|
||||
sudo pip uninstall atticmatic
|
||||
sudo pip install borgmatic
|
||||
|
||||
That's it! borgmatic will continue using your /etc/borgmatic configuration
|
||||
files.
|
||||
|
||||
## Usage
|
||||
|
||||
You can run borgmatic and start a backup simply by invoking it without
|
||||
arguments:
|
||||
|
||||
borgmatic
|
||||
|
||||
This will also prune any old backups as per the configured retention policy,
|
||||
and check backups for consistency problems due to things like file damage.
|
||||
|
||||
By default, the backup will proceed silently except in the case of errors. But
|
||||
if you'd like to to get additional information about the progress of the
|
||||
backup as it proceeds, use the verbosity option:
|
||||
|
||||
borgmatic --verbosity 1
|
||||
|
||||
Or, for even more progress spew:
|
||||
|
||||
borgmatic --verbosity 2
|
||||
|
||||
If you'd like to see the available command-line arguments, view the help:
|
||||
|
||||
borgmatic --help
|
||||
* [borgmatic configuration reference](https://torsion.org/borgmatic/docs/reference/configuration/)
|
||||
* [borgmatic command-line reference](https://torsion.org/borgmatic/docs/reference/command-line/)
|
||||
|
||||
|
||||
## Running tests
|
||||
## Hosting providers
|
||||
|
||||
First install tox, which is used for setting up testing environments:
|
||||
Need somewhere to store your encrypted offsite backups? The following hosting
|
||||
providers include specific support for Borg/borgmatic. Using these links and
|
||||
services helps support borgmatic development and hosting. (These are referral
|
||||
links, but without any tracking scripts or cookies.)
|
||||
|
||||
pip install tox
|
||||
<ul>
|
||||
<li class="referral"><a href="https://www.rsync.net/cgi-bin/borg.cgi?campaign=borg&adgroup=borgmatic">rsync.net</a>: Cloud Storage provider with full support for borg and any other SSH/SFTP tool</li>
|
||||
<li class="referral"><a href="https://www.borgbase.com/?utm_source=borgmatic">BorgBase</a>: Borg hosting service with support for monitoring, 2FA, and append-only repos</li>
|
||||
</ul>
|
||||
|
||||
Then, to actually run tests, run:
|
||||
## Support and contributing
|
||||
|
||||
tox
|
||||
### Issues
|
||||
|
||||
You've got issues? Or an idea for a feature enhancement? We've got an [issue
|
||||
tracker](https://projects.torsion.org/witten/borgmatic/issues). In order to
|
||||
create a new issue or comment on an issue, you'll need to [login
|
||||
first](https://projects.torsion.org/user/login). Note that you can login with
|
||||
an existing GitHub account if you prefer.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Broken pipe with remote repository
|
||||
|
||||
When running borgmatic on a large remote repository, you may receive errors
|
||||
like the following, particularly while "borg check" is validating backups for
|
||||
consistency:
|
||||
|
||||
Write failed: Broken pipe
|
||||
borg: Error: Connection closed by remote host
|
||||
|
||||
This error can be caused by an ssh timeout, which you can rectify by adding
|
||||
the following to the ~/.ssh/config file on the client:
|
||||
|
||||
Host *
|
||||
ServerAliveInterval 120
|
||||
|
||||
This should make the client keep the connection alive while validating
|
||||
backups.
|
||||
|
||||
|
||||
## Issues and feedback
|
||||
|
||||
Got an issue or an idea for a feature enhancement? Check out the [borgmatic
|
||||
issue tracker](https://tree.taiga.io/project/witten-borgmatic/issues). In
|
||||
order to create a new issue or comment on an issue, you'll need to [login
|
||||
first](https://tree.taiga.io/login).
|
||||
If you'd like to chat with borgmatic developers or users, head on over to the
|
||||
`#borgmatic` IRC channel on Freenode, either via <a
|
||||
href="https://webchat.freenode.net/?channels=borgmatic">web chat</a> or a
|
||||
native <a href="irc://chat.freenode.net:6697">IRC client</a>.
|
||||
|
||||
Other questions or comments? Contact <mailto:witten@torsion.org>.
|
||||
|
||||
|
||||
### Contributing
|
||||
|
||||
If you'd like to contribute to borgmatic development, please feel free to
|
||||
submit a [Pull Request](https://projects.torsion.org/witten/borgmatic/pulls)
|
||||
or open an [issue](https://projects.torsion.org/witten/borgmatic/issues) first
|
||||
to discuss your idea. We also accept Pull Requests on GitHub, if that's more
|
||||
your thing. In general, contributions are very welcome. We don't bite!
|
||||
|
||||
Also, please check out the [borgmatic development
|
||||
how-to](https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/) for
|
||||
info on cloning source code, running tests, etc.
|
||||
|
||||
<script>
|
||||
var links = document.getElementsByClassName("referral");
|
||||
links[Math.floor(Math.random() * links.length)].style.display = "none";
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,186 +0,0 @@
|
|||
from datetime import datetime
|
||||
import os
|
||||
import re
|
||||
import platform
|
||||
import subprocess
|
||||
from glob import glob
|
||||
from itertools import chain
|
||||
|
||||
from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
|
||||
|
||||
|
||||
# Integration with Borg for actually handling backups.
|
||||
|
||||
|
||||
COMMAND = 'borg'
|
||||
|
||||
|
||||
def initialize(storage_config, command=COMMAND):
|
||||
passphrase = storage_config.get('encryption_passphrase')
|
||||
|
||||
if passphrase:
|
||||
os.environ['{}_PASSPHRASE'.format(command.upper())] = passphrase
|
||||
|
||||
|
||||
def create_archive(
|
||||
excludes_filename, verbosity, storage_config, source_directories, repository, command=COMMAND,
|
||||
one_file_system=None, remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given an excludes filename (or None), a vebosity flag, a storage config dict, a space-separated
|
||||
list of source directories, a local or remote repository path, and a command to run, create an
|
||||
attic archive.
|
||||
'''
|
||||
sources = re.split('\s+', source_directories)
|
||||
sources = tuple(chain.from_iterable(glob(x) or [x] for x in sources))
|
||||
exclude_flags = ('--exclude-from', excludes_filename) if excludes_filename else ()
|
||||
compression = storage_config.get('compression', None)
|
||||
compression_flags = ('--compression', compression) if compression else ()
|
||||
umask = storage_config.get('umask', None)
|
||||
umask_flags = ('--umask', str(umask)) if umask else ()
|
||||
one_file_system_flags = ('--one-file-system',) if one_file_system else ()
|
||||
remote_path_flags = ('--remote-path', remote_path) if remote_path else ()
|
||||
verbosity_flags = {
|
||||
VERBOSITY_SOME: ('--stats',),
|
||||
VERBOSITY_LOTS: ('--verbose', '--stats'),
|
||||
}.get(verbosity, ())
|
||||
|
||||
full_command = (
|
||||
command, 'create',
|
||||
'{repo}::{hostname}-{timestamp}'.format(
|
||||
repo=repository,
|
||||
hostname=platform.node(),
|
||||
timestamp=datetime.now().isoformat(),
|
||||
),
|
||||
) + sources + exclude_flags + compression_flags + one_file_system_flags + \
|
||||
remote_path_flags + umask_flags + verbosity_flags
|
||||
|
||||
subprocess.check_call(full_command)
|
||||
|
||||
|
||||
def _make_prune_flags(retention_config):
|
||||
'''
|
||||
Given a retention config dict mapping from option name to value, tranform it into an iterable of
|
||||
command-line name-value flag pairs.
|
||||
|
||||
For example, given a retention config of:
|
||||
|
||||
{'keep_weekly': 4, 'keep_monthly': 6}
|
||||
|
||||
This will be returned as an iterable of:
|
||||
|
||||
(
|
||||
('--keep-weekly', '4'),
|
||||
('--keep-monthly', '6'),
|
||||
)
|
||||
'''
|
||||
return (
|
||||
('--' + option_name.replace('_', '-'), str(retention_config[option_name]))
|
||||
for option_name, value in retention_config.items()
|
||||
)
|
||||
|
||||
|
||||
def prune_archives(verbosity, repository, retention_config, command=COMMAND, remote_path=None):
|
||||
'''
|
||||
Given a verbosity flag, a local or remote repository path, a retention config dict, and a
|
||||
command to run, prune attic archives according the the retention policy specified in that
|
||||
configuration.
|
||||
'''
|
||||
remote_path_flags = ('--remote-path', remote_path) if remote_path else ()
|
||||
verbosity_flags = {
|
||||
VERBOSITY_SOME: ('--stats',),
|
||||
VERBOSITY_LOTS: ('--verbose', '--stats'),
|
||||
}.get(verbosity, ())
|
||||
|
||||
full_command = (
|
||||
command, 'prune',
|
||||
repository,
|
||||
) + tuple(
|
||||
element
|
||||
for pair in _make_prune_flags(retention_config)
|
||||
for element in pair
|
||||
) + remote_path_flags + verbosity_flags
|
||||
|
||||
subprocess.check_call(full_command)
|
||||
|
||||
|
||||
DEFAULT_CHECKS = ('repository', 'archives')
|
||||
|
||||
|
||||
def _parse_checks(consistency_config):
|
||||
'''
|
||||
Given a consistency config with a space-separated "checks" option, transform it to a tuple of
|
||||
named checks to run.
|
||||
|
||||
For example, given a retention config of:
|
||||
|
||||
{'checks': 'repository archives'}
|
||||
|
||||
This will be returned as:
|
||||
|
||||
('repository', 'archives')
|
||||
|
||||
If no "checks" option is present, return the DEFAULT_CHECKS. If the checks value is the string
|
||||
"disabled", return an empty tuple, meaning that no checks should be run.
|
||||
'''
|
||||
checks = consistency_config.get('checks', '').strip()
|
||||
if not checks:
|
||||
return DEFAULT_CHECKS
|
||||
|
||||
return tuple(
|
||||
check for check in consistency_config['checks'].split(' ')
|
||||
if check.lower() not in ('disabled', '')
|
||||
)
|
||||
|
||||
|
||||
def _make_check_flags(checks, check_last=None):
|
||||
'''
|
||||
Given a parsed sequence of checks, transform it into tuple of command-line flags.
|
||||
|
||||
For example, given parsed checks of:
|
||||
|
||||
('repository',)
|
||||
|
||||
This will be returned as:
|
||||
|
||||
('--repository-only',)
|
||||
|
||||
Additionally, if a check_last value is given, a "--last" flag will be added. Note that only
|
||||
Borg supports this flag.
|
||||
'''
|
||||
last_flag = ('--last', check_last) if check_last else ()
|
||||
if checks == DEFAULT_CHECKS:
|
||||
return last_flag
|
||||
|
||||
return tuple(
|
||||
'--{}-only'.format(check) for check in checks
|
||||
) + last_flag
|
||||
|
||||
|
||||
def check_archives(verbosity, repository, consistency_config, command=COMMAND, remote_path=None):
|
||||
'''
|
||||
Given a verbosity flag, a local or remote repository path, a consistency config dict, and a
|
||||
command to run, check the contained attic archives for consistency.
|
||||
|
||||
If there are no consistency checks to run, skip running them.
|
||||
'''
|
||||
checks = _parse_checks(consistency_config)
|
||||
check_last = consistency_config.get('check_last', None)
|
||||
if not checks:
|
||||
return
|
||||
|
||||
remote_path_flags = ('--remote-path', remote_path) if remote_path else ()
|
||||
verbosity_flags = {
|
||||
VERBOSITY_SOME: ('--verbose',),
|
||||
VERBOSITY_LOTS: ('--verbose',),
|
||||
}.get(verbosity, ())
|
||||
|
||||
full_command = (
|
||||
command, 'check',
|
||||
repository,
|
||||
) + _make_check_flags(checks, check_last) + remote_path_flags + verbosity_flags
|
||||
|
||||
# The check command spews to stdout/stderr even without the verbose flag. Suppress it.
|
||||
stdout = None if verbosity_flags else open(os.devnull, 'w')
|
||||
|
||||
subprocess.check_call(full_command, stdout=stdout, stderr=subprocess.STDOUT)
|
||||
132
borgmatic/borg/check.py
Normal file
132
borgmatic/borg/check.py
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
import logging
|
||||
|
||||
from borgmatic.borg import extract
|
||||
from borgmatic.execute import execute_command
|
||||
|
||||
DEFAULT_CHECKS = ('repository', 'archives')
|
||||
DEFAULT_PREFIX = '{hostname}-'
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _parse_checks(consistency_config, only_checks=None):
|
||||
'''
|
||||
Given a consistency config with a "checks" list, and an optional list of override checks,
|
||||
transform them a tuple of named checks to run.
|
||||
|
||||
For example, given a retention config of:
|
||||
|
||||
{'checks': ['repository', 'archives']}
|
||||
|
||||
This will be returned as:
|
||||
|
||||
('repository', 'archives')
|
||||
|
||||
If no "checks" option is present in the config, return the DEFAULT_CHECKS. If the checks value
|
||||
is the string "disabled", return an empty tuple, meaning that no checks should be run.
|
||||
|
||||
If the "data" option is present, then make sure the "archives" option is included as well.
|
||||
'''
|
||||
checks = [
|
||||
check.lower() for check in (only_checks or consistency_config.get('checks', []) or [])
|
||||
]
|
||||
if checks == ['disabled']:
|
||||
return ()
|
||||
|
||||
if 'data' in checks and 'archives' not in checks:
|
||||
checks.append('archives')
|
||||
|
||||
return tuple(check for check in checks if check not in ('disabled', '')) or DEFAULT_CHECKS
|
||||
|
||||
|
||||
def _make_check_flags(checks, check_last=None, prefix=None):
|
||||
'''
|
||||
Given a parsed sequence of checks, transform it into tuple of command-line flags.
|
||||
|
||||
For example, given parsed checks of:
|
||||
|
||||
('repository',)
|
||||
|
||||
This will be returned as:
|
||||
|
||||
('--repository-only',)
|
||||
|
||||
However, if both "repository" and "archives" are in checks, then omit them from the returned
|
||||
flags because Borg does both checks by default.
|
||||
|
||||
Additionally, if a check_last value is given and "archives" is in checks, then include a
|
||||
"--last" flag. And if a prefix value is given and "archives" is in checks, then include a
|
||||
"--prefix" flag.
|
||||
'''
|
||||
if 'archives' in checks:
|
||||
last_flags = ('--last', str(check_last)) if check_last else ()
|
||||
prefix_flags = ('--prefix', prefix) if prefix else ()
|
||||
else:
|
||||
last_flags = ()
|
||||
prefix_flags = ()
|
||||
if check_last:
|
||||
logger.warning(
|
||||
'Ignoring check_last option, as "archives" is not in consistency checks.'
|
||||
)
|
||||
if prefix:
|
||||
logger.warning(
|
||||
'Ignoring consistency prefix option, as "archives" is not in consistency checks.'
|
||||
)
|
||||
|
||||
common_flags = last_flags + prefix_flags + (('--verify-data',) if 'data' in checks else ())
|
||||
|
||||
if set(DEFAULT_CHECKS).issubset(set(checks)):
|
||||
return common_flags
|
||||
|
||||
return (
|
||||
tuple('--{}-only'.format(check) for check in checks if check in DEFAULT_CHECKS)
|
||||
+ common_flags
|
||||
)
|
||||
|
||||
|
||||
def check_archives(
|
||||
repository,
|
||||
storage_config,
|
||||
consistency_config,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
only_checks=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a storage config dict, a consistency config dict,
|
||||
local/remote commands to run, and an optional list of checks to use instead of configured
|
||||
checks, check the contained Borg archives for consistency.
|
||||
|
||||
If there are no consistency checks to run, skip running them.
|
||||
'''
|
||||
checks = _parse_checks(consistency_config, only_checks)
|
||||
check_last = consistency_config.get('check_last', None)
|
||||
lock_wait = None
|
||||
|
||||
if set(checks).intersection(set(DEFAULT_CHECKS + ('data',))):
|
||||
remote_path_flags = ('--remote-path', remote_path) if remote_path else ()
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
lock_wait_flags = ('--lock-wait', str(lock_wait)) if lock_wait else ()
|
||||
|
||||
verbosity_flags = ()
|
||||
if logger.isEnabledFor(logging.INFO):
|
||||
verbosity_flags = ('--info',)
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
verbosity_flags = ('--debug', '--show-rc')
|
||||
|
||||
prefix = consistency_config.get('prefix', DEFAULT_PREFIX)
|
||||
|
||||
full_command = (
|
||||
(local_path, 'check')
|
||||
+ _make_check_flags(checks, check_last, prefix)
|
||||
+ remote_path_flags
|
||||
+ lock_wait_flags
|
||||
+ verbosity_flags
|
||||
+ (repository,)
|
||||
)
|
||||
|
||||
execute_command(full_command)
|
||||
|
||||
if 'extract' in checks:
|
||||
extract.extract_last_archive_dry_run(repository, lock_wait, local_path, remote_path)
|
||||
179
borgmatic/borg/create.py
Normal file
179
borgmatic/borg/create.py
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
import glob
|
||||
import itertools
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from borgmatic.execute import execute_command, execute_command_without_capture
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _expand_directory(directory):
|
||||
'''
|
||||
Given a directory path, expand any tilde (representing a user's home directory) and any globs
|
||||
therein. Return a list of one or more resulting paths.
|
||||
'''
|
||||
expanded_directory = os.path.expanduser(directory)
|
||||
|
||||
return glob.glob(expanded_directory) or [expanded_directory]
|
||||
|
||||
|
||||
def _expand_directories(directories):
|
||||
'''
|
||||
Given a sequence of directory paths, expand tildes and globs in each one. Return all the
|
||||
resulting directories as a single flattened tuple.
|
||||
'''
|
||||
if directories is None:
|
||||
return ()
|
||||
|
||||
return tuple(
|
||||
itertools.chain.from_iterable(_expand_directory(directory) for directory in directories)
|
||||
)
|
||||
|
||||
|
||||
def _expand_home_directories(directories):
|
||||
'''
|
||||
Given a sequence of directory paths, expand tildes in each one. Do not perform any globbing.
|
||||
Return the results as a tuple.
|
||||
'''
|
||||
if directories is None:
|
||||
return ()
|
||||
|
||||
return tuple(os.path.expanduser(directory) for directory in directories)
|
||||
|
||||
|
||||
def _write_pattern_file(patterns=None):
|
||||
'''
|
||||
Given a sequence of patterns, write them to a named temporary file and return it. Return None
|
||||
if no patterns are provided.
|
||||
'''
|
||||
if not patterns:
|
||||
return None
|
||||
|
||||
pattern_file = tempfile.NamedTemporaryFile('w')
|
||||
pattern_file.write('\n'.join(patterns))
|
||||
pattern_file.flush()
|
||||
|
||||
return pattern_file
|
||||
|
||||
|
||||
def _make_pattern_flags(location_config, pattern_filename=None):
|
||||
'''
|
||||
Given a location config dict with a potential pattern_from option, and a filename containing any
|
||||
additional patterns, return the corresponding Borg flags for those files as a tuple.
|
||||
'''
|
||||
pattern_filenames = tuple(location_config.get('patterns_from') or ()) + (
|
||||
(pattern_filename,) if pattern_filename else ()
|
||||
)
|
||||
|
||||
return tuple(
|
||||
itertools.chain.from_iterable(
|
||||
('--patterns-from', pattern_filename) for pattern_filename in pattern_filenames
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _make_exclude_flags(location_config, exclude_filename=None):
|
||||
'''
|
||||
Given a location config dict with various exclude options, and a filename containing any exclude
|
||||
patterns, return the corresponding Borg flags as a tuple.
|
||||
'''
|
||||
exclude_filenames = tuple(location_config.get('exclude_from') or ()) + (
|
||||
(exclude_filename,) if exclude_filename else ()
|
||||
)
|
||||
exclude_from_flags = tuple(
|
||||
itertools.chain.from_iterable(
|
||||
('--exclude-from', exclude_filename) for exclude_filename in exclude_filenames
|
||||
)
|
||||
)
|
||||
caches_flag = ('--exclude-caches',) if location_config.get('exclude_caches') else ()
|
||||
if_present = location_config.get('exclude_if_present')
|
||||
if_present_flags = ('--exclude-if-present', if_present) if if_present else ()
|
||||
|
||||
return exclude_from_flags + caches_flag + if_present_flags
|
||||
|
||||
|
||||
def create_archive(
|
||||
dry_run,
|
||||
repository,
|
||||
location_config,
|
||||
storage_config,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
progress=False,
|
||||
stats=False,
|
||||
json=False,
|
||||
):
|
||||
'''
|
||||
Given vebosity/dry-run flags, a local or remote repository path, a location config dict, and a
|
||||
storage config dict, create a Borg archive and return Borg's JSON output (if any).
|
||||
'''
|
||||
sources = _expand_directories(location_config['source_directories'])
|
||||
|
||||
pattern_file = _write_pattern_file(location_config.get('patterns'))
|
||||
exclude_file = _write_pattern_file(
|
||||
_expand_home_directories(location_config.get('exclude_patterns'))
|
||||
)
|
||||
checkpoint_interval = storage_config.get('checkpoint_interval', None)
|
||||
chunker_params = storage_config.get('chunker_params', None)
|
||||
compression = storage_config.get('compression', None)
|
||||
remote_rate_limit = storage_config.get('remote_rate_limit', None)
|
||||
umask = storage_config.get('umask', None)
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
files_cache = location_config.get('files_cache')
|
||||
default_archive_name_format = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
|
||||
archive_name_format = storage_config.get('archive_name_format', default_archive_name_format)
|
||||
|
||||
full_command = (
|
||||
(local_path, 'create')
|
||||
+ _make_pattern_flags(location_config, pattern_file.name if pattern_file else None)
|
||||
+ _make_exclude_flags(location_config, exclude_file.name if exclude_file else None)
|
||||
+ (('--checkpoint-interval', str(checkpoint_interval)) if checkpoint_interval else ())
|
||||
+ (('--chunker-params', chunker_params) if chunker_params else ())
|
||||
+ (('--compression', compression) if compression else ())
|
||||
+ (('--remote-ratelimit', str(remote_rate_limit)) if remote_rate_limit else ())
|
||||
+ (('--one-file-system',) if location_config.get('one_file_system') else ())
|
||||
+ (('--numeric-owner',) if location_config.get('numeric_owner') else ())
|
||||
+ (('--noatime',) if location_config.get('atime') is False else ())
|
||||
+ (('--noctime',) if location_config.get('ctime') is False else ())
|
||||
+ (('--nobirthtime',) if location_config.get('birthtime') is False else ())
|
||||
+ (('--read-special',) if location_config.get('read_special') else ())
|
||||
+ (('--nobsdflags',) if location_config.get('bsd_flags') is False else ())
|
||||
+ (('--files-cache', files_cache) if files_cache else ())
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--list', '--filter', 'AME-') if logger.isEnabledFor(logging.INFO) and not json else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO and not json else ())
|
||||
+ (
|
||||
('--stats',)
|
||||
if not dry_run and (logger.isEnabledFor(logging.INFO) or stats) and not json
|
||||
else ()
|
||||
)
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) and not json else ())
|
||||
+ (('--dry-run',) if dry_run else ())
|
||||
+ (('--progress',) if progress else ())
|
||||
+ (('--json',) if json else ())
|
||||
+ (
|
||||
'{repository}::{archive_name_format}'.format(
|
||||
repository=repository, archive_name_format=archive_name_format
|
||||
),
|
||||
)
|
||||
+ sources
|
||||
)
|
||||
|
||||
# The progress output isn't compatible with captured and logged output, as progress messes with
|
||||
# the terminal directly.
|
||||
if progress:
|
||||
execute_command_without_capture(full_command)
|
||||
return
|
||||
|
||||
if json:
|
||||
output_log_level = None
|
||||
elif stats:
|
||||
output_log_level = logging.WARNING
|
||||
else:
|
||||
output_log_level = logging.INFO
|
||||
|
||||
return execute_command(full_command, output_log_level)
|
||||
31
borgmatic/borg/environment.py
Normal file
31
borgmatic/borg/environment.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import os
|
||||
|
||||
OPTION_TO_ENVIRONMENT_VARIABLE = {
|
||||
'borg_base_directory': 'BORG_BASE_DIR',
|
||||
'borg_config_directory': 'BORG_CONFIG_DIR',
|
||||
'borg_cache_directory': 'BORG_CACHE_DIR',
|
||||
'borg_security_directory': 'BORG_SECURITY_DIR',
|
||||
'borg_keys_directory': 'BORG_KEYS_DIR',
|
||||
'encryption_passcommand': 'BORG_PASSCOMMAND',
|
||||
'encryption_passphrase': 'BORG_PASSPHRASE',
|
||||
'ssh_command': 'BORG_RSH',
|
||||
}
|
||||
|
||||
DEFAULT_BOOL_OPTION_TO_ENVIRONMENT_VARIABLE = {
|
||||
'relocated_repo_access_is_ok': 'BORG_RELOCATED_REPO_ACCESS_IS_OK',
|
||||
'unknown_unencrypted_repo_access_is_ok': 'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK',
|
||||
}
|
||||
|
||||
|
||||
def initialize(storage_config):
|
||||
for option_name, environment_variable_name in OPTION_TO_ENVIRONMENT_VARIABLE.items():
|
||||
value = storage_config.get(option_name)
|
||||
if value:
|
||||
os.environ[environment_variable_name] = value
|
||||
|
||||
for (
|
||||
option_name,
|
||||
environment_variable_name,
|
||||
) in DEFAULT_BOOL_OPTION_TO_ENVIRONMENT_VARIABLE.items():
|
||||
value = storage_config.get(option_name, False)
|
||||
os.environ[environment_variable_name] = 'yes' if value else 'no'
|
||||
92
borgmatic/borg/extract.py
Normal file
92
borgmatic/borg/extract.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import logging
|
||||
|
||||
from borgmatic.execute import execute_command, execute_command_without_capture
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def extract_last_archive_dry_run(repository, lock_wait=None, local_path='borg', remote_path=None):
|
||||
'''
|
||||
Perform an extraction dry-run of the most recent archive. If there are no archives, skip the
|
||||
dry-run.
|
||||
'''
|
||||
remote_path_flags = ('--remote-path', remote_path) if remote_path else ()
|
||||
lock_wait_flags = ('--lock-wait', str(lock_wait)) if lock_wait else ()
|
||||
verbosity_flags = ()
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
verbosity_flags = ('--debug', '--show-rc')
|
||||
elif logger.isEnabledFor(logging.INFO):
|
||||
verbosity_flags = ('--info',)
|
||||
|
||||
full_list_command = (
|
||||
(local_path, 'list', '--short')
|
||||
+ remote_path_flags
|
||||
+ lock_wait_flags
|
||||
+ verbosity_flags
|
||||
+ (repository,)
|
||||
)
|
||||
|
||||
list_output = execute_command(full_list_command, output_log_level=None)
|
||||
|
||||
try:
|
||||
last_archive_name = list_output.strip().splitlines()[-1]
|
||||
except IndexError:
|
||||
return
|
||||
|
||||
list_flag = ('--list',) if logger.isEnabledFor(logging.DEBUG) else ()
|
||||
full_extract_command = (
|
||||
(local_path, 'extract', '--dry-run')
|
||||
+ remote_path_flags
|
||||
+ lock_wait_flags
|
||||
+ verbosity_flags
|
||||
+ list_flag
|
||||
+ (
|
||||
'{repository}::{last_archive_name}'.format(
|
||||
repository=repository, last_archive_name=last_archive_name
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
execute_command(full_extract_command)
|
||||
|
||||
|
||||
def extract_archive(
|
||||
dry_run,
|
||||
repository,
|
||||
archive,
|
||||
restore_paths,
|
||||
location_config,
|
||||
storage_config,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
progress=False,
|
||||
):
|
||||
'''
|
||||
Given a dry-run flag, a local or remote repository path, an archive name, zero or more paths to
|
||||
restore from the archive, and location/storage configuration dicts, extract the archive into the
|
||||
current directory.
|
||||
'''
|
||||
umask = storage_config.get('umask', None)
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
||||
full_command = (
|
||||
(local_path, 'extract')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--numeric-owner',) if location_config.get('numeric_owner') else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--dry-run',) if dry_run else ())
|
||||
+ (('--progress',) if progress else ())
|
||||
+ ('::'.join((repository, archive)),)
|
||||
+ (tuple(restore_paths) if restore_paths else ())
|
||||
)
|
||||
|
||||
# The progress output isn't compatible with captured and logged output, as progress messes with
|
||||
# the terminal directly.
|
||||
if progress:
|
||||
execute_command_without_capture(full_command)
|
||||
return
|
||||
|
||||
execute_command(full_command)
|
||||
31
borgmatic/borg/flags.py
Normal file
31
borgmatic/borg/flags.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import itertools
|
||||
|
||||
|
||||
def make_flags(name, value):
|
||||
'''
|
||||
Given a flag name and its value, return it formatted as Borg-compatible flags.
|
||||
'''
|
||||
if not value:
|
||||
return ()
|
||||
|
||||
flag = '--{}'.format(name.replace('_', '-'))
|
||||
|
||||
if value is True:
|
||||
return (flag,)
|
||||
|
||||
return (flag, str(value))
|
||||
|
||||
|
||||
def make_flags_from_arguments(arguments, excludes=()):
|
||||
'''
|
||||
Given borgmatic command-line arguments as an instance of argparse.Namespace, and optionally a
|
||||
list of named arguments to exclude, generate and return the corresponding Borg command-line
|
||||
flags as a tuple.
|
||||
'''
|
||||
return tuple(
|
||||
itertools.chain.from_iterable(
|
||||
make_flags(name, value=getattr(arguments, name))
|
||||
for name in sorted(vars(arguments))
|
||||
if name not in excludes and not name.startswith('_')
|
||||
)
|
||||
)
|
||||
43
borgmatic/borg/info.py
Normal file
43
borgmatic/borg/info.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import logging
|
||||
|
||||
from borgmatic.borg.flags import make_flags, make_flags_from_arguments
|
||||
from borgmatic.execute import execute_command
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def display_archives_info(
|
||||
repository, storage_config, info_arguments, local_path='borg', remote_path=None
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a storage config dict, and the arguments to the info
|
||||
action, display summary information for Borg archives in the repository or return JSON summary
|
||||
information.
|
||||
'''
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
||||
full_command = (
|
||||
(local_path, 'info')
|
||||
+ (
|
||||
('--info',)
|
||||
if logger.getEffectiveLevel() == logging.INFO and not info_arguments.json
|
||||
else ()
|
||||
)
|
||||
+ (
|
||||
('--debug', '--show-rc')
|
||||
if logger.isEnabledFor(logging.DEBUG) and not info_arguments.json
|
||||
else ()
|
||||
)
|
||||
+ make_flags('remote-path', remote_path)
|
||||
+ make_flags('lock-wait', lock_wait)
|
||||
+ make_flags_from_arguments(info_arguments, excludes=('repository', 'archive'))
|
||||
+ (
|
||||
'::'.join((repository, info_arguments.archive))
|
||||
if info_arguments.archive
|
||||
else repository,
|
||||
)
|
||||
)
|
||||
|
||||
return execute_command(
|
||||
full_command, output_log_level=None if info_arguments.json else logging.WARNING
|
||||
)
|
||||
48
borgmatic/borg/init.py
Normal file
48
borgmatic/borg/init.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import logging
|
||||
import subprocess
|
||||
|
||||
from borgmatic.execute import execute_command, execute_command_without_capture
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
INFO_REPOSITORY_NOT_FOUND_EXIT_CODE = 2
|
||||
|
||||
|
||||
def initialize_repository(
|
||||
repository,
|
||||
encryption_mode,
|
||||
append_only=None,
|
||||
storage_quota=None,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a Borg encryption mode, whether the repository should
|
||||
be append-only, and the storage quota to use, initialize the repository. If the repository
|
||||
already exists, then log and skip initialization.
|
||||
'''
|
||||
info_command = (local_path, 'info', repository)
|
||||
logger.debug(' '.join(info_command))
|
||||
|
||||
try:
|
||||
execute_command(info_command, output_log_level=None)
|
||||
logger.info('Repository already exists. Skipping initialization.')
|
||||
return
|
||||
except subprocess.CalledProcessError as error:
|
||||
if error.returncode != INFO_REPOSITORY_NOT_FOUND_EXIT_CODE:
|
||||
raise
|
||||
|
||||
init_command = (
|
||||
(local_path, 'init')
|
||||
+ (('--encryption', encryption_mode) if encryption_mode else ())
|
||||
+ (('--append-only',) if append_only else ())
|
||||
+ (('--storage-quota', storage_quota) if storage_quota else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (repository,)
|
||||
)
|
||||
|
||||
# Don't use execute_command() here because it doesn't support interactive prompts.
|
||||
execute_command_without_capture(init_command)
|
||||
41
borgmatic/borg/list.py
Normal file
41
borgmatic/borg/list.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import logging
|
||||
|
||||
from borgmatic.borg.flags import make_flags, make_flags_from_arguments
|
||||
from borgmatic.execute import execute_command
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def list_archives(repository, storage_config, list_arguments, local_path='borg', remote_path=None):
|
||||
'''
|
||||
Given a local or remote repository path, a storage config dict, and the arguments to the list
|
||||
action, display the output of listing Borg archives in the repository or return JSON output. Or,
|
||||
if an archive name is given, listing the files in that archive.
|
||||
'''
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
||||
full_command = (
|
||||
(local_path, 'list')
|
||||
+ (
|
||||
('--info',)
|
||||
if logger.getEffectiveLevel() == logging.INFO and not list_arguments.json
|
||||
else ()
|
||||
)
|
||||
+ (
|
||||
('--debug', '--show-rc')
|
||||
if logger.isEnabledFor(logging.DEBUG) and not list_arguments.json
|
||||
else ()
|
||||
)
|
||||
+ make_flags('remote-path', remote_path)
|
||||
+ make_flags('lock-wait', lock_wait)
|
||||
+ make_flags_from_arguments(list_arguments, excludes=('repository', 'archive'))
|
||||
+ (
|
||||
'::'.join((repository, list_arguments.archive))
|
||||
if list_arguments.archive
|
||||
else repository,
|
||||
)
|
||||
)
|
||||
|
||||
return execute_command(
|
||||
full_command, output_log_level=None if list_arguments.json else logging.WARNING
|
||||
)
|
||||
67
borgmatic/borg/prune.py
Normal file
67
borgmatic/borg/prune.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import logging
|
||||
|
||||
from borgmatic.execute import execute_command
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _make_prune_flags(retention_config):
|
||||
'''
|
||||
Given a retention config dict mapping from option name to value, tranform it into an iterable of
|
||||
command-line name-value flag pairs.
|
||||
|
||||
For example, given a retention config of:
|
||||
|
||||
{'keep_weekly': 4, 'keep_monthly': 6}
|
||||
|
||||
This will be returned as an iterable of:
|
||||
|
||||
(
|
||||
('--keep-weekly', '4'),
|
||||
('--keep-monthly', '6'),
|
||||
)
|
||||
'''
|
||||
config = retention_config.copy()
|
||||
|
||||
if 'prefix' not in config:
|
||||
config['prefix'] = '{hostname}-'
|
||||
elif not config['prefix']:
|
||||
config.pop('prefix')
|
||||
|
||||
return (
|
||||
('--' + option_name.replace('_', '-'), str(value)) for option_name, value in config.items()
|
||||
)
|
||||
|
||||
|
||||
def prune_archives(
|
||||
dry_run,
|
||||
repository,
|
||||
storage_config,
|
||||
retention_config,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
stats=False,
|
||||
):
|
||||
'''
|
||||
Given dry-run flag, a local or remote repository path, a storage config dict, and a
|
||||
retention config dict, prune Borg archives according to the retention policy specified in that
|
||||
configuration.
|
||||
'''
|
||||
umask = storage_config.get('umask', None)
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
||||
full_command = (
|
||||
(local_path, 'prune')
|
||||
+ tuple(element for pair in _make_prune_flags(retention_config) for element in pair)
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--stats',) if not dry_run and logger.isEnabledFor(logging.INFO) else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--dry-run',) if dry_run else ())
|
||||
+ (('--stats',) if stats else ())
|
||||
+ (repository,)
|
||||
)
|
||||
|
||||
execute_command(full_command, output_log_level=logging.WARNING if stats else logging.INFO)
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
from __future__ import print_function
|
||||
from argparse import ArgumentParser
|
||||
import os
|
||||
from subprocess import CalledProcessError
|
||||
import sys
|
||||
|
||||
from borgmatic import borg
|
||||
from borgmatic.config import parse_configuration, CONFIG_FORMAT
|
||||
|
||||
|
||||
DEFAULT_CONFIG_FILENAME = '/etc/borgmatic/config'
|
||||
DEFAULT_EXCLUDES_FILENAME = '/etc/borgmatic/excludes'
|
||||
|
||||
|
||||
def parse_arguments(*arguments):
|
||||
'''
|
||||
Given the name of the command with which this script was invoked and command-line arguments,
|
||||
parse the arguments and return them as an ArgumentParser instance. Use the command name to
|
||||
determine the default configuration and excludes paths.
|
||||
'''
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument(
|
||||
'-c', '--config',
|
||||
dest='config_filename',
|
||||
default=DEFAULT_CONFIG_FILENAME,
|
||||
help='Configuration filename',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--excludes',
|
||||
dest='excludes_filename',
|
||||
default=DEFAULT_EXCLUDES_FILENAME if os.path.exists(DEFAULT_EXCLUDES_FILENAME) else None,
|
||||
help='Excludes filename',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-v', '--verbosity',
|
||||
type=int,
|
||||
help='Display verbose progress (1 for some, 2 for lots)',
|
||||
)
|
||||
|
||||
return parser.parse_args(arguments)
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
args = parse_arguments(*sys.argv[1:])
|
||||
config = parse_configuration(args.config_filename, CONFIG_FORMAT)
|
||||
repository = config.location['repository']
|
||||
remote_path = config.location['remote_path']
|
||||
|
||||
borg.initialize(config.storage)
|
||||
borg.create_archive(
|
||||
args.excludes_filename, args.verbosity, config.storage, **config.location
|
||||
)
|
||||
borg.prune_archives(args.verbosity, repository, config.retention, remote_path=remote_path)
|
||||
borg.check_archives(args.verbosity, repository, config.consistency, remote_path=remote_path)
|
||||
except (ValueError, IOError, CalledProcessError) as error:
|
||||
print(error, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
399
borgmatic/commands/arguments.py
Normal file
399
borgmatic/commands/arguments.py
Normal file
|
|
@ -0,0 +1,399 @@
|
|||
import collections
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from borgmatic.config import collect
|
||||
|
||||
SUBPARSER_ALIASES = {
|
||||
'init': ['--init', '-I'],
|
||||
'prune': ['--prune', '-p'],
|
||||
'create': ['--create', '-C'],
|
||||
'check': ['--check', '-k'],
|
||||
'extract': ['--extract', '-x'],
|
||||
'list': ['--list', '-l'],
|
||||
'info': ['--info', '-i'],
|
||||
}
|
||||
|
||||
|
||||
def parse_subparser_arguments(unparsed_arguments, subparsers):
|
||||
'''
|
||||
Given a sequence of arguments, and a subparsers object as returned by
|
||||
argparse.ArgumentParser().add_subparsers(), give each requested action's subparser a shot at
|
||||
parsing all arguments. This allows common arguments like "--repository" to be shared across
|
||||
multiple subparsers.
|
||||
|
||||
Return the result as a dict mapping from subparser name to a parsed namespace of arguments.
|
||||
'''
|
||||
arguments = collections.OrderedDict()
|
||||
remaining_arguments = list(unparsed_arguments)
|
||||
alias_to_subparser_name = {
|
||||
alias: subparser_name
|
||||
for subparser_name, aliases in SUBPARSER_ALIASES.items()
|
||||
for alias in aliases
|
||||
}
|
||||
|
||||
for subparser_name, subparser in subparsers.choices.items():
|
||||
if subparser_name not in remaining_arguments:
|
||||
continue
|
||||
|
||||
canonical_name = alias_to_subparser_name.get(subparser_name, subparser_name)
|
||||
|
||||
# If a parsed value happens to be the same as the name of a subparser, remove it from the
|
||||
# remaining arguments. This prevents, for instance, "check --only extract" from triggering
|
||||
# the "extract" subparser.
|
||||
parsed, unused_remaining = subparser.parse_known_args(unparsed_arguments)
|
||||
for value in vars(parsed).values():
|
||||
if isinstance(value, str):
|
||||
if value in subparsers.choices:
|
||||
remaining_arguments.remove(value)
|
||||
elif isinstance(value, list):
|
||||
for item in value:
|
||||
if item in subparsers.choices:
|
||||
remaining_arguments.remove(item)
|
||||
|
||||
arguments[canonical_name] = parsed
|
||||
|
||||
# If no actions are explicitly requested, assume defaults: prune, create, and check.
|
||||
if not arguments and '--help' not in unparsed_arguments and '-h' not in unparsed_arguments:
|
||||
for subparser_name in ('prune', 'create', 'check'):
|
||||
subparser = subparsers.choices[subparser_name]
|
||||
parsed, unused_remaining = subparser.parse_known_args(unparsed_arguments)
|
||||
arguments[subparser_name] = parsed
|
||||
|
||||
return arguments
|
||||
|
||||
|
||||
def parse_global_arguments(unparsed_arguments, top_level_parser, subparsers):
|
||||
'''
|
||||
Given a sequence of arguments, a top-level parser (containing subparsers), and a subparsers
|
||||
object as returned by argparse.ArgumentParser().add_subparsers(), parse and return any global
|
||||
arguments as a parsed argparse.Namespace instance.
|
||||
'''
|
||||
# Ask each subparser, one by one, to greedily consume arguments. Any arguments that remain
|
||||
# are global arguments.
|
||||
remaining_arguments = list(unparsed_arguments)
|
||||
present_subparser_names = set()
|
||||
|
||||
for subparser_name, subparser in subparsers.choices.items():
|
||||
if subparser_name not in remaining_arguments:
|
||||
continue
|
||||
|
||||
present_subparser_names.add(subparser_name)
|
||||
unused_parsed, remaining_arguments = subparser.parse_known_args(remaining_arguments)
|
||||
|
||||
# If no actions are explicitly requested, assume defaults: prune, create, and check.
|
||||
if (
|
||||
not present_subparser_names
|
||||
and '--help' not in unparsed_arguments
|
||||
and '-h' not in unparsed_arguments
|
||||
):
|
||||
for subparser_name in ('prune', 'create', 'check'):
|
||||
subparser = subparsers.choices[subparser_name]
|
||||
unused_parsed, remaining_arguments = subparser.parse_known_args(remaining_arguments)
|
||||
|
||||
# Remove the subparser names themselves.
|
||||
for subparser_name in present_subparser_names:
|
||||
if subparser_name in remaining_arguments:
|
||||
remaining_arguments.remove(subparser_name)
|
||||
|
||||
return top_level_parser.parse_args(remaining_arguments)
|
||||
|
||||
|
||||
def parse_arguments(*unparsed_arguments):
|
||||
'''
|
||||
Given command-line arguments with which this script was invoked, parse the arguments and return
|
||||
them as a dict mapping from subparser name (or "global") to an argparse.Namespace instance.
|
||||
'''
|
||||
config_paths = collect.get_default_config_paths()
|
||||
|
||||
global_parser = ArgumentParser(add_help=False)
|
||||
global_group = global_parser.add_argument_group('global arguments')
|
||||
|
||||
global_group.add_argument(
|
||||
'-c',
|
||||
'--config',
|
||||
nargs='*',
|
||||
dest='config_paths',
|
||||
default=config_paths,
|
||||
help='Configuration filenames or directories, defaults to: {}'.format(
|
||||
' '.join(config_paths)
|
||||
),
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--excludes',
|
||||
dest='excludes_filename',
|
||||
help='Deprecated in favor of exclude_patterns within configuration',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'-n',
|
||||
'--dry-run',
|
||||
dest='dry_run',
|
||||
action='store_true',
|
||||
help='Go through the motions, but do not actually write to any repositories',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'-nc', '--no-color', dest='no_color', action='store_true', help='Disable colored output'
|
||||
)
|
||||
global_group.add_argument(
|
||||
'-v',
|
||||
'--verbosity',
|
||||
type=int,
|
||||
choices=range(0, 3),
|
||||
default=0,
|
||||
help='Display verbose progress to the console (from none to lots: 0, 1, or 2)',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--syslog-verbosity',
|
||||
type=int,
|
||||
choices=range(0, 3),
|
||||
default=0,
|
||||
help='Display verbose progress to syslog (from none to lots: 0, 1, or 2). Ignored when console is interactive',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--version',
|
||||
dest='version',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Display installed version number of borgmatic and exit',
|
||||
)
|
||||
|
||||
top_level_parser = ArgumentParser(
|
||||
description='''
|
||||
A simple wrapper script for the Borg backup software that creates and prunes backups.
|
||||
If none of the action options are given, then borgmatic defaults to: prune, create, and
|
||||
check archives.
|
||||
''',
|
||||
parents=[global_parser],
|
||||
)
|
||||
|
||||
subparsers = top_level_parser.add_subparsers(
|
||||
title='actions',
|
||||
metavar='',
|
||||
help='Specify zero or more actions. Defaults to prune, create, and check. Use --help with action for details:',
|
||||
)
|
||||
init_parser = subparsers.add_parser(
|
||||
'init',
|
||||
aliases=SUBPARSER_ALIASES['init'],
|
||||
help='Initialize an empty Borg repository',
|
||||
description='Initialize an empty Borg repository',
|
||||
add_help=False,
|
||||
)
|
||||
init_group = init_parser.add_argument_group('init arguments')
|
||||
init_group.add_argument(
|
||||
'-e',
|
||||
'--encryption',
|
||||
dest='encryption_mode',
|
||||
help='Borg repository encryption mode',
|
||||
required=True,
|
||||
)
|
||||
init_group.add_argument(
|
||||
'--append-only',
|
||||
dest='append_only',
|
||||
action='store_true',
|
||||
help='Create an append-only repository',
|
||||
)
|
||||
init_group.add_argument(
|
||||
'--storage-quota',
|
||||
dest='storage_quota',
|
||||
help='Create a repository with a fixed storage quota',
|
||||
)
|
||||
init_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
prune_parser = subparsers.add_parser(
|
||||
'prune',
|
||||
aliases=SUBPARSER_ALIASES['prune'],
|
||||
help='Prune archives according to the retention policy',
|
||||
description='Prune archives according to the retention policy',
|
||||
add_help=False,
|
||||
)
|
||||
prune_group = prune_parser.add_argument_group('prune arguments')
|
||||
prune_group.add_argument(
|
||||
'--stats',
|
||||
dest='stats',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Display statistics of archive',
|
||||
)
|
||||
prune_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
create_parser = subparsers.add_parser(
|
||||
'create',
|
||||
aliases=SUBPARSER_ALIASES['create'],
|
||||
help='Create archives (actually perform backups)',
|
||||
description='Create archives (actually perform backups)',
|
||||
add_help=False,
|
||||
)
|
||||
create_group = create_parser.add_argument_group('create arguments')
|
||||
create_group.add_argument(
|
||||
'--progress',
|
||||
dest='progress',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Display progress for each file as it is processed',
|
||||
)
|
||||
create_group.add_argument(
|
||||
'--stats',
|
||||
dest='stats',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Display statistics of archive',
|
||||
)
|
||||
create_group.add_argument(
|
||||
'--json', dest='json', default=False, action='store_true', help='Output results as JSON'
|
||||
)
|
||||
create_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
check_parser = subparsers.add_parser(
|
||||
'check',
|
||||
aliases=SUBPARSER_ALIASES['check'],
|
||||
help='Check archives for consistency',
|
||||
description='Check archives for consistency',
|
||||
add_help=False,
|
||||
)
|
||||
check_group = check_parser.add_argument_group('check arguments')
|
||||
check_group.add_argument(
|
||||
'--only',
|
||||
metavar='CHECK',
|
||||
choices=('repository', 'archives', 'data', 'extract'),
|
||||
dest='only',
|
||||
action='append',
|
||||
help='Run a particular consistency check (repository, archives, data, or extract) instead of configured checks; can specify flag multiple times',
|
||||
)
|
||||
check_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
extract_parser = subparsers.add_parser(
|
||||
'extract',
|
||||
aliases=SUBPARSER_ALIASES['extract'],
|
||||
help='Extract a named archive to the current directory',
|
||||
description='Extract a named archive to the current directory',
|
||||
add_help=False,
|
||||
)
|
||||
extract_group = extract_parser.add_argument_group('extract arguments')
|
||||
extract_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to extract, defaults to the configured repository if there is only one',
|
||||
)
|
||||
extract_group.add_argument('--archive', help='Name of archive to operate on', required=True)
|
||||
extract_group.add_argument(
|
||||
'--restore-path',
|
||||
nargs='+',
|
||||
dest='restore_paths',
|
||||
help='Paths to restore from archive, defaults to the entire archive',
|
||||
)
|
||||
extract_group.add_argument(
|
||||
'--progress',
|
||||
dest='progress',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Display progress for each file as it is processed',
|
||||
)
|
||||
extract_group.add_argument(
|
||||
'-h', '--help', action='help', help='Show this help message and exit'
|
||||
)
|
||||
|
||||
list_parser = subparsers.add_parser(
|
||||
'list',
|
||||
aliases=SUBPARSER_ALIASES['list'],
|
||||
help='List archives',
|
||||
description='List archives or the contents of an archive',
|
||||
add_help=False,
|
||||
)
|
||||
list_group = list_parser.add_argument_group('list arguments')
|
||||
list_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to list, defaults to the configured repository if there is only one',
|
||||
)
|
||||
list_group.add_argument('--archive', help='Name of archive to list')
|
||||
list_group.add_argument(
|
||||
'--short', default=False, action='store_true', help='Output only archive or path names'
|
||||
)
|
||||
list_group.add_argument('--format', help='Format for file listing')
|
||||
list_group.add_argument(
|
||||
'--json', default=False, action='store_true', help='Output results as JSON'
|
||||
)
|
||||
list_group.add_argument(
|
||||
'-P', '--prefix', help='Only list archive names starting with this prefix'
|
||||
)
|
||||
list_group.add_argument(
|
||||
'-a', '--glob-archives', metavar='GLOB', help='Only list archive names matching this glob'
|
||||
)
|
||||
list_group.add_argument(
|
||||
'--sort-by', metavar='KEYS', help='Comma-separated list of sorting keys'
|
||||
)
|
||||
list_group.add_argument(
|
||||
'--first', metavar='N', help='List first N archives after other filters are applied'
|
||||
)
|
||||
list_group.add_argument(
|
||||
'--last', metavar='N', help='List first N archives after other filters are applied'
|
||||
)
|
||||
list_group.add_argument(
|
||||
'-e', '--exclude', metavar='PATTERN', help='Exclude paths matching the pattern'
|
||||
)
|
||||
list_group.add_argument(
|
||||
'--exclude-from', metavar='FILENAME', help='Exclude paths from exclude file, one per line'
|
||||
)
|
||||
list_group.add_argument('--pattern', help='Include or exclude paths matching a pattern')
|
||||
list_group.add_argument(
|
||||
'--pattern-from',
|
||||
metavar='FILENAME',
|
||||
help='Include or exclude paths matching patterns from pattern file, one per line',
|
||||
)
|
||||
list_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
info_parser = subparsers.add_parser(
|
||||
'info',
|
||||
aliases=SUBPARSER_ALIASES['info'],
|
||||
help='Display summary information on archives',
|
||||
description='Display summary information on archives',
|
||||
add_help=False,
|
||||
)
|
||||
info_group = info_parser.add_argument_group('info arguments')
|
||||
info_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to show info for, defaults to the configured repository if there is only one',
|
||||
)
|
||||
info_group.add_argument('--archive', help='Name of archive to show info for')
|
||||
info_group.add_argument(
|
||||
'--json', dest='json', default=False, action='store_true', help='Output results as JSON'
|
||||
)
|
||||
info_group.add_argument(
|
||||
'-P', '--prefix', help='Only show info for archive names starting with this prefix'
|
||||
)
|
||||
info_group.add_argument(
|
||||
'-a',
|
||||
'--glob-archives',
|
||||
metavar='GLOB',
|
||||
help='Only show info for archive names matching this glob',
|
||||
)
|
||||
info_group.add_argument(
|
||||
'--sort-by', metavar='KEYS', help='Comma-separated list of sorting keys'
|
||||
)
|
||||
info_group.add_argument(
|
||||
'--first',
|
||||
metavar='N',
|
||||
help='Show info for first N archives after other filters are applied',
|
||||
)
|
||||
info_group.add_argument(
|
||||
'--last', metavar='N', help='Show info for first N archives after other filters are applied'
|
||||
)
|
||||
info_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
arguments = parse_subparser_arguments(unparsed_arguments, subparsers)
|
||||
arguments['global'] = parse_global_arguments(unparsed_arguments, top_level_parser, subparsers)
|
||||
|
||||
if arguments['global'].excludes_filename:
|
||||
raise ValueError(
|
||||
'The --excludes option has been replaced with exclude_patterns in configuration'
|
||||
)
|
||||
|
||||
if 'init' in arguments and arguments['global'].dry_run:
|
||||
raise ValueError('The init action cannot be used with the --dry-run option')
|
||||
|
||||
if (
|
||||
'list' in arguments
|
||||
and 'info' in arguments
|
||||
and arguments['list'].json
|
||||
and arguments['info'].json
|
||||
):
|
||||
raise ValueError('With the --json option, list and info actions cannot be used together')
|
||||
|
||||
return arguments
|
||||
367
borgmatic/commands/borgmatic.py
Normal file
367
borgmatic/commands/borgmatic.py
Normal file
|
|
@ -0,0 +1,367 @@
|
|||
import collections
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from subprocess import CalledProcessError
|
||||
|
||||
import colorama
|
||||
import pkg_resources
|
||||
|
||||
from borgmatic import hook
|
||||
from borgmatic.borg import check as borg_check
|
||||
from borgmatic.borg import create as borg_create
|
||||
from borgmatic.borg import environment as borg_environment
|
||||
from borgmatic.borg import extract as borg_extract
|
||||
from borgmatic.borg import info as borg_info
|
||||
from borgmatic.borg import init as borg_init
|
||||
from borgmatic.borg import list as borg_list
|
||||
from borgmatic.borg import prune as borg_prune
|
||||
from borgmatic.commands.arguments import parse_arguments
|
||||
from borgmatic.config import checks, collect, convert, validate
|
||||
from borgmatic.logger import configure_logging, should_do_markup
|
||||
from borgmatic.signals import configure_signals
|
||||
from borgmatic.verbosity import verbosity_to_log_level
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
LEGACY_CONFIG_PATH = '/etc/borgmatic/config'
|
||||
|
||||
|
||||
def run_configuration(config_filename, config, arguments): # pragma: no cover
|
||||
'''
|
||||
Given a config filename, the corresponding parsed config dict, and command-line arguments as a
|
||||
dict from subparser name to a namespace of parsed arguments, execute its defined pruning,
|
||||
backups, consistency checks, and/or other actions.
|
||||
|
||||
Yield JSON output strings from executing any actions that produce JSON.
|
||||
'''
|
||||
(location, storage, retention, consistency, hooks) = (
|
||||
config.get(section_name, {})
|
||||
for section_name in ('location', 'storage', 'retention', 'consistency', 'hooks')
|
||||
)
|
||||
global_arguments = arguments['global']
|
||||
|
||||
try:
|
||||
local_path = location.get('local_path', 'borg')
|
||||
remote_path = location.get('remote_path')
|
||||
borg_environment.initialize(storage)
|
||||
|
||||
if 'create' in arguments:
|
||||
hook.execute_hook(
|
||||
hooks.get('before_backup'),
|
||||
hooks.get('umask'),
|
||||
config_filename,
|
||||
'pre-backup',
|
||||
global_arguments.dry_run,
|
||||
)
|
||||
|
||||
for repository_path in location['repositories']:
|
||||
yield from run_actions(
|
||||
arguments=arguments,
|
||||
location=location,
|
||||
storage=storage,
|
||||
retention=retention,
|
||||
consistency=consistency,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
repository_path=repository_path,
|
||||
)
|
||||
|
||||
if 'create' in arguments:
|
||||
hook.execute_hook(
|
||||
hooks.get('after_backup'),
|
||||
hooks.get('umask'),
|
||||
config_filename,
|
||||
'post-backup',
|
||||
global_arguments.dry_run,
|
||||
)
|
||||
except (OSError, CalledProcessError):
|
||||
hook.execute_hook(
|
||||
hooks.get('on_error'),
|
||||
hooks.get('umask'),
|
||||
config_filename,
|
||||
'on-error',
|
||||
global_arguments.dry_run,
|
||||
)
|
||||
raise
|
||||
|
||||
|
||||
def run_actions(
|
||||
*,
|
||||
arguments,
|
||||
location,
|
||||
storage,
|
||||
retention,
|
||||
consistency,
|
||||
local_path,
|
||||
remote_path,
|
||||
repository_path
|
||||
): # pragma: no cover
|
||||
'''
|
||||
Given parsed command-line arguments as an argparse.ArgumentParser instance, several different
|
||||
configuration dicts, local and remote paths to Borg, and a repository name, run all actions
|
||||
from the command-line arguments on the given repository.
|
||||
|
||||
Yield JSON output strings from executing any actions that produce JSON.
|
||||
'''
|
||||
repository = os.path.expanduser(repository_path)
|
||||
global_arguments = arguments['global']
|
||||
dry_run_label = ' (dry run; not making any changes)' if global_arguments.dry_run else ''
|
||||
if 'init' in arguments:
|
||||
logger.info('{}: Initializing repository'.format(repository))
|
||||
borg_init.initialize_repository(
|
||||
repository,
|
||||
arguments['init'].encryption_mode,
|
||||
arguments['init'].append_only,
|
||||
arguments['init'].storage_quota,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
if 'prune' in arguments:
|
||||
logger.info('{}: Pruning archives{}'.format(repository, dry_run_label))
|
||||
borg_prune.prune_archives(
|
||||
global_arguments.dry_run,
|
||||
repository,
|
||||
storage,
|
||||
retention,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
stats=arguments['prune'].stats,
|
||||
)
|
||||
if 'create' in arguments:
|
||||
logger.info('{}: Creating archive{}'.format(repository, dry_run_label))
|
||||
json_output = borg_create.create_archive(
|
||||
global_arguments.dry_run,
|
||||
repository,
|
||||
location,
|
||||
storage,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
progress=arguments['create'].progress,
|
||||
stats=arguments['create'].stats,
|
||||
json=arguments['create'].json,
|
||||
)
|
||||
if json_output:
|
||||
yield json.loads(json_output)
|
||||
if 'check' in arguments and checks.repository_enabled_for_checks(repository, consistency):
|
||||
logger.info('{}: Running consistency checks'.format(repository))
|
||||
borg_check.check_archives(
|
||||
repository,
|
||||
storage,
|
||||
consistency,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
only_checks=arguments['check'].only,
|
||||
)
|
||||
if 'extract' in arguments:
|
||||
if arguments['extract'].repository is None or repository == arguments['extract'].repository:
|
||||
logger.info(
|
||||
'{}: Extracting archive {}'.format(repository, arguments['extract'].archive)
|
||||
)
|
||||
borg_extract.extract_archive(
|
||||
global_arguments.dry_run,
|
||||
repository,
|
||||
arguments['extract'].archive,
|
||||
arguments['extract'].restore_paths,
|
||||
location,
|
||||
storage,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
progress=arguments['extract'].progress,
|
||||
)
|
||||
if 'list' in arguments:
|
||||
if arguments['list'].repository is None or repository == arguments['list'].repository:
|
||||
logger.info('{}: Listing archives'.format(repository))
|
||||
json_output = borg_list.list_archives(
|
||||
repository,
|
||||
storage,
|
||||
list_arguments=arguments['list'],
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
if json_output:
|
||||
yield json.loads(json_output)
|
||||
if 'info' in arguments:
|
||||
if arguments['info'].repository is None or repository == arguments['info'].repository:
|
||||
logger.info('{}: Displaying summary info for archives'.format(repository))
|
||||
json_output = borg_info.display_archives_info(
|
||||
repository,
|
||||
storage,
|
||||
info_arguments=arguments['info'],
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
if json_output:
|
||||
yield json.loads(json_output)
|
||||
|
||||
|
||||
def load_configurations(config_filenames):
|
||||
'''
|
||||
Given a sequence of configuration filenames, load and validate each configuration file. Return
|
||||
the results as a tuple of: dict of configuration filename to corresponding parsed configuration,
|
||||
and sequence of logging.LogRecord instances containing any parse errors.
|
||||
'''
|
||||
# Dict mapping from config filename to corresponding parsed config dict.
|
||||
configs = collections.OrderedDict()
|
||||
logs = []
|
||||
|
||||
# Parse and load each configuration file.
|
||||
for config_filename in config_filenames:
|
||||
try:
|
||||
configs[config_filename] = validate.parse_configuration(
|
||||
config_filename, validate.schema_filename()
|
||||
)
|
||||
except (ValueError, OSError, validate.Validation_error) as error:
|
||||
logs.extend(
|
||||
[
|
||||
logging.makeLogRecord(
|
||||
dict(
|
||||
levelno=logging.CRITICAL,
|
||||
levelname='CRITICAL',
|
||||
msg='{}: Error parsing configuration file'.format(config_filename),
|
||||
)
|
||||
),
|
||||
logging.makeLogRecord(
|
||||
dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error)
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
return (configs, logs)
|
||||
|
||||
|
||||
def collect_configuration_run_summary_logs(configs, arguments):
|
||||
'''
|
||||
Given a dict of configuration filename to corresponding parsed configuration, and parsed
|
||||
command-line arguments as a dict from subparser name to a parsed namespace of arguments, run
|
||||
each configuration file and yield a series of logging.LogRecord instances containing summary
|
||||
information about each run.
|
||||
|
||||
As a side effect of running through these configuration files, output their JSON results, if
|
||||
any, to stdout.
|
||||
'''
|
||||
# Run cross-file validation checks.
|
||||
if 'extract' in arguments:
|
||||
repository = arguments['extract'].repository
|
||||
elif 'list' in arguments and arguments['list'].archive:
|
||||
repository = arguments['list'].repository
|
||||
else:
|
||||
repository = None
|
||||
|
||||
if repository:
|
||||
try:
|
||||
validate.guard_configuration_contains_repository(repository, configs)
|
||||
except ValueError as error:
|
||||
yield logging.makeLogRecord(
|
||||
dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error)
|
||||
)
|
||||
return
|
||||
|
||||
# Execute the actions corresponding to each configuration file.
|
||||
json_results = []
|
||||
for config_filename, config in configs.items():
|
||||
try:
|
||||
json_results.extend(list(run_configuration(config_filename, config, arguments)))
|
||||
yield logging.makeLogRecord(
|
||||
dict(
|
||||
levelno=logging.INFO,
|
||||
levelname='INFO',
|
||||
msg='{}: Successfully ran configuration file'.format(config_filename),
|
||||
)
|
||||
)
|
||||
except CalledProcessError as error:
|
||||
yield logging.makeLogRecord(
|
||||
dict(
|
||||
levelno=logging.CRITICAL,
|
||||
levelname='CRITICAL',
|
||||
msg='{}: Error running configuration file'.format(config_filename),
|
||||
)
|
||||
)
|
||||
yield logging.makeLogRecord(
|
||||
dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error.output)
|
||||
)
|
||||
yield logging.makeLogRecord(
|
||||
dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error)
|
||||
)
|
||||
except (ValueError, OSError) as error:
|
||||
yield logging.makeLogRecord(
|
||||
dict(
|
||||
levelno=logging.CRITICAL,
|
||||
levelname='CRITICAL',
|
||||
msg='{}: Error running configuration file'.format(config_filename),
|
||||
)
|
||||
)
|
||||
yield logging.makeLogRecord(
|
||||
dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error)
|
||||
)
|
||||
|
||||
if json_results:
|
||||
sys.stdout.write(json.dumps(json_results))
|
||||
|
||||
if not configs:
|
||||
yield logging.makeLogRecord(
|
||||
dict(
|
||||
levelno=logging.CRITICAL,
|
||||
levelname='CRITICAL',
|
||||
msg='{}: No configuration files found'.format(
|
||||
' '.join(arguments['global'].config_paths)
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def exit_with_help_link(): # pragma: no cover
|
||||
'''
|
||||
Display a link to get help and exit with an error code.
|
||||
'''
|
||||
logger.critical('')
|
||||
logger.critical('Need some help? https://torsion.org/borgmatic/#issues')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main(): # pragma: no cover
|
||||
configure_signals()
|
||||
|
||||
try:
|
||||
arguments = parse_arguments(*sys.argv[1:])
|
||||
except ValueError as error:
|
||||
configure_logging(logging.CRITICAL)
|
||||
logger.critical(error)
|
||||
exit_with_help_link()
|
||||
except SystemExit as error:
|
||||
if error.code == 0:
|
||||
raise error
|
||||
configure_logging(logging.CRITICAL)
|
||||
logger.critical('Error parsing arguments: {}'.format(' '.join(sys.argv)))
|
||||
exit_with_help_link()
|
||||
|
||||
global_arguments = arguments['global']
|
||||
if global_arguments.version:
|
||||
print(pkg_resources.require('borgmatic')[0].version)
|
||||
sys.exit(0)
|
||||
|
||||
config_filenames = tuple(collect.collect_config_filenames(global_arguments.config_paths))
|
||||
configs, parse_logs = load_configurations(config_filenames)
|
||||
|
||||
colorama.init(autoreset=True, strip=not should_do_markup(global_arguments.no_color, configs))
|
||||
configure_logging(
|
||||
verbosity_to_log_level(global_arguments.verbosity),
|
||||
verbosity_to_log_level(global_arguments.syslog_verbosity),
|
||||
)
|
||||
|
||||
logger.debug('Ensuring legacy configuration is upgraded')
|
||||
convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)
|
||||
|
||||
summary_logs = list(collect_configuration_run_summary_logs(configs, arguments))
|
||||
|
||||
logger.info('')
|
||||
logger.info('summary:')
|
||||
[
|
||||
logger.handle(log)
|
||||
for log in parse_logs + summary_logs
|
||||
if log.levelno >= logger.getEffectiveLevel()
|
||||
]
|
||||
|
||||
if any(log.levelno == logging.CRITICAL for log in summary_logs):
|
||||
exit_with_help_link()
|
||||
108
borgmatic/commands/convert_config.py
Normal file
108
borgmatic/commands/convert_config.py
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from ruamel import yaml
|
||||
|
||||
from borgmatic.config import convert, generate, legacy, validate
|
||||
|
||||
DEFAULT_SOURCE_CONFIG_FILENAME = '/etc/borgmatic/config'
|
||||
DEFAULT_SOURCE_EXCLUDES_FILENAME = '/etc/borgmatic/excludes'
|
||||
DEFAULT_DESTINATION_CONFIG_FILENAME = '/etc/borgmatic/config.yaml'
|
||||
|
||||
|
||||
def parse_arguments(*arguments):
|
||||
'''
|
||||
Given command-line arguments with which this script was invoked, parse the arguments and return
|
||||
them as an ArgumentParser instance.
|
||||
'''
|
||||
parser = ArgumentParser(
|
||||
description='''
|
||||
Convert legacy INI-style borgmatic configuration and excludes files to a single YAML
|
||||
configuration file. Note that this replaces any comments from the source files.
|
||||
'''
|
||||
)
|
||||
parser.add_argument(
|
||||
'-s',
|
||||
'--source-config',
|
||||
dest='source_config_filename',
|
||||
default=DEFAULT_SOURCE_CONFIG_FILENAME,
|
||||
help='Source INI-style configuration filename. Default: {}'.format(
|
||||
DEFAULT_SOURCE_CONFIG_FILENAME
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'-e',
|
||||
'--source-excludes',
|
||||
dest='source_excludes_filename',
|
||||
default=DEFAULT_SOURCE_EXCLUDES_FILENAME
|
||||
if os.path.exists(DEFAULT_SOURCE_EXCLUDES_FILENAME)
|
||||
else None,
|
||||
help='Excludes filename',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-d',
|
||||
'--destination-config',
|
||||
dest='destination_config_filename',
|
||||
default=DEFAULT_DESTINATION_CONFIG_FILENAME,
|
||||
help='Destination YAML configuration filename. Default: {}'.format(
|
||||
DEFAULT_DESTINATION_CONFIG_FILENAME
|
||||
),
|
||||
)
|
||||
|
||||
return parser.parse_args(arguments)
|
||||
|
||||
|
||||
TEXT_WRAP_CHARACTERS = 80
|
||||
|
||||
|
||||
def display_result(args): # pragma: no cover
|
||||
result_lines = textwrap.wrap(
|
||||
'Your borgmatic configuration has been upgraded. Please review the result in {}.'.format(
|
||||
args.destination_config_filename
|
||||
),
|
||||
TEXT_WRAP_CHARACTERS,
|
||||
)
|
||||
|
||||
delete_lines = textwrap.wrap(
|
||||
'Once you are satisfied, you can safely delete {}{}.'.format(
|
||||
args.source_config_filename,
|
||||
' and {}'.format(args.source_excludes_filename)
|
||||
if args.source_excludes_filename
|
||||
else '',
|
||||
),
|
||||
TEXT_WRAP_CHARACTERS,
|
||||
)
|
||||
|
||||
print('\n'.join(result_lines))
|
||||
print()
|
||||
print('\n'.join(delete_lines))
|
||||
|
||||
|
||||
def main(): # pragma: no cover
|
||||
try:
|
||||
args = parse_arguments(*sys.argv[1:])
|
||||
schema = yaml.round_trip_load(open(validate.schema_filename()).read())
|
||||
source_config = legacy.parse_configuration(
|
||||
args.source_config_filename, legacy.CONFIG_FORMAT
|
||||
)
|
||||
source_config_file_mode = os.stat(args.source_config_filename).st_mode
|
||||
source_excludes = (
|
||||
open(args.source_excludes_filename).read().splitlines()
|
||||
if args.source_excludes_filename
|
||||
else []
|
||||
)
|
||||
|
||||
destination_config = convert.convert_legacy_parsed_config(
|
||||
source_config, source_excludes, schema
|
||||
)
|
||||
|
||||
generate.write_configuration(
|
||||
args.destination_config_filename, destination_config, mode=source_config_file_mode
|
||||
)
|
||||
|
||||
display_result(args)
|
||||
except (ValueError, OSError) as error:
|
||||
print(error, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
44
borgmatic/commands/generate_config.py
Normal file
44
borgmatic/commands/generate_config.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import sys
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from borgmatic.config import generate, validate
|
||||
|
||||
DEFAULT_DESTINATION_CONFIG_FILENAME = '/etc/borgmatic/config.yaml'
|
||||
|
||||
|
||||
def parse_arguments(*arguments):
|
||||
'''
|
||||
Given command-line arguments with which this script was invoked, parse the arguments and return
|
||||
them as an ArgumentParser instance.
|
||||
'''
|
||||
parser = ArgumentParser(description='Generate a sample borgmatic YAML configuration file.')
|
||||
parser.add_argument(
|
||||
'-d',
|
||||
'--destination',
|
||||
dest='destination_filename',
|
||||
default=DEFAULT_DESTINATION_CONFIG_FILENAME,
|
||||
help='Destination YAML configuration filename. Default: {}'.format(
|
||||
DEFAULT_DESTINATION_CONFIG_FILENAME
|
||||
),
|
||||
)
|
||||
|
||||
return parser.parse_args(arguments)
|
||||
|
||||
|
||||
def main(): # pragma: no cover
|
||||
try:
|
||||
args = parse_arguments(*sys.argv[1:])
|
||||
|
||||
generate.generate_sample_configuration(
|
||||
args.destination_filename, validate.schema_filename()
|
||||
)
|
||||
|
||||
print('Generated a sample configuration file at {}.'.format(args.destination_filename))
|
||||
print()
|
||||
print('Please edit the file to suit your needs. The values are representative.')
|
||||
print('All fields are optional except where indicated.')
|
||||
print()
|
||||
print('If you ever need help: https://torsion.org/borgmatic/#issues')
|
||||
except (ValueError, OSError) as error:
|
||||
print(error, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
56
borgmatic/commands/validate_config.py
Normal file
56
borgmatic/commands/validate_config.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import logging
|
||||
import sys
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from borgmatic.config import collect, validate
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def parse_arguments(*arguments):
|
||||
'''
|
||||
Given command-line arguments with which this script was invoked, parse the arguments and return
|
||||
them as an ArgumentParser instance.
|
||||
'''
|
||||
config_paths = collect.get_default_config_paths()
|
||||
|
||||
parser = ArgumentParser(description='Validate borgmatic configuration file(s).')
|
||||
parser.add_argument(
|
||||
'-c',
|
||||
'--config',
|
||||
nargs='+',
|
||||
dest='config_paths',
|
||||
default=config_paths,
|
||||
help='Configuration filenames or directories, defaults to: {}'.format(
|
||||
' '.join(config_paths)
|
||||
),
|
||||
)
|
||||
|
||||
return parser.parse_args(arguments)
|
||||
|
||||
|
||||
def main(): # pragma: no cover
|
||||
args = parse_arguments(*sys.argv[1:])
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
||||
|
||||
config_filenames = tuple(collect.collect_config_filenames(args.config_paths))
|
||||
if len(config_filenames) == 0:
|
||||
logger.critical('No files to validate found')
|
||||
sys.exit(1)
|
||||
|
||||
found_issues = False
|
||||
for config_filename in config_filenames:
|
||||
try:
|
||||
validate.parse_configuration(config_filename, validate.schema_filename())
|
||||
except (ValueError, OSError, validate.Validation_error) as error:
|
||||
logging.critical('{}: Error parsing configuration file'.format(config_filename))
|
||||
logging.critical(error)
|
||||
found_issues = True
|
||||
|
||||
if found_issues:
|
||||
sys.exit(1)
|
||||
else:
|
||||
logger.info(
|
||||
'All given configuration files are valid: {}'.format(', '.join(config_filenames))
|
||||
)
|
||||
9
borgmatic/config/checks.py
Normal file
9
borgmatic/config/checks.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def repository_enabled_for_checks(repository, consistency):
|
||||
'''
|
||||
Given a repository name and a consistency configuration dict, return whether the repository
|
||||
is enabled to have consistency checks run.
|
||||
'''
|
||||
if not consistency.get('check_repositories'):
|
||||
return True
|
||||
|
||||
return repository in consistency['check_repositories']
|
||||
48
borgmatic/config/collect.py
Normal file
48
borgmatic/config/collect.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import os
|
||||
|
||||
|
||||
def get_default_config_paths():
|
||||
'''
|
||||
Based on the value of the XDG_CONFIG_HOME and HOME environment variables, return a list of
|
||||
default configuration paths. This includes both system-wide configuration and configuration in
|
||||
the current user's home directory.
|
||||
'''
|
||||
user_config_directory = os.getenv('XDG_CONFIG_HOME') or os.path.expandvars(
|
||||
os.path.join('$HOME', '.config')
|
||||
)
|
||||
|
||||
return [
|
||||
'/etc/borgmatic/config.yaml',
|
||||
'/etc/borgmatic.d',
|
||||
'%s/borgmatic/config.yaml' % user_config_directory,
|
||||
]
|
||||
|
||||
|
||||
def collect_config_filenames(config_paths):
|
||||
'''
|
||||
Given a sequence of config paths, both filenames and directories, resolve that to an iterable
|
||||
of files. Accomplish this by listing any given directories looking for contained config files
|
||||
(ending with the ".yaml" or ".yml" extension). This is non-recursive, so any directories within the given
|
||||
directories are ignored.
|
||||
|
||||
Return paths even if they don't exist on disk, so the user can find out about missing
|
||||
configuration paths. However, skip a default config path if it's missing, so the user doesn't
|
||||
have to create a default config path unless they need it.
|
||||
'''
|
||||
real_default_config_paths = set(map(os.path.realpath, get_default_config_paths()))
|
||||
|
||||
for path in config_paths:
|
||||
exists = os.path.exists(path)
|
||||
|
||||
if os.path.realpath(path) in real_default_config_paths and not exists:
|
||||
continue
|
||||
|
||||
if not os.path.isdir(path) or not exists:
|
||||
yield path
|
||||
continue
|
||||
|
||||
for filename in sorted(os.listdir(path)):
|
||||
full_filename = os.path.join(path, filename)
|
||||
matching_filetype = full_filename.endswith('.yaml') or full_filename.endswith('.yml')
|
||||
if matching_filetype and not os.path.isdir(full_filename):
|
||||
yield full_filename
|
||||
95
borgmatic/config/convert.py
Normal file
95
borgmatic/config/convert.py
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
import os
|
||||
|
||||
from ruamel import yaml
|
||||
|
||||
from borgmatic.config import generate
|
||||
|
||||
|
||||
def _convert_section(source_section_config, section_schema):
|
||||
'''
|
||||
Given a legacy Parsed_config instance for a single section, convert it to its corresponding
|
||||
yaml.comments.CommentedMap representation in preparation for actual serialization to YAML.
|
||||
|
||||
Where integer types exist in the given section schema, convert their values to integers.
|
||||
'''
|
||||
destination_section_config = yaml.comments.CommentedMap(
|
||||
[
|
||||
(
|
||||
option_name,
|
||||
int(option_value)
|
||||
if section_schema['map'].get(option_name, {}).get('type') == 'int'
|
||||
else option_value,
|
||||
)
|
||||
for option_name, option_value in source_section_config.items()
|
||||
]
|
||||
)
|
||||
|
||||
return destination_section_config
|
||||
|
||||
|
||||
def convert_legacy_parsed_config(source_config, source_excludes, schema):
|
||||
'''
|
||||
Given a legacy Parsed_config instance loaded from an INI-style config file and a list of exclude
|
||||
patterns, convert them to a corresponding yaml.comments.CommentedMap representation in
|
||||
preparation for serialization to a single YAML config file.
|
||||
|
||||
Additionally, use the given schema as a source of helpful comments to include within the
|
||||
returned CommentedMap.
|
||||
'''
|
||||
destination_config = yaml.comments.CommentedMap(
|
||||
[
|
||||
(section_name, _convert_section(section_config, schema['map'][section_name]))
|
||||
for section_name, section_config in source_config._asdict().items()
|
||||
]
|
||||
)
|
||||
|
||||
# Split space-seperated values into actual lists, make "repository" into a list, and merge in
|
||||
# excludes.
|
||||
location = destination_config['location']
|
||||
location['source_directories'] = source_config.location['source_directories'].split(' ')
|
||||
location['repositories'] = [location.pop('repository')]
|
||||
location['exclude_patterns'] = source_excludes
|
||||
|
||||
if source_config.consistency.get('checks'):
|
||||
destination_config['consistency']['checks'] = source_config.consistency['checks'].split(' ')
|
||||
|
||||
# Add comments to each section, and then add comments to the fields in each section.
|
||||
generate.add_comments_to_configuration(destination_config, schema)
|
||||
|
||||
for section_name, section_config in destination_config.items():
|
||||
generate.add_comments_to_configuration(
|
||||
section_config, schema['map'][section_name], indent=generate.INDENT
|
||||
)
|
||||
|
||||
return destination_config
|
||||
|
||||
|
||||
class Legacy_configuration_not_upgraded(FileNotFoundError):
|
||||
def __init__(self):
|
||||
super(Legacy_configuration_not_upgraded, self).__init__(
|
||||
'''borgmatic changed its configuration file format in version 1.1.0 from INI-style
|
||||
to YAML. This better supports validation, and has a more natural way to express
|
||||
lists of values. To upgrade your existing configuration, run:
|
||||
|
||||
sudo upgrade-borgmatic-config
|
||||
|
||||
That will generate a new YAML configuration file at /etc/borgmatic/config.yaml
|
||||
(by default) using the values from both your existing configuration and excludes
|
||||
files. The new version of borgmatic will consume the YAML configuration file
|
||||
instead of the old one.'''
|
||||
)
|
||||
|
||||
|
||||
def guard_configuration_upgraded(source_config_filename, destination_config_filenames):
|
||||
'''
|
||||
If legacy source configuration exists but no destination upgraded configs do, raise
|
||||
Legacy_configuration_not_upgraded.
|
||||
|
||||
The idea is that we want to alert the user about upgrading their config if they haven't already.
|
||||
'''
|
||||
destination_config_exists = any(
|
||||
os.path.exists(filename) for filename in destination_config_filenames
|
||||
)
|
||||
|
||||
if os.path.exists(source_config_filename) and not destination_config_exists:
|
||||
raise Legacy_configuration_not_upgraded()
|
||||
144
borgmatic/config/generate.py
Normal file
144
borgmatic/config/generate.py
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
import os
|
||||
|
||||
from ruamel import yaml
|
||||
|
||||
INDENT = 4
|
||||
|
||||
|
||||
def _insert_newline_before_comment(config, field_name):
|
||||
'''
|
||||
Using some ruamel.yaml black magic, insert a blank line in the config right before the given
|
||||
field and its comments.
|
||||
'''
|
||||
config.ca.items[field_name][1].insert(
|
||||
0, yaml.tokens.CommentToken('\n', yaml.error.CommentMark(0), None)
|
||||
)
|
||||
|
||||
|
||||
def _schema_to_sample_configuration(schema, level=0):
|
||||
'''
|
||||
Given a loaded configuration schema, generate and return sample config for it. Include comments
|
||||
for each section based on the schema "desc" description.
|
||||
'''
|
||||
example = schema.get('example')
|
||||
if example is not None:
|
||||
return example
|
||||
|
||||
config = yaml.comments.CommentedMap(
|
||||
[
|
||||
(section_name, _schema_to_sample_configuration(section_schema, level + 1))
|
||||
for section_name, section_schema in schema['map'].items()
|
||||
]
|
||||
)
|
||||
|
||||
add_comments_to_configuration(config, schema, indent=(level * INDENT))
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def _comment_out_line(line):
|
||||
# If it's already is commented out (or empty), there's nothing further to do!
|
||||
stripped_line = line.lstrip()
|
||||
if not stripped_line or stripped_line.startswith('#'):
|
||||
return line
|
||||
|
||||
# Comment out the names of optional sections.
|
||||
one_indent = ' ' * INDENT
|
||||
if not line.startswith(one_indent):
|
||||
return '# ' + line
|
||||
|
||||
# Otherwise, comment out the line, but insert the "#" after the first indent for aesthetics.
|
||||
return '# '.join((one_indent, line[INDENT:]))
|
||||
|
||||
|
||||
REQUIRED_KEYS = {'source_directories', 'repositories', 'keep_daily'}
|
||||
REQUIRED_SECTION_NAMES = {'location', 'retention'}
|
||||
|
||||
|
||||
def _comment_out_optional_configuration(rendered_config):
|
||||
'''
|
||||
Post-process a rendered configuration string to comment out optional key/values. The idea is
|
||||
that this prevents the user from having to comment out a bunch of configuration they don't care
|
||||
about to get to a minimal viable configuration file.
|
||||
|
||||
Ideally ruamel.yaml would support this during configuration generation, but it's not terribly
|
||||
easy to accomplish that way.
|
||||
'''
|
||||
lines = []
|
||||
required = False
|
||||
|
||||
for line in rendered_config.split('\n'):
|
||||
key = line.strip().split(':')[0]
|
||||
|
||||
if key in REQUIRED_SECTION_NAMES:
|
||||
lines.append(line)
|
||||
continue
|
||||
|
||||
# Upon encountering a required configuration option, skip commenting out lines until the
|
||||
# next blank line.
|
||||
if key in REQUIRED_KEYS:
|
||||
required = True
|
||||
elif not key:
|
||||
required = False
|
||||
|
||||
lines.append(_comment_out_line(line) if not required else line)
|
||||
|
||||
return '\n'.join(lines)
|
||||
|
||||
|
||||
def _render_configuration(config):
|
||||
'''
|
||||
Given a config data structure of nested OrderedDicts, render the config as YAML and return it.
|
||||
'''
|
||||
return yaml.round_trip_dump(config, indent=INDENT, block_seq_indent=INDENT)
|
||||
|
||||
|
||||
def write_configuration(config_filename, rendered_config, mode=0o600):
|
||||
'''
|
||||
Given a target config filename and rendered config YAML, write it out to file. Create any
|
||||
containing directories as needed.
|
||||
'''
|
||||
if os.path.exists(config_filename):
|
||||
raise FileExistsError('{} already exists. Aborting.'.format(config_filename))
|
||||
|
||||
try:
|
||||
os.makedirs(os.path.dirname(config_filename), mode=0o700)
|
||||
except (FileExistsError, FileNotFoundError):
|
||||
pass
|
||||
|
||||
with open(config_filename, 'w') as config_file:
|
||||
config_file.write(rendered_config)
|
||||
|
||||
os.chmod(config_filename, mode)
|
||||
|
||||
|
||||
def add_comments_to_configuration(config, schema, indent=0):
|
||||
'''
|
||||
Using descriptions from a schema as a source, add those descriptions as comments to the given
|
||||
config before each field. This function only adds comments for the top-most config map level.
|
||||
Indent the comment the given number of characters.
|
||||
'''
|
||||
for index, field_name in enumerate(config.keys()):
|
||||
field_schema = schema['map'].get(field_name, {})
|
||||
description = field_schema.get('desc')
|
||||
|
||||
# No description to use? Skip it.
|
||||
if not field_schema or not description:
|
||||
continue
|
||||
|
||||
config.yaml_set_comment_before_after_key(key=field_name, before=description, indent=indent)
|
||||
if index > 0:
|
||||
_insert_newline_before_comment(config, field_name)
|
||||
|
||||
|
||||
def generate_sample_configuration(config_filename, schema_filename):
|
||||
'''
|
||||
Given a target config filename and the path to a schema filename in pykwalify YAML schema
|
||||
format, write out a sample configuration file based on that schema.
|
||||
'''
|
||||
schema = yaml.round_trip_load(open(schema_filename))
|
||||
config = _schema_to_sample_configuration(schema)
|
||||
|
||||
write_configuration(
|
||||
config_filename, _comment_out_optional_configuration(_render_configuration(config))
|
||||
)
|
||||
|
|
@ -1,12 +1,5 @@
|
|||
from collections import OrderedDict, namedtuple
|
||||
|
||||
try:
|
||||
# Python 2
|
||||
from ConfigParser import RawConfigParser
|
||||
except ImportError:
|
||||
# Python 3
|
||||
from configparser import RawConfigParser
|
||||
|
||||
from configparser import RawConfigParser
|
||||
|
||||
Section_format = namedtuple('Section_format', ('name', 'options'))
|
||||
Config_option = namedtuple('Config_option', ('name', 'value_type', 'required'))
|
||||
|
|
@ -51,12 +44,8 @@ CONFIG_FORMAT = (
|
|||
),
|
||||
),
|
||||
Section_format(
|
||||
'consistency',
|
||||
(
|
||||
option('checks', required=False),
|
||||
option('check_last', required=False),
|
||||
),
|
||||
)
|
||||
'consistency', (option('checks', required=False), option('check_last', required=False))
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -72,7 +61,8 @@ def validate_configuration_format(parser, config_format):
|
|||
'''
|
||||
section_names = set(parser.sections())
|
||||
required_section_names = tuple(
|
||||
section.name for section in config_format
|
||||
section.name
|
||||
for section in config_format
|
||||
if any(option.required for option in section.options)
|
||||
)
|
||||
|
||||
|
|
@ -86,9 +76,7 @@ def validate_configuration_format(parser, config_format):
|
|||
|
||||
missing_section_names = set(required_section_names) - section_names
|
||||
if missing_section_names:
|
||||
raise ValueError(
|
||||
'Missing config sections: {}'.format(', '.join(missing_section_names))
|
||||
)
|
||||
raise ValueError('Missing config sections: {}'.format(', '.join(missing_section_names)))
|
||||
|
||||
for section_format in config_format:
|
||||
if section_format.name not in section_names:
|
||||
|
|
@ -97,26 +85,28 @@ def validate_configuration_format(parser, config_format):
|
|||
option_names = parser.options(section_format.name)
|
||||
expected_options = section_format.options
|
||||
|
||||
unexpected_option_names = set(option_names) - set(option.name for option in expected_options)
|
||||
unexpected_option_names = set(option_names) - set(
|
||||
option.name for option in expected_options
|
||||
)
|
||||
|
||||
if unexpected_option_names:
|
||||
raise ValueError(
|
||||
'Unexpected options found in config section {}: {}'.format(
|
||||
section_format.name,
|
||||
', '.join(sorted(unexpected_option_names)),
|
||||
section_format.name, ', '.join(sorted(unexpected_option_names))
|
||||
)
|
||||
)
|
||||
|
||||
missing_option_names = tuple(
|
||||
option.name for option in expected_options if option.required
|
||||
option.name
|
||||
for option in expected_options
|
||||
if option.required
|
||||
if option.name not in option_names
|
||||
)
|
||||
|
||||
if missing_option_names:
|
||||
raise ValueError(
|
||||
'Required options missing from config section {}: {}'.format(
|
||||
section_format.name,
|
||||
', '.join(missing_option_names)
|
||||
section_format.name, ', '.join(missing_option_names)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -129,11 +119,7 @@ def parse_section_options(parser, section_format):
|
|||
|
||||
Raise ValueError if any option values cannot be coerced to the expected Python data type.
|
||||
'''
|
||||
type_getter = {
|
||||
str: parser.get,
|
||||
int: parser.getint,
|
||||
bool: parser.getboolean,
|
||||
}
|
||||
type_getter = {str: parser.get, int: parser.getint, bool: parser.getboolean}
|
||||
|
||||
return OrderedDict(
|
||||
(option.name, type_getter[option.value_type](section_format.name, option.name))
|
||||
|
|
@ -157,11 +143,10 @@ def parse_configuration(config_filename, config_format):
|
|||
|
||||
# Describes a parsed configuration, where each attribute is the name of a configuration file
|
||||
# section and each value is a dict of that section's parsed options.
|
||||
Parsed_config = namedtuple('Parsed_config', (section_format.name for section_format in config_format))
|
||||
Parsed_config = namedtuple(
|
||||
'Parsed_config', (section_format.name for section_format in config_format)
|
||||
)
|
||||
|
||||
return Parsed_config(
|
||||
*(
|
||||
parse_section_options(parser, section_format)
|
||||
for section_format in config_format
|
||||
)
|
||||
*(parse_section_options(parser, section_format) for section_format in config_format)
|
||||
)
|
||||
59
borgmatic/config/load.py
Normal file
59
borgmatic/config/load.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
import ruamel.yaml
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def load_configuration(filename):
|
||||
'''
|
||||
Load the given configuration file and return its contents as a data structure of nested dicts
|
||||
and lists.
|
||||
|
||||
Raise ruamel.yaml.error.YAMLError if something goes wrong parsing the YAML, or RecursionError
|
||||
if there are too many recursive includes.
|
||||
'''
|
||||
yaml = ruamel.yaml.YAML(typ='safe')
|
||||
yaml.Constructor = Include_constructor
|
||||
|
||||
return yaml.load(open(filename))
|
||||
|
||||
|
||||
def include_configuration(loader, filename_node):
|
||||
'''
|
||||
Load the given YAML filename (ignoring the given loader so we can use our own), and return its
|
||||
contents as a data structure of nested dicts and lists.
|
||||
'''
|
||||
return load_configuration(os.path.expanduser(filename_node.value))
|
||||
|
||||
|
||||
class Include_constructor(ruamel.yaml.SafeConstructor):
|
||||
'''
|
||||
A YAML "constructor" (a ruamel.yaml concept) that supports a custom "!include" tag for including
|
||||
separate YAML configuration files. Example syntax: `retention: !include common.yaml`
|
||||
'''
|
||||
|
||||
def __init__(self, preserve_quotes=None, loader=None):
|
||||
super(Include_constructor, self).__init__(preserve_quotes, loader)
|
||||
self.add_constructor('!include', include_configuration)
|
||||
|
||||
def flatten_mapping(self, node):
|
||||
'''
|
||||
Support the special case of shallow merging included configuration into an existing mapping
|
||||
using the YAML '<<' merge key. Example syntax:
|
||||
|
||||
```
|
||||
retention:
|
||||
keep_daily: 1
|
||||
<<: !include common.yaml
|
||||
```
|
||||
'''
|
||||
representer = ruamel.yaml.representer.SafeRepresenter()
|
||||
|
||||
for index, (key_node, value_node) in enumerate(node.value):
|
||||
if key_node.tag == u'tag:yaml.org,2002:merge' and value_node.tag == '!include':
|
||||
included_value = representer.represent_data(self.construct_object(value_node))
|
||||
node.value[index] = (key_node, included_value)
|
||||
|
||||
super(Include_constructor, self).flatten_mapping(node)
|
||||
368
borgmatic/config/schema.yaml
Normal file
368
borgmatic/config/schema.yaml
Normal file
|
|
@ -0,0 +1,368 @@
|
|||
name: Borgmatic configuration file schema
|
||||
version: 1
|
||||
map:
|
||||
location:
|
||||
desc: |
|
||||
Where to look for files to backup, and where to store those backups. See
|
||||
https://borgbackup.readthedocs.io/en/stable/quickstart.html and
|
||||
https://borgbackup.readthedocs.io/en/stable/usage.html#borg-create for details.
|
||||
required: true
|
||||
map:
|
||||
source_directories:
|
||||
required: true
|
||||
seq:
|
||||
- type: str
|
||||
desc: |
|
||||
List of source directories to backup (required). Globs and tildes are expanded.
|
||||
example:
|
||||
- /home
|
||||
- /etc
|
||||
- /var/log/syslog*
|
||||
repositories:
|
||||
required: true
|
||||
seq:
|
||||
- type: str
|
||||
desc: |
|
||||
Paths to local or remote repositories (required). Tildes are expanded. Multiple
|
||||
repositories are backed up to in sequence. See ssh_command for SSH options like
|
||||
identity file or port.
|
||||
example:
|
||||
- user@backupserver:sourcehostname.borg
|
||||
one_file_system:
|
||||
type: bool
|
||||
desc: Stay in same file system (do not cross mount points). Defaults to false.
|
||||
example: true
|
||||
numeric_owner:
|
||||
type: bool
|
||||
desc: Only store/extract numeric user and group identifiers. Defaults to false.
|
||||
example: true
|
||||
atime:
|
||||
type: bool
|
||||
desc: Store atime into archive. Defaults to true.
|
||||
example: false
|
||||
ctime:
|
||||
type: bool
|
||||
desc: Store ctime into archive. Defaults to true.
|
||||
example: false
|
||||
birthtime:
|
||||
type: bool
|
||||
desc: Store birthtime (creation date) into archive. Defaults to true.
|
||||
example: false
|
||||
read_special:
|
||||
type: bool
|
||||
desc: |
|
||||
Use Borg's --read-special flag to allow backup of block and other special
|
||||
devices. Use with caution, as it will lead to problems if used when
|
||||
backing up special devices such as /dev/zero. Defaults to false.
|
||||
example: false
|
||||
bsd_flags:
|
||||
type: bool
|
||||
desc: Record bsdflags (e.g. NODUMP, IMMUTABLE) in archive. Defaults to true.
|
||||
example: true
|
||||
files_cache:
|
||||
type: str
|
||||
desc: |
|
||||
Mode in which to operate the files cache. See
|
||||
https://borgbackup.readthedocs.io/en/stable/usage/create.html#description for
|
||||
details. Defaults to "ctime,size,inode".
|
||||
example: ctime,size,inode
|
||||
local_path:
|
||||
type: str
|
||||
desc: Alternate Borg local executable. Defaults to "borg".
|
||||
example: borg1
|
||||
remote_path:
|
||||
type: str
|
||||
desc: Alternate Borg remote executable. Defaults to "borg".
|
||||
example: borg1
|
||||
patterns:
|
||||
seq:
|
||||
- type: str
|
||||
desc: |
|
||||
Any paths matching these patterns are included/excluded from backups. Globs are
|
||||
expanded. (Tildes are not.) Note that Borg considers this option experimental.
|
||||
See the output of "borg help patterns" for more details. Quote any value if it
|
||||
contains leading punctuation, so it parses correctly.
|
||||
example:
|
||||
- 'R /'
|
||||
- '- /home/*/.cache'
|
||||
- '+ /home/susan'
|
||||
- '- /home/*'
|
||||
patterns_from:
|
||||
seq:
|
||||
- type: str
|
||||
desc: |
|
||||
Read include/exclude patterns from one or more separate named files, one pattern
|
||||
per line. Note that Borg considers this option experimental. See the output of
|
||||
"borg help patterns" for more details.
|
||||
example:
|
||||
- /etc/borgmatic/patterns
|
||||
exclude_patterns:
|
||||
seq:
|
||||
- type: str
|
||||
desc: |
|
||||
Any paths matching these patterns are excluded from backups. Globs and tildes
|
||||
are expanded. See the output of "borg help patterns" for more details.
|
||||
example:
|
||||
- '*.pyc'
|
||||
- ~/*/.cache
|
||||
- /etc/ssl
|
||||
exclude_from:
|
||||
seq:
|
||||
- type: str
|
||||
desc: |
|
||||
Read exclude patterns from one or more separate named files, one pattern per
|
||||
line. See the output of "borg help patterns" for more details.
|
||||
example:
|
||||
- /etc/borgmatic/excludes
|
||||
exclude_caches:
|
||||
type: bool
|
||||
desc: |
|
||||
Exclude directories that contain a CACHEDIR.TAG file. See
|
||||
http://www.brynosaurus.com/cachedir/spec.html for details. Defaults to false.
|
||||
example: true
|
||||
exclude_if_present:
|
||||
type: str
|
||||
desc: |
|
||||
Exclude directories that contain a file with the given filename. Defaults to not
|
||||
set.
|
||||
example: .nobackup
|
||||
storage:
|
||||
desc: |
|
||||
Repository storage options. See
|
||||
https://borgbackup.readthedocs.io/en/stable/usage.html#borg-create and
|
||||
https://borgbackup.readthedocs.io/en/stable/usage/general.html#environment-variables for
|
||||
details.
|
||||
map:
|
||||
encryption_passcommand:
|
||||
type: str
|
||||
desc: |
|
||||
The standard output of this command is used to unlock the encryption key. Only
|
||||
use on repositories that were initialized with passcommand/repokey encryption.
|
||||
Note that if both encryption_passcommand and encryption_passphrase are set,
|
||||
then encryption_passphrase takes precedence. Defaults to not set.
|
||||
example: "secret-tool lookup borg-repository repo-name"
|
||||
encryption_passphrase:
|
||||
type: str
|
||||
desc: |
|
||||
Passphrase to unlock the encryption key with. Only use on repositories that were
|
||||
initialized with passphrase/repokey encryption. Quote the value if it contains
|
||||
punctuation, so it parses correctly. And backslash any quote or backslash
|
||||
literals as well. Defaults to not set.
|
||||
example: "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
|
||||
checkpoint_interval:
|
||||
type: int
|
||||
desc: |
|
||||
Number of seconds between each checkpoint during a long-running backup. See
|
||||
https://borgbackup.readthedocs.io/en/stable/faq.html#if-a-backup-stops-mid-way-does-the-already-backed-up-data-stay-there
|
||||
for details. Defaults to checkpoints every 1800 seconds (30 minutes).
|
||||
example: 1800
|
||||
chunker_params:
|
||||
type: str
|
||||
desc: |
|
||||
Specify the parameters passed to then chunker (CHUNK_MIN_EXP, CHUNK_MAX_EXP,
|
||||
HASH_MASK_BITS, HASH_WINDOW_SIZE). See https://borgbackup.readthedocs.io/en/stable/internals.html
|
||||
for details. Defaults to "19,23,21,4095".
|
||||
example: 19,23,21,4095
|
||||
compression:
|
||||
type: str
|
||||
desc: |
|
||||
Type of compression to use when creating archives. See
|
||||
https://borgbackup.readthedocs.org/en/stable/usage.html#borg-create for details.
|
||||
Defaults to "lz4".
|
||||
example: lz4
|
||||
remote_rate_limit:
|
||||
type: int
|
||||
desc: Remote network upload rate limit in kiBytes/second. Defaults to unlimited.
|
||||
example: 100
|
||||
ssh_command:
|
||||
type: str
|
||||
desc: |
|
||||
Command to use instead of "ssh". This can be used to specify ssh options.
|
||||
Defaults to not set.
|
||||
example: ssh -i /path/to/private/key
|
||||
borg_base_directory:
|
||||
type: str
|
||||
desc: |
|
||||
Base path used for various Borg directories. Defaults to $HOME, ~$USER, or ~.
|
||||
See https://borgbackup.readthedocs.io/en/stable/usage/general.html#environment-variables for details.
|
||||
example: /path/to/base
|
||||
borg_config_directory:
|
||||
type: str
|
||||
desc: |
|
||||
Path for Borg configuration files. Defaults to $borg_base_directory/.config/borg
|
||||
example: /path/to/base/config
|
||||
borg_cache_directory:
|
||||
type: str
|
||||
desc: |
|
||||
Path for Borg cache files. Defaults to $borg_base_directory/.cache/borg
|
||||
example: /path/to/base/cache
|
||||
borg_security_directory:
|
||||
type: str
|
||||
desc: |
|
||||
Path for Borg security and encryption nonce files. Defaults to $borg_base_directory/.config/borg/security
|
||||
example: /path/to/base/config/security
|
||||
borg_keys_directory:
|
||||
type: str
|
||||
desc: |
|
||||
Path for Borg encryption key files. Defaults to $borg_base_directory/.config/borg/keys
|
||||
example: /path/to/base/config/keys
|
||||
umask:
|
||||
type: scalar
|
||||
desc: Umask to be used for borg create. Defaults to 0077.
|
||||
example: 0077
|
||||
lock_wait:
|
||||
type: int
|
||||
desc: Maximum seconds to wait for acquiring a repository/cache lock. Defaults to 1.
|
||||
example: 5
|
||||
archive_name_format:
|
||||
type: str
|
||||
desc: |
|
||||
Name of the archive. Borg placeholders can be used. See the output of
|
||||
"borg help placeholders" for details. Defaults to
|
||||
"{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}". If you specify this option, you must
|
||||
also specify a prefix in the retention section to avoid accidental pruning of
|
||||
archives with a different archive name format. And you should also specify a
|
||||
prefix in the consistency section as well.
|
||||
example: "{hostname}-documents-{now}"
|
||||
relocated_repo_access_is_ok:
|
||||
type: bool
|
||||
desc: Bypass Borg error about a repository that has been moved. Defaults to false.
|
||||
example: true
|
||||
unknown_unencrypted_repo_access_is_ok:
|
||||
type: bool
|
||||
desc: |
|
||||
Bypass Borg error about a previously unknown unencrypted repository. Defaults to
|
||||
false.
|
||||
example: true
|
||||
retention:
|
||||
desc: |
|
||||
Retention policy for how many backups to keep in each category. See
|
||||
https://borgbackup.readthedocs.org/en/stable/usage.html#borg-prune for details.
|
||||
At least one of the "keep" options is required for pruning to work. See
|
||||
https://torsion.org/borgmatic/docs/how-to/deal-with-very-large-backups/
|
||||
if you'd like to skip pruning entirely.
|
||||
map:
|
||||
keep_within:
|
||||
type: str
|
||||
desc: Keep all archives within this time interval.
|
||||
example: 3H
|
||||
keep_secondly:
|
||||
type: int
|
||||
desc: Number of secondly archives to keep.
|
||||
example: 60
|
||||
keep_minutely:
|
||||
type: int
|
||||
desc: Number of minutely archives to keep.
|
||||
example: 60
|
||||
keep_hourly:
|
||||
type: int
|
||||
desc: Number of hourly archives to keep.
|
||||
example: 24
|
||||
keep_daily:
|
||||
type: int
|
||||
desc: Number of daily archives to keep.
|
||||
example: 7
|
||||
keep_weekly:
|
||||
type: int
|
||||
desc: Number of weekly archives to keep.
|
||||
example: 4
|
||||
keep_monthly:
|
||||
type: int
|
||||
desc: Number of monthly archives to keep.
|
||||
example: 6
|
||||
keep_yearly:
|
||||
type: int
|
||||
desc: Number of yearly archives to keep.
|
||||
example: 1
|
||||
prefix:
|
||||
type: str
|
||||
desc: |
|
||||
When pruning, only consider archive names starting with this prefix.
|
||||
Borg placeholders can be used. See the output of "borg help placeholders" for
|
||||
details. Defaults to "{hostname}-". Use an empty value to disable the default.
|
||||
example: sourcehostname
|
||||
consistency:
|
||||
desc: |
|
||||
Consistency checks to run after backups. See
|
||||
https://borgbackup.readthedocs.org/en/stable/usage.html#borg-check and
|
||||
https://borgbackup.readthedocs.org/en/stable/usage.html#borg-extract for details.
|
||||
map:
|
||||
checks:
|
||||
seq:
|
||||
- type: str
|
||||
enum: ['repository', 'archives', 'data', 'extract', 'disabled']
|
||||
unique: true
|
||||
desc: |
|
||||
List of one or more consistency checks to run: "repository", "archives", "data",
|
||||
and/or "extract". Defaults to "repository" and "archives". Set to "disabled" to
|
||||
disable all consistency checks. "repository" checks the consistency of the
|
||||
repository, "archives" checks all of the archives, "data" verifies the integrity
|
||||
of the data within the archives, and "extract" does an extraction dry-run of the
|
||||
most recent archive. Note that "data" implies "archives".
|
||||
example:
|
||||
- repository
|
||||
- archives
|
||||
check_repositories:
|
||||
seq:
|
||||
- type: str
|
||||
desc: |
|
||||
Paths to a subset of the repositories in the location section on which to run
|
||||
consistency checks. Handy in case some of your repositories are very large, and
|
||||
so running consistency checks on them would take too long. Defaults to running
|
||||
consistency checks on all repositories configured in the location section.
|
||||
example:
|
||||
- user@backupserver:sourcehostname.borg
|
||||
check_last:
|
||||
type: int
|
||||
desc: Restrict the number of checked archives to the last n. Applies only to the
|
||||
"archives" check. Defaults to checking all archives.
|
||||
example: 3
|
||||
prefix:
|
||||
type: str
|
||||
desc: |
|
||||
When performing the "archives" check, only consider archive names starting with
|
||||
this prefix. Borg placeholders can be used. See the output of
|
||||
"borg help placeholders" for details. Defaults to "{hostname}-". Use an empty
|
||||
value to disable the default.
|
||||
example: sourcehostname
|
||||
output:
|
||||
desc: |
|
||||
Options for customizing borgmatic's own output and logging.
|
||||
map:
|
||||
color:
|
||||
type: bool
|
||||
desc: |
|
||||
Apply color to console output. Can be overridden with --no-color command-line
|
||||
flag. Defaults to true.
|
||||
example: false
|
||||
hooks:
|
||||
desc: |
|
||||
Shell commands or scripts to execute before and after a backup or if an error has occurred.
|
||||
IMPORTANT: All provided commands and scripts are executed with user permissions of borgmatic.
|
||||
Do not forget to set secure permissions on this file as well as on any script listed (chmod 0700) to
|
||||
prevent potential shell injection or privilege escalation.
|
||||
map:
|
||||
before_backup:
|
||||
seq:
|
||||
- type: str
|
||||
desc: List of one or more shell commands or scripts to execute before creating a backup.
|
||||
example:
|
||||
- echo "Starting a backup job."
|
||||
after_backup:
|
||||
seq:
|
||||
- type: str
|
||||
desc: List of one or more shell commands or scripts to execute after creating a backup.
|
||||
example:
|
||||
- echo "Backup created."
|
||||
on_error:
|
||||
seq:
|
||||
- type: str
|
||||
desc: |
|
||||
List of one or more shell commands or scripts to execute when an exception occurs
|
||||
during a backup or when running a hook.
|
||||
example:
|
||||
- echo "Error while creating a backup or running a hook."
|
||||
umask:
|
||||
type: scalar
|
||||
desc: Umask used when executing hooks. Defaults to the umask that borgmatic is run with.
|
||||
example: 0077
|
||||
144
borgmatic/config/validate.py
Normal file
144
borgmatic/config/validate.py
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
import logging
|
||||
|
||||
import pkg_resources
|
||||
import pykwalify.core
|
||||
import pykwalify.errors
|
||||
import ruamel.yaml
|
||||
|
||||
from borgmatic.config import load
|
||||
|
||||
|
||||
def schema_filename():
|
||||
'''
|
||||
Path to the installed YAML configuration schema file, used to validate and parse the
|
||||
configuration.
|
||||
'''
|
||||
return pkg_resources.resource_filename('borgmatic', 'config/schema.yaml')
|
||||
|
||||
|
||||
class Validation_error(ValueError):
|
||||
'''
|
||||
A collection of error message strings generated when attempting to validate a particular
|
||||
configurartion file.
|
||||
'''
|
||||
|
||||
def __init__(self, config_filename, error_messages):
|
||||
self.config_filename = config_filename
|
||||
self.error_messages = error_messages
|
||||
|
||||
def __str__(self):
|
||||
'''
|
||||
Render a validation error as a user-facing string.
|
||||
'''
|
||||
return 'An error occurred while parsing a configuration file at {}:\n'.format(
|
||||
self.config_filename
|
||||
) + '\n'.join(self.error_messages)
|
||||
|
||||
|
||||
def apply_logical_validation(config_filename, parsed_configuration):
|
||||
'''
|
||||
Given a parsed and schematically valid configuration as a data structure of nested dicts (see
|
||||
below), run through any additional logical validation checks. If there are any such validation
|
||||
problems, raise a Validation_error.
|
||||
'''
|
||||
archive_name_format = parsed_configuration.get('storage', {}).get('archive_name_format')
|
||||
prefix = parsed_configuration.get('retention', {}).get('prefix')
|
||||
|
||||
if archive_name_format and not prefix:
|
||||
raise Validation_error(
|
||||
config_filename,
|
||||
('If you provide an archive_name_format, you must also specify a retention prefix.',),
|
||||
)
|
||||
|
||||
location_repositories = parsed_configuration.get('location', {}).get('repositories')
|
||||
check_repositories = parsed_configuration.get('consistency', {}).get('check_repositories', [])
|
||||
for repository in check_repositories:
|
||||
if repository not in location_repositories:
|
||||
raise Validation_error(
|
||||
config_filename,
|
||||
(
|
||||
'Unknown repository in the consistency section\'s check_repositories: {}'.format(
|
||||
repository
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def parse_configuration(config_filename, schema_filename):
|
||||
'''
|
||||
Given the path to a config filename in YAML format and the path to a schema filename in
|
||||
pykwalify YAML schema format, return the parsed configuration as a data structure of nested
|
||||
dicts and lists corresponding to the schema. Example return value:
|
||||
|
||||
{'location': {'source_directories': ['/home', '/etc'], 'repository': 'hostname.borg'},
|
||||
'retention': {'keep_daily': 7}, 'consistency': {'checks': ['repository', 'archives']}}
|
||||
|
||||
Raise FileNotFoundError if the file does not exist, PermissionError if the user does not
|
||||
have permissions to read the file, or Validation_error if the config does not match the schema.
|
||||
'''
|
||||
logging.getLogger('pykwalify').setLevel(logging.ERROR)
|
||||
|
||||
try:
|
||||
config = load.load_configuration(config_filename)
|
||||
schema = load.load_configuration(schema_filename)
|
||||
except (ruamel.yaml.error.YAMLError, RecursionError) as error:
|
||||
raise Validation_error(config_filename, (str(error),))
|
||||
|
||||
# pykwalify gets angry if the example field is not a string. So rather than bend to its will,
|
||||
# remove all examples before passing the schema to pykwalify.
|
||||
for section_name, section_schema in schema['map'].items():
|
||||
for field_name, field_schema in section_schema['map'].items():
|
||||
field_schema.pop('example', None)
|
||||
|
||||
validator = pykwalify.core.Core(source_data=config, schema_data=schema)
|
||||
parsed_result = validator.validate(raise_exception=False)
|
||||
|
||||
if validator.validation_errors:
|
||||
raise Validation_error(config_filename, validator.validation_errors)
|
||||
|
||||
apply_logical_validation(config_filename, parsed_result)
|
||||
|
||||
return parsed_result
|
||||
|
||||
|
||||
def guard_configuration_contains_repository(repository, configurations):
|
||||
'''
|
||||
Given a repository path and a dict mapping from config filename to corresponding parsed config
|
||||
dict, ensure that the repository is declared exactly once in all of the configurations.
|
||||
|
||||
If no repository is given, then error if there are multiple configured repositories.
|
||||
|
||||
Raise ValueError if the repository is not found in a configuration, or is declared multiple
|
||||
times.
|
||||
'''
|
||||
if not repository:
|
||||
count = len(
|
||||
tuple(
|
||||
config_repository
|
||||
for config in configurations.values()
|
||||
for config_repository in config['location']['repositories']
|
||||
)
|
||||
)
|
||||
|
||||
if count > 1:
|
||||
raise ValueError(
|
||||
'Can\'t determine which repository to use. Use --repository option to disambiguate'.format(
|
||||
repository
|
||||
)
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
count = len(
|
||||
tuple(
|
||||
config_repository
|
||||
for config in configurations.values()
|
||||
for config_repository in config['location']['repositories']
|
||||
if repository == config_repository
|
||||
)
|
||||
)
|
||||
|
||||
if count == 0:
|
||||
raise ValueError('Repository {} not found in configuration files'.format(repository))
|
||||
if count > 1:
|
||||
raise ValueError('Repository {} found in multiple configuration files'.format(repository))
|
||||
78
borgmatic/execute.py
Normal file
78
borgmatic/execute.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import logging
|
||||
import subprocess
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
ERROR_OUTPUT_MAX_LINE_COUNT = 25
|
||||
BORG_ERROR_EXIT_CODE = 2
|
||||
|
||||
|
||||
def execute_and_log_output(full_command, output_log_level, shell):
|
||||
last_lines = []
|
||||
process = subprocess.Popen(
|
||||
full_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell
|
||||
)
|
||||
|
||||
while process.poll() is None:
|
||||
line = process.stdout.readline().rstrip().decode()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
# Keep the last few lines of output in case the command errors, and we need the output for
|
||||
# the exception below.
|
||||
last_lines.append(line)
|
||||
if len(last_lines) > ERROR_OUTPUT_MAX_LINE_COUNT:
|
||||
last_lines.pop(0)
|
||||
|
||||
logger.log(output_log_level, line)
|
||||
|
||||
remaining_output = process.stdout.read().rstrip().decode()
|
||||
if remaining_output: # pragma: no cover
|
||||
logger.log(output_log_level, remaining_output)
|
||||
|
||||
exit_code = process.poll()
|
||||
|
||||
# If shell is True, assume we're running something other than Borg and should treat all non-zero
|
||||
# exit codes as errors.
|
||||
error = bool(exit_code != 0) if shell else bool(exit_code >= BORG_ERROR_EXIT_CODE)
|
||||
|
||||
if error:
|
||||
# If an error occurs, include its output in the raised exception so that we don't
|
||||
# inadvertently hide error output.
|
||||
if len(last_lines) == ERROR_OUTPUT_MAX_LINE_COUNT:
|
||||
last_lines.insert(0, '...')
|
||||
|
||||
raise subprocess.CalledProcessError(
|
||||
exit_code, ' '.join(full_command), '\n'.join(last_lines)
|
||||
)
|
||||
|
||||
|
||||
def execute_command(full_command, output_log_level=logging.INFO, shell=False):
|
||||
'''
|
||||
Execute the given command (a sequence of command/argument strings) and log its output at the
|
||||
given log level. If output log level is None, instead capture and return the output. If
|
||||
shell is True, execute the command within a shell.
|
||||
'''
|
||||
logger.debug(' '.join(full_command))
|
||||
|
||||
if output_log_level is None:
|
||||
output = subprocess.check_output(full_command, shell=shell)
|
||||
return output.decode() if output is not None else None
|
||||
else:
|
||||
execute_and_log_output(full_command, output_log_level, shell=shell)
|
||||
|
||||
|
||||
def execute_command_without_capture(full_command):
|
||||
'''
|
||||
Execute the given command (a sequence of command/argument strings), but don't capture or log its
|
||||
output in any way. This is necessary for commands that monkey with the terminal (e.g. progress
|
||||
display) or provide interactive prompts.
|
||||
'''
|
||||
logger.debug(' '.join(full_command))
|
||||
|
||||
try:
|
||||
subprocess.check_call(full_command)
|
||||
except subprocess.CalledProcessError as error:
|
||||
if error.returncode >= BORG_ERROR_EXIT_CODE:
|
||||
raise
|
||||
53
borgmatic/hook.py
Normal file
53
borgmatic/hook.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
from borgmatic import execute
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def execute_hook(commands, umask, config_filename, description, dry_run):
|
||||
'''
|
||||
Given a list of hook commands to execute, a umask to execute with (or None), a config filename,
|
||||
a hook description, and whether this is a dry run, run the given commands. Or, don't run them
|
||||
if this is a dry run.
|
||||
|
||||
Raise ValueError if the umask cannot be parsed.
|
||||
'''
|
||||
if not commands:
|
||||
logger.debug('{}: No commands to run for {} hook'.format(config_filename, description))
|
||||
return
|
||||
|
||||
dry_run_label = ' (dry run; not actually running hooks)' if dry_run else ''
|
||||
|
||||
if len(commands) == 1:
|
||||
logger.info(
|
||||
'{}: Running command for {} hook{}'.format(config_filename, description, dry_run_label)
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
'{}: Running {} commands for {} hook{}'.format(
|
||||
config_filename, len(commands), description, dry_run_label
|
||||
)
|
||||
)
|
||||
|
||||
if umask:
|
||||
parsed_umask = int(str(umask), 8)
|
||||
logger.debug('{}: Set hook umask to {}'.format(config_filename, oct(parsed_umask)))
|
||||
original_umask = os.umask(parsed_umask)
|
||||
else:
|
||||
original_umask = None
|
||||
|
||||
try:
|
||||
for command in commands:
|
||||
if not dry_run:
|
||||
execute.execute_command(
|
||||
[command],
|
||||
output_log_level=logging.ERROR
|
||||
if description == 'on-error'
|
||||
else logging.WARNING,
|
||||
shell=True,
|
||||
)
|
||||
finally:
|
||||
if original_umask:
|
||||
os.umask(original_umask)
|
||||
101
borgmatic/logger.py
Normal file
101
borgmatic/logger.py
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import colorama
|
||||
|
||||
|
||||
def to_bool(arg):
|
||||
'''
|
||||
Return a boolean value based on `arg`.
|
||||
'''
|
||||
if arg is None or isinstance(arg, bool):
|
||||
return arg
|
||||
|
||||
if isinstance(arg, str):
|
||||
arg = arg.lower()
|
||||
|
||||
if arg in ('yes', 'on', '1', 'true', 1):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def interactive_console():
|
||||
'''
|
||||
Return whether the current console is "interactive". Meaning: Capable of
|
||||
user input and not just something like a cron job.
|
||||
'''
|
||||
return sys.stdout.isatty() and os.environ.get('TERM') != 'dumb'
|
||||
|
||||
|
||||
def should_do_markup(no_color, configs):
|
||||
'''
|
||||
Given the value of the command-line no-color argument, and a dict of configuration filename to
|
||||
corresponding parsed configuration, determine if we should enable colorama marking up.
|
||||
'''
|
||||
if no_color:
|
||||
return False
|
||||
|
||||
if any(config.get('output', {}).get('color') is False for config in configs.values()):
|
||||
return False
|
||||
|
||||
py_colors = os.environ.get('PY_COLORS', None)
|
||||
|
||||
if py_colors is not None:
|
||||
return to_bool(py_colors)
|
||||
|
||||
return interactive_console()
|
||||
|
||||
|
||||
LOG_LEVEL_TO_COLOR = {
|
||||
logging.CRITICAL: colorama.Fore.RED,
|
||||
logging.ERROR: colorama.Fore.RED,
|
||||
logging.WARN: colorama.Fore.YELLOW,
|
||||
logging.INFO: colorama.Fore.GREEN,
|
||||
logging.DEBUG: colorama.Fore.CYAN,
|
||||
}
|
||||
|
||||
|
||||
class Console_color_formatter(logging.Formatter):
|
||||
def format(self, record):
|
||||
color = LOG_LEVEL_TO_COLOR.get(record.levelno)
|
||||
return color_text(color, record.msg)
|
||||
|
||||
|
||||
def color_text(color, message):
|
||||
'''
|
||||
Give colored text.
|
||||
'''
|
||||
if not color:
|
||||
return message
|
||||
|
||||
return '{}{}{}'.format(color, message, colorama.Style.RESET_ALL)
|
||||
|
||||
|
||||
def configure_logging(console_log_level, syslog_log_level=None):
|
||||
'''
|
||||
Configure logging to go to both the console and syslog. Use the given log levels, respectively.
|
||||
'''
|
||||
if syslog_log_level is None:
|
||||
syslog_log_level = console_log_level
|
||||
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setFormatter(Console_color_formatter())
|
||||
console_handler.setLevel(console_log_level)
|
||||
|
||||
syslog_path = None
|
||||
if os.path.exists('/dev/log'):
|
||||
syslog_path = '/dev/log'
|
||||
elif os.path.exists('/var/run/syslog'):
|
||||
syslog_path = '/var/run/syslog'
|
||||
|
||||
if syslog_path and not interactive_console():
|
||||
syslog_handler = logging.handlers.SysLogHandler(address=syslog_path)
|
||||
syslog_handler.setFormatter(logging.Formatter('borgmatic: %(levelname)s %(message)s'))
|
||||
syslog_handler.setLevel(syslog_log_level)
|
||||
handlers = (console_handler, syslog_handler)
|
||||
else:
|
||||
handlers = (console_handler,)
|
||||
|
||||
logging.basicConfig(level=min(console_log_level, syslog_log_level), handlers=handlers)
|
||||
18
borgmatic/signals.py
Normal file
18
borgmatic/signals.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import os
|
||||
import signal
|
||||
|
||||
|
||||
def _handle_signal(signal_number, frame): # pragma: no cover
|
||||
'''
|
||||
Send the signal to all processes in borgmatic's process group, which includes child process.
|
||||
'''
|
||||
os.killpg(os.getpgrp(), signal_number)
|
||||
|
||||
|
||||
def configure_signals(): # pragma: no cover
|
||||
'''
|
||||
Configure borgmatic's signal handlers to pass relevant signals through to any child processes
|
||||
like Borg. Note that SIGINT gets passed through even without these changes.
|
||||
'''
|
||||
for signal_number in (signal.SIGHUP, signal.SIGTERM, signal.SIGUSR1, signal.SIGUSR2):
|
||||
signal.signal(signal_number, _handle_signal)
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
from flexmock import flexmock
|
||||
import sys
|
||||
|
||||
|
||||
def builtins_mock():
|
||||
try:
|
||||
# Python 2
|
||||
return flexmock(sys.modules['__builtin__'])
|
||||
except KeyError:
|
||||
# Python 3
|
||||
return flexmock(sys.modules['builtins'])
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
from flexmock import flexmock
|
||||
import pytest
|
||||
|
||||
from borgmatic import command as module
|
||||
|
||||
|
||||
def test_parse_arguments_with_no_arguments_uses_defaults():
|
||||
flexmock(os.path).should_receive('exists').and_return(True)
|
||||
|
||||
parser = module.parse_arguments()
|
||||
|
||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
||||
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME
|
||||
assert parser.verbosity == None
|
||||
|
||||
|
||||
def test_parse_arguments_with_filename_arguments_overrides_defaults():
|
||||
flexmock(os.path).should_receive('exists').and_return(True)
|
||||
|
||||
parser = module.parse_arguments('--config', 'myconfig', '--excludes', 'myexcludes')
|
||||
|
||||
assert parser.config_filename == 'myconfig'
|
||||
assert parser.excludes_filename == 'myexcludes'
|
||||
assert parser.verbosity == None
|
||||
|
||||
|
||||
def test_parse_arguments_with_missing_default_excludes_file_sets_filename_to_none():
|
||||
flexmock(os.path).should_receive('exists').and_return(False)
|
||||
|
||||
parser = module.parse_arguments()
|
||||
|
||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
||||
assert parser.excludes_filename == None
|
||||
assert parser.verbosity == None
|
||||
|
||||
|
||||
def test_parse_arguments_with_missing_overridden_excludes_file_retains_filename():
|
||||
flexmock(os.path).should_receive('exists').and_return(False)
|
||||
|
||||
parser = module.parse_arguments('--excludes', 'myexcludes')
|
||||
|
||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
||||
assert parser.excludes_filename == 'myexcludes'
|
||||
assert parser.verbosity == None
|
||||
|
||||
|
||||
def test_parse_arguments_with_verbosity_flag_overrides_default():
|
||||
flexmock(os.path).should_receive('exists').and_return(True)
|
||||
|
||||
parser = module.parse_arguments('--verbosity', '1')
|
||||
|
||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
||||
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME
|
||||
assert parser.verbosity == 1
|
||||
|
||||
|
||||
def test_parse_arguments_with_invalid_arguments_exits():
|
||||
flexmock(os.path).should_receive('exists').and_return(True)
|
||||
original_stderr = sys.stderr
|
||||
sys.stderr = sys.stdout
|
||||
|
||||
try:
|
||||
with pytest.raises(SystemExit):
|
||||
module.parse_arguments('--posix-me-harder')
|
||||
finally:
|
||||
sys.stderr = original_stderr
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
try:
|
||||
# Python 2
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
# Python 3
|
||||
from io import StringIO
|
||||
|
||||
from collections import OrderedDict
|
||||
import string
|
||||
|
||||
from borgmatic import config as module
|
||||
|
||||
|
||||
def test_parse_section_options_with_punctuation_should_return_section_options():
|
||||
parser = module.RawConfigParser()
|
||||