mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-22 18:13:02 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
3967e1b5f0 | ||
|
|
8cbd51512b | ||
|
|
c38f7a3693 | ||
|
|
7c77a5a8a5 | ||
|
|
9caaee18b5 | ||
|
|
7c0407ed22 | ||
|
|
499f8aa0a4 | ||
|
|
548212274f | ||
|
|
1292dd2162 | ||
|
|
b02ac44cfc | ||
|
|
52963adfc9 | ||
|
|
2274cfe480 | ||
|
|
8cf52651fe | ||
|
|
166ef8faae | ||
|
|
ac2a63763f | ||
|
|
8b2b41eefc | ||
|
|
fb172f018a | ||
|
|
b1355e75c4 | ||
|
|
d2c143d39c | ||
|
|
ef32b292a8 | ||
|
|
61f88228b0 | ||
|
|
f98558546c | ||
|
|
9cc7c77ba9 | ||
|
|
3b1b058ffe | ||
|
|
9a3b52e1fd | ||
|
|
0dfc935af6 | ||
|
|
2f7527a333 | ||
|
|
263891f414 | ||
|
|
644c2e6612 | ||
|
|
999feb81ca | ||
|
|
f581f4b8d9 | ||
|
|
c7803a2814 | ||
|
|
f4e5dc8382 | ||
|
|
f19a40ef9c | ||
|
|
483bd50bdf | ||
|
|
5110e64e63 | ||
|
|
4d7556f68b | ||
|
|
9212f87735 | ||
|
|
ebd34f1695 | ||
|
|
a34dccbd27 | ||
|
|
49c4f483fd | ||
|
|
4447956da7 | ||
|
|
9a96a277e6 | ||
|
|
a45d7bec81 | ||
|
|
63c4bf3bf9 | ||
|
|
ed0127df91 | ||
|
|
17e9f21fb9 | ||
|
|
16cc77fd9d | ||
|
|
5d9bb13410 | ||
|
|
da513c1089 | ||
|
|
3579dbe813 | ||
|
|
8e3a2c7a85 | ||
|
|
706a31f189 | ||
|
|
e5c772d8a5 | ||
|
|
40a215802f | ||
|
|
5d46acbe41 | ||
|
|
9dc4960277 | ||
|
|
7644a38574 | ||
|
|
2359135327 | ||
|
|
df9cc6a7d2 | ||
|
|
448c2593ed | ||
|
|
a364369f25 | ||
|
|
e430b8c281 | ||
|
|
219408647c | ||
|
|
5bffa35741 | ||
|
|
a938a2ad61 | ||
|
|
37b6f043dd | ||
|
|
0c97dba5f1 | ||
|
|
f149fa4b4b | ||
|
|
f669e31305 | ||
|
|
dd2be365b1 | ||
|
|
d6585811d6 | ||
|
|
14a277a64f | ||
|
|
9723dbdd4c | ||
|
|
9f5c5c8e13 | ||
|
|
4453f41967 | ||
|
|
e4cf193cd7 | ||
|
|
e1605ae6ab | ||
|
|
d6ea9b6658 | ||
|
|
147996b234 | ||
|
|
ac374f89d2 | ||
|
|
ddde37ff59 | ||
|
|
278aaabeb9 | ||
|
|
06cdc2c46c | ||
|
|
e5586f7d87 | ||
|
|
d044504693 | ||
|
|
ec416cb152 | ||
|
|
0da1c6ec7b | ||
|
|
f54acc9bbf | ||
|
|
d86faa30d3 | ||
|
|
a44212ff00 | ||
|
|
178e56e77b | ||
|
|
1cb44da6b3 | ||
|
|
7e8123379f | ||
|
|
c554d1d36d | ||
|
|
a56529871c | ||
|
|
820492f9a9 | ||
|
|
f803198f14 | ||
|
|
f59bc98d79 | ||
|
|
158e889deb | ||
|
|
2444c4b372 | ||
|
|
9ecc207139 | ||
|
|
803fd3a851 | ||
|
|
e18cfd6c80 | ||
|
|
7a287ba289 | ||
|
|
3f99dc6db2 | ||
|
|
837d25cfd8 | ||
|
|
fedc75cafc | ||
|
|
29106b9645 | ||
|
|
4f6337c46e | ||
|
|
55183bf890 | ||
|
|
cc09d7fc10 | ||
|
|
96ce9309e0 | ||
|
|
f2f8503e77 | ||
|
|
bdce17ae71 | ||
|
|
b501a568aa | ||
|
|
1578b44536 | ||
|
|
932145f20b | ||
|
|
6c2e668262 | ||
|
|
df2d059af2 | ||
|
|
301eb4926e | ||
|
|
897046cf51 | ||
|
|
645c66c98a | ||
|
|
811678396a | ||
|
|
fd94debba6 | ||
|
|
851dd69785 | ||
|
|
6430e3799a | ||
|
|
c15a89b9f8 | ||
|
|
0bf033de06 | ||
|
|
5bc7c04cdf | ||
|
|
a5eda0d305 | ||
|
|
04216922c4 | ||
|
|
aa482d088c | ||
|
|
b755d09b0a | ||
|
|
89703111d0 | ||
|
|
0f21919626 | ||
|
|
e3fa18b892 | ||
|
|
6d4e40a819 | ||
|
|
de40570db4 | ||
|
|
2a45f43167 | ||
|
|
f8c6da6ff4 | ||
|
|
63018fad4e | ||
|
|
2038354b61 | ||
|
|
9d7db93655 | ||
|
|
f4d8469085 | ||
|
|
273ca83f6b | ||
|
|
41008b3ef4 | ||
|
|
16ba9ef4c6 | ||
|
|
25b78d6de4 | ||
|
|
d311e90792 | ||
|
|
0fc9acce7c | ||
|
|
5a3c66a667 | ||
|
|
f8387c7bd1 | ||
|
|
181fed83df | ||
|
|
243e2b698d | ||
|
|
f2f4ce38c9 | ||
|
|
965ec51171 | ||
|
|
cd11e89fde | ||
|
|
866c707f58 | ||
|
|
c459c42ffc | ||
|
|
0bca430c02 | ||
|
|
7b3efddcbd | ||
|
|
cdb4035bab | ||
|
|
c7d68246cd | ||
|
|
8784e19e45 | ||
|
|
48523810ec | ||
|
|
6dff335c8b |
@@ -1,6 +1,9 @@
|
||||
*.egg-info
|
||||
*.pyc
|
||||
*.swp
|
||||
.cache
|
||||
.coverage
|
||||
.pytest_cache
|
||||
.tox
|
||||
build
|
||||
dist
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
syntax: glob
|
||||
*.egg-info
|
||||
*.pyc
|
||||
*.swp
|
||||
.cache
|
||||
.coverage
|
||||
.tox
|
||||
build
|
||||
dist
|
||||
@@ -1,34 +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
|
||||
de2d7721cdec93a52d20222a9ddd579ed93c1017 1.0.1
|
||||
9603d13910b32d57a887765cab694ac5d0acc1f4 1.0.2
|
||||
32c6341dda9fad77a3982641bce8a3a45821842e 1.0.3
|
||||
5a003056a8ff4709c5bd4d6d33354199423f8a1d 1.1.0
|
||||
7d3d11eff6c0773883c48f221431f157bc7995eb 1.1.1
|
||||
@@ -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
|
||||
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
|
||||
Scott Squires: Custom archive names
|
||||
Thomas LÉVEIL: Support for a keep_minutely prune option. Support for the --json option
|
||||
|
||||
@@ -1,10 +1,138 @@
|
||||
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
|
||||
|
||||
* #32: Fix for passing check_last as integer to subprocess when calling Borg.
|
||||
* #33: Fix for passing check_last as integer to subprocess when calling Borg.
|
||||
|
||||
1.1.1
|
||||
|
||||
* Part of #32: Fix for upgrade-borgmatic-config converting check_last option as a string instead of
|
||||
* 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.
|
||||
|
||||
@@ -13,8 +141,8 @@
|
||||
* 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.
|
||||
* #18: Fix for README mention of sample files not included in package.
|
||||
* #22: Sample files for triggering borgmatic from a systemd timer.
|
||||
* #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.
|
||||
@@ -22,15 +150,15 @@
|
||||
|
||||
1.0.3
|
||||
|
||||
* #21: Fix for verbosity flag not actually causing verbose output.
|
||||
* #22: Fix for verbosity flag not actually causing verbose output.
|
||||
|
||||
1.0.2
|
||||
|
||||
* #20: Fix for traceback when remote_path option is missing.
|
||||
* #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
|
||||
@@ -52,13 +180,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
|
||||
|
||||
@@ -70,7 +198,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
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
---
|
||||
title: borgmatic
|
||||
|
||||
<img src="static/borgmatic.svg" alt="borgmatic logo" style="width: 8em; float: right; padding-left: 1em;" />
|
||||
|
||||
permalink: borgmatic/index.html
|
||||
---
|
||||
## 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" width="150px" style="float: right; padding-left: 1em;">
|
||||
|
||||
borgmatic is a simple Python wrapper script for the
|
||||
[Borg](https://www.borgbackup.org/) 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.
|
||||
|
||||
Here's an example config file:
|
||||
|
||||
@@ -43,50 +45,136 @@ consistency:
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
<a href="https://asciinema.org/a/164143" target="_blank"><img src="https://asciinema.org/a/164143.png" width="100%" /></a>
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
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.
|
||||
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 either need to set the borgmatic
|
||||
`encryption_passphrase` configuration variable or set the `BORG_PASSPHRASE`
|
||||
environment variable. See the [repository encryption
|
||||
section](https://borgbackup.readthedocs.io/en/latest/quickstart.html#repository-encryption)
|
||||
of the Quick Start for more info.
|
||||
|
||||
Alternatively, the passphrase can be specified programatically by setting
|
||||
either the borgmatic `encryption_passcommand` configuration variable or the
|
||||
`BORG_PASSCOMMAND` environment variable. See the [Borg Security
|
||||
FAQ](http://borgbackup.readthedocs.io/en/stable/faq.html#how-can-i-specify-the-encryption-passphrase-programmatically)
|
||||
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
|
||||
```bash
|
||||
sudo pip3 install --upgrade borgmatic
|
||||
```
|
||||
|
||||
Make sure you're using Python 3, as borgmatic does not support Python 2. (You
|
||||
may have to use "pip3" or similar instead of "pip".)
|
||||
Note that your pip binary may have a different name than "pip3". Make sure
|
||||
you're using Python 3, as borgmatic does not support Python 2.
|
||||
|
||||
Then, generate a sample configuration file:
|
||||
### Other ways to install
|
||||
|
||||
sudo generate-borgmatic-config
|
||||
* [A borgmatic Docker image](https://hub.docker.com/r/b3vis/borgmatic/) based
|
||||
on Alpine Linux.
|
||||
* [Another borgmatic Docker image](https://hub.docker.com/r/coaxial/borgmatic/) based
|
||||
on Alpine Linux, updated automatically whenever the Alpine image updates.
|
||||
* [A borgmatic package for
|
||||
Fedora](https://bodhi.fedoraproject.org/updates/?search=borgmatic).
|
||||
* [A borgmatic package for Arch
|
||||
Linux](https://aur.archlinux.org/packages/borgmatic/).
|
||||
* [A borgmatic package for OpenBSD](http://ports.su/sysutils/borgmatic).
|
||||
<br><br>
|
||||
|
||||
## Configuration
|
||||
|
||||
After you install borgmatic, generate a sample configuration file:
|
||||
|
||||
```bash
|
||||
sudo generate-borgmatic-config
|
||||
```
|
||||
|
||||
If that command is not found, then it may be installed in a location that's
|
||||
not in your system `PATH`. Try looking in `/usr/local/bin/`.
|
||||
|
||||
This generates a sample configuration file at /etc/borgmatic/config.yaml (by
|
||||
default). You should edit the file to suit your needs, as the values are just
|
||||
representative. All fields are optional except where indicated, so feel free
|
||||
to remove anything you don't need.
|
||||
|
||||
You can also have a look at the [full configuration
|
||||
schema](https://projects.torsion.org/witten/borgmatic/src/master/borgmatic/config/schema.yaml)
|
||||
for the authoritative set of all configuration options. This is handy if
|
||||
borgmatic has added new options since you originally created your
|
||||
configuration file.
|
||||
|
||||
|
||||
### Multiple configuration files
|
||||
|
||||
A more advanced usage is to create multiple separate configuration files and
|
||||
place each one in an /etc/borgmatic.d directory. For instance:
|
||||
|
||||
```bash
|
||||
sudo mkdir /etc/borgmatic.d
|
||||
sudo generate-borgmatic-config --destination /etc/borgmatic.d/app1.yaml
|
||||
sudo generate-borgmatic-config --destination /etc/borgmatic.d/app2.yaml
|
||||
```
|
||||
|
||||
With this approach, you can have entirely different backup policies for
|
||||
different applications on your system. For instance, you may want one backup
|
||||
configuration for your database data directory, and a different configuration
|
||||
for your user home directories.
|
||||
|
||||
When you set up multiple configuration files like this, borgmatic will run
|
||||
each one in turn from a single borgmatic invocation. This includes, by
|
||||
default, the traditional /etc/borgmatic/config.yaml as well.
|
||||
|
||||
And if you need even more customizability, you can specify alternate
|
||||
configuration paths on the command-line with borgmatic's `--config` option.
|
||||
See `borgmatic --help` for more information.
|
||||
|
||||
|
||||
### Hooks
|
||||
|
||||
If you find yourself performing prepraration tasks before your backup runs, or
|
||||
cleanup work afterwards, borgmatic hooks may be of interest. They're simply
|
||||
shell commands that borgmatic executes for you at various points, and they're
|
||||
configured in the `hooks` section of your configuration file.
|
||||
|
||||
For instance, you can specify `before_backup` hooks to dump a database to file
|
||||
before backing it up, and specify `after_backup` hooks to delete the temporary
|
||||
file afterwards.
|
||||
|
||||
borgmatic hooks run once per configuration file. `before_backup` hooks run
|
||||
prior to backups of all repositories. `after_backup` hooks run afterwards, but
|
||||
not if an error occurs in a previous hook or in the backups themselves. And
|
||||
borgmatic runs `on_error` hooks if an error occurs.
|
||||
|
||||
An important security note about hooks: borgmatic executes all hook commands
|
||||
with the user permissions of borgmatic itself. So to prevent potential shell
|
||||
injection or privilege escalation, do not forget to set secure permissions
|
||||
(`chmod 0700`) on borgmatic configuration files and scripts invoked by hooks.
|
||||
|
||||
See the sample generated configuration file mentioned above for specifics
|
||||
about hook configuration syntax.
|
||||
|
||||
|
||||
## Upgrading
|
||||
|
||||
In general, all you should need to do to upgrade borgmatic is run the
|
||||
following:
|
||||
|
||||
sudo pip install --upgrade borgmatic
|
||||
|
||||
(You may have to use "pip3" or similar instead of "pip", so Python 3 gets
|
||||
used.)
|
||||
```bash
|
||||
sudo pip3 install --upgrade borgmatic
|
||||
```
|
||||
|
||||
However, see below about special cases.
|
||||
|
||||
@@ -96,18 +184,22 @@ However, see below about special cases.
|
||||
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, first
|
||||
upgrade to the new version of borgmatic:
|
||||
upgrade to the new version of borgmatic.
|
||||
|
||||
As of version 1.1.0, borgmatic no longer supports Python 2. If you were
|
||||
already running borgmatic with Python 3, then you can simply upgrade borgmatic
|
||||
in-place:
|
||||
|
||||
sudo pip install --upgrade borgmatic
|
||||
```bash
|
||||
sudo pip3 install --upgrade borgmatic
|
||||
```
|
||||
|
||||
But if you were running borgmatic with Python 2, uninstall and reinstall instead:
|
||||
|
||||
sudo pip uninstall borgmatic
|
||||
sudo pip3 install borgmatic
|
||||
```bash
|
||||
sudo pip uninstall borgmatic
|
||||
sudo pip3 install borgmatic
|
||||
```
|
||||
|
||||
The pip binary names for different versions of Python can differ, so the above
|
||||
commands may need some tweaking to work on your machine.
|
||||
@@ -115,7 +207,9 @@ commands may need some tweaking to work on your machine.
|
||||
|
||||
Once borgmatic is upgraded, run:
|
||||
|
||||
sudo upgrade-borgmatic-config
|
||||
```bash
|
||||
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
|
||||
@@ -137,8 +231,10 @@ 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
|
||||
```bash
|
||||
sudo pip3 uninstall atticmatic
|
||||
sudo pip3 install borgmatic
|
||||
```
|
||||
|
||||
That's it! borgmatic will continue using your /etc/borgmatic configuration
|
||||
files.
|
||||
@@ -149,24 +245,69 @@ files.
|
||||
You can run borgmatic and start a backup simply by invoking it without
|
||||
arguments:
|
||||
|
||||
borgmatic
|
||||
```bash
|
||||
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.
|
||||
|
||||
If you'd like to see the available command-line arguments, view the help:
|
||||
|
||||
```bash
|
||||
borgmatic --help
|
||||
```
|
||||
|
||||
Note that borgmatic prunes archives *before* creating an archive, so as to
|
||||
free up space for archiving. This means that when a borgmatic run finishes,
|
||||
there may still be prune-able archives. Not to worry, as they will get cleaned
|
||||
up at the start of the next run.
|
||||
|
||||
### Verbosity
|
||||
|
||||
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
|
||||
```bash
|
||||
borgmatic --verbosity 1
|
||||
```
|
||||
|
||||
Or, for even more progress spew:
|
||||
|
||||
borgmatic --verbosity 2
|
||||
```bash
|
||||
borgmatic --verbosity 2
|
||||
```
|
||||
|
||||
If you'd like to see the available command-line arguments, view the help:
|
||||
### À la carte
|
||||
|
||||
borgmatic --help
|
||||
If you want to run borgmatic with only pruning, creating, or checking enabled,
|
||||
the following optional flags are available:
|
||||
|
||||
```bash
|
||||
borgmatic --prune
|
||||
borgmatic --create
|
||||
borgmatic --check
|
||||
```
|
||||
|
||||
You can run with only one of these flags provided, or you can mix and match
|
||||
any number of them. 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.
|
||||
|
||||
Additionally, borgmatic provides convenient flags for Borg's
|
||||
[list](https://borgbackup.readthedocs.io/en/stable/usage/list.html) and
|
||||
[info](https://borgbackup.readthedocs.io/en/stable/usage/info.html)
|
||||
functionality:
|
||||
|
||||
|
||||
```bash
|
||||
borgmatic --list
|
||||
borgmatic --info
|
||||
```
|
||||
|
||||
You can include an optional `--json` flag with `--create`, `--list`, or
|
||||
`--info` to get the output formatted as JSON.
|
||||
|
||||
|
||||
## Autopilot
|
||||
@@ -177,11 +318,13 @@ configure a job runner to invoke it periodically.
|
||||
### cron
|
||||
|
||||
If you're using cron, download the [sample cron
|
||||
file](https://torsion.org/hg/borgmatic/raw-file/tip/sample/cron/borgmatic).
|
||||
file](https://projects.torsion.org/witten/borgmatic/src/master/sample/cron/borgmatic).
|
||||
Then, from the directory where you downloaded it:
|
||||
|
||||
sudo mv borgmatic /etc/cron.d/borgmatic
|
||||
sudo chmod +x /etc/cron.d/borgmatic
|
||||
```bash
|
||||
sudo mv borgmatic /etc/cron.d/borgmatic
|
||||
sudo chmod +x /etc/cron.d/borgmatic
|
||||
```
|
||||
|
||||
You can modify the cron file if you'd like to run borgmatic more or less frequently.
|
||||
|
||||
@@ -189,28 +332,106 @@ You can modify the cron file if you'd like to run borgmatic more or less frequen
|
||||
|
||||
If you're using systemd instead of cron to run jobs, download the [sample
|
||||
systemd service
|
||||
file](https://torsion.org/hg/borgmatic/raw-file/tip/sample/systemd/borgmatic.service)
|
||||
file](https://projects.torsion.org/witten/borgmatic/src/master/sample/systemd/borgmatic.service)
|
||||
and the [sample systemd timer
|
||||
file](https://torsion.org/hg/borgmatic/raw-file/tip/sample/systemd/borgmatic.timer).
|
||||
file](https://projects.torsion.org/witten/borgmatic/src/master/sample/systemd/borgmatic.timer).
|
||||
Then, from the directory where you downloaded them:
|
||||
|
||||
sudo mv borgmatic.service borgmatic.timer /etc/systemd/system/
|
||||
sudo systemctl enable borgmatic.timer
|
||||
sudo systemctl start borgmatic.timer
|
||||
```bash
|
||||
sudo mv borgmatic.service borgmatic.timer /etc/systemd/system/
|
||||
sudo systemctl enable borgmatic.timer
|
||||
sudo systemctl start borgmatic.timer
|
||||
```
|
||||
|
||||
Feel free to modify the timer file based on how frequently you'd like
|
||||
borgmatic to run.
|
||||
|
||||
|
||||
## Running tests
|
||||
## Support and contributing
|
||||
|
||||
First install tox, which is used for setting up testing environments:
|
||||
### Issues
|
||||
|
||||
pip install tox
|
||||
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.
|
||||
|
||||
Then, to actually run tests, run:
|
||||
Other questions or comments? Contact <mailto:witten@torsion.org>.
|
||||
|
||||
tox
|
||||
|
||||
### 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!
|
||||
|
||||
|
||||
### Code style
|
||||
|
||||
Start with [PEP 8](https://www.python.org/dev/peps/pep-0008/). But then, apply
|
||||
the following deviations from it:
|
||||
|
||||
* For strings, prefer single quotes over double quotes.
|
||||
* Limit all lines to a maximum of 100 characters.
|
||||
* Use trailing commas within multiline values or argument lists.
|
||||
* For multiline constructs, put opening and closing delimeters on lines
|
||||
separate from their contents.
|
||||
* Within multiline constructs, use standard four-space indentation. Don't align
|
||||
indentation with an opening delimeter.
|
||||
|
||||
|
||||
### Development
|
||||
|
||||
To get set up to hack on borgmatic, first clone master via HTTPS or SSH:
|
||||
|
||||
```bash
|
||||
git clone https://projects.torsion.org/witten/borgmatic.git
|
||||
```
|
||||
|
||||
Or:
|
||||
|
||||
```bash
|
||||
git clone ssh://git@projects.torsion.org:3022/witten/borgmatic.git
|
||||
```
|
||||
|
||||
Then, install borgmatic
|
||||
"[editable](https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs)"
|
||||
so that you can easily run borgmatic commands while you're hacking on them to
|
||||
make sure your changes work.
|
||||
|
||||
```bash
|
||||
cd borgmatic/
|
||||
pip3 install --editable --user .
|
||||
```
|
||||
|
||||
Note that this will typically install the borgmatic commands into
|
||||
`~/.local/bin`, which may or may not be on your PATH. There are other ways to
|
||||
install borgmatic editable as well, for instance into the system Python
|
||||
install (so without `--user`, as root), or even into a
|
||||
[virtualenv](https://virtualenv.pypa.io/en/stable/). How or where you install
|
||||
borgmatic is up to you, but generally an editable install makes development
|
||||
and testing easier.
|
||||
|
||||
|
||||
### Running tests
|
||||
|
||||
Assuming you've cloned the borgmatic source code as described above, and
|
||||
you're in the `borgmatic/` working copy, install tox, which is used for
|
||||
setting up testing environments:
|
||||
|
||||
```bash
|
||||
sudo pip3 install tox
|
||||
```
|
||||
|
||||
Finally, to actually run tests, run:
|
||||
|
||||
```bash
|
||||
cd borgmatic
|
||||
tox
|
||||
```
|
||||
|
||||
|
||||
## Troubleshooting
|
||||
@@ -221,14 +442,18 @@ When running borgmatic on a large remote repository, you may receive errors
|
||||
like the following, particularly while "borg check" is validating backups for
|
||||
consistency:
|
||||
|
||||
```text
|
||||
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:
|
||||
|
||||
```text
|
||||
Host *
|
||||
ServerAliveInterval 120
|
||||
```
|
||||
|
||||
This should make the client keep the connection alive while validating
|
||||
backups.
|
||||
@@ -243,13 +468,3 @@ YAML library. If so, not to worry. borgmatic should install and function
|
||||
correctly even without the C YAML library. And borgmatic won't be any faster
|
||||
with the C library present, so you don't need to go out of your way to install
|
||||
it.
|
||||
|
||||
|
||||
## 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?page=1&status=399951,399952,399955). In
|
||||
order to create a new issue or comment on an issue, you'll need to [login
|
||||
first](https://tree.taiga.io/login).
|
||||
|
||||
Other questions or comments? Contact <mailto:witten@torsion.org>.
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
from datetime import datetime
|
||||
import glob
|
||||
import itertools
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
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 _write_exclude_file(exclude_patterns=None):
|
||||
'''
|
||||
Given a sequence of exclude patterns, write them to a named temporary file and return it. Return
|
||||
None if no patterns are provided.
|
||||
'''
|
||||
if not exclude_patterns:
|
||||
return None
|
||||
|
||||
exclude_file = tempfile.NamedTemporaryFile('w')
|
||||
exclude_file.write('\n'.join(exclude_patterns))
|
||||
exclude_file.flush()
|
||||
|
||||
return exclude_file
|
||||
|
||||
|
||||
def create_archive(
|
||||
verbosity, repository, location_config, storage_config, command=COMMAND,
|
||||
):
|
||||
'''
|
||||
Given a vebosity flag, a storage config dict, a list of source directories, a local or remote
|
||||
repository path, a list of exclude patterns, and a command to run, create an attic archive.
|
||||
'''
|
||||
sources = tuple(
|
||||
itertools.chain.from_iterable(
|
||||
glob.glob(directory) or [directory]
|
||||
for directory in location_config['source_directories']
|
||||
)
|
||||
)
|
||||
|
||||
exclude_file = _write_exclude_file(location_config.get('exclude_patterns'))
|
||||
exclude_flags = ('--exclude-from', exclude_file.name) if exclude_file 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 location_config.get('one_file_system') else ()
|
||||
remote_path = location_config.get('remote_path')
|
||||
remote_path_flags = ('--remote-path', remote_path) if remote_path else ()
|
||||
verbosity_flags = {
|
||||
VERBOSITY_SOME: ('--info', '--stats',),
|
||||
VERBOSITY_LOTS: ('--debug', '--list', '--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: ('--info', '--stats',),
|
||||
VERBOSITY_LOTS: ('--debug', '--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 "checks" list, 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', [])
|
||||
if checks == ['disabled']:
|
||||
return ()
|
||||
|
||||
return tuple(check for check in checks if check.lower() not in ('disabled', '')) or DEFAULT_CHECKS
|
||||
|
||||
|
||||
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.
|
||||
'''
|
||||
last_flag = ('--last', str(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: ('--info',),
|
||||
VERBOSITY_LOTS: ('--debug',),
|
||||
}.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)
|
||||
@@ -0,0 +1,112 @@
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from borgmatic.borg import extract
|
||||
|
||||
|
||||
DEFAULT_CHECKS = ('repository', 'archives')
|
||||
DEFAULT_PREFIX = '{hostname}-'
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _parse_checks(consistency_config):
|
||||
'''
|
||||
Given a consistency config with a "checks" list, 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', [])
|
||||
if checks == ['disabled']:
|
||||
return ()
|
||||
|
||||
return tuple(check for check in checks if check.lower() 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 ('--prefix', DEFAULT_PREFIX)
|
||||
else:
|
||||
last_flags = ()
|
||||
prefix_flags = ()
|
||||
if check_last:
|
||||
logger.warn('Ignoring check_last option, as "archives" is not in consistency checks.')
|
||||
if prefix:
|
||||
logger.warn('Ignoring consistency prefix option, as "archives" is not in consistency checks.')
|
||||
|
||||
if set(DEFAULT_CHECKS).issubset(set(checks)):
|
||||
return last_flags + prefix_flags
|
||||
|
||||
return tuple(
|
||||
'--{}-only'.format(check) for check in checks
|
||||
if check in DEFAULT_CHECKS
|
||||
) + last_flags + prefix_flags
|
||||
|
||||
|
||||
def check_archives(repository, storage_config, consistency_config, local_path='borg', remote_path=None):
|
||||
'''
|
||||
Given a local or remote repository path, a storage config dict, a consistency config dict,
|
||||
and a local/remote commands to run, check the contained Borg 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)
|
||||
lock_wait = None
|
||||
|
||||
if set(checks).intersection(set(DEFAULT_CHECKS)):
|
||||
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')
|
||||
|
||||
full_command = (
|
||||
local_path, 'check',
|
||||
repository,
|
||||
) + _make_check_flags(checks, check_last, prefix) + remote_path_flags + lock_wait_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')
|
||||
|
||||
logger.debug(' '.join(full_command))
|
||||
subprocess.check_call(full_command, stdout=stdout, stderr=subprocess.STDOUT)
|
||||
|
||||
if 'extract' in checks:
|
||||
extract.extract_last_archive_dry_run(repository, lock_wait, local_path, remote_path)
|
||||
@@ -0,0 +1,160 @@
|
||||
import glob
|
||||
import itertools
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def initialize_environment(storage_config):
|
||||
passcommand = storage_config.get('encryption_passcommand')
|
||||
if passcommand:
|
||||
os.environ['BORG_PASSCOMMAND'] = passcommand
|
||||
|
||||
passphrase = storage_config.get('encryption_passphrase')
|
||||
if passphrase:
|
||||
os.environ['BORG_PASSPHRASE'] = passphrase
|
||||
|
||||
ssh_command = storage_config.get('ssh_command')
|
||||
if ssh_command:
|
||||
os.environ['BORG_RSH'] = ssh_command
|
||||
|
||||
|
||||
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 _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, 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.
|
||||
'''
|
||||
sources = _expand_directories(location_config['source_directories'])
|
||||
|
||||
pattern_file = _write_pattern_file(location_config.get('patterns'))
|
||||
exclude_file = _write_pattern_file(_expand_directories(location_config.get('exclude_patterns')))
|
||||
checkpoint_interval = storage_config.get('checkpoint_interval', 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',
|
||||
'{repository}::{archive_name_format}'.format(
|
||||
repository=repository,
|
||||
archive_name_format=archive_name_format,
|
||||
),
|
||||
)
|
||||
+ sources
|
||||
+ _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 ())
|
||||
+ (('--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 ())
|
||||
+ (('--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) else ())
|
||||
+ (( '--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--stats',) if not dry_run and logger.isEnabledFor(logging.INFO) else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--dry-run',) if dry_run else ())
|
||||
+ (('--json',) if json else ())
|
||||
)
|
||||
|
||||
logger.debug(' '.join(full_command))
|
||||
subprocess.check_call(full_command)
|
||||
@@ -0,0 +1,46 @@
|
||||
import logging
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
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 just 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',
|
||||
repository,
|
||||
) + remote_path_flags + lock_wait_flags + verbosity_flags
|
||||
|
||||
list_output = subprocess.check_output(full_list_command).decode(sys.stdout.encoding)
|
||||
|
||||
last_archive_name = list_output.strip().split('\n')[-1]
|
||||
if not last_archive_name:
|
||||
return
|
||||
|
||||
list_flag = ('--list',) if logger.isEnabledFor(logging.DEBUG) else ()
|
||||
full_extract_command = (
|
||||
local_path, 'extract',
|
||||
'--dry-run',
|
||||
'{repository}::{last_archive_name}'.format(
|
||||
repository=repository,
|
||||
last_archive_name=last_archive_name,
|
||||
),
|
||||
) + remote_path_flags + lock_wait_flags + verbosity_flags + list_flag
|
||||
|
||||
logger.debug(' '.join(full_extract_command))
|
||||
subprocess.check_call(full_extract_command)
|
||||
@@ -0,0 +1,27 @@
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def display_archives_info(repository, storage_config, local_path='borg', remote_path=None, json=False):
|
||||
'''
|
||||
Given a local or remote repository path, and a storage config dict,
|
||||
display summary information for Borg archives in the repository.
|
||||
'''
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
||||
full_command = (
|
||||
(local_path, 'info', repository)
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--json',) if json else ())
|
||||
)
|
||||
|
||||
logger.debug(' '.join(full_command))
|
||||
|
||||
output = subprocess.check_output(full_command)
|
||||
return output.decode() if output is not None else None
|
||||
@@ -0,0 +1,26 @@
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def list_archives(repository, storage_config, local_path='borg', remote_path=None, json=False):
|
||||
'''
|
||||
Given a local or remote repository path, and a storage config dict,
|
||||
list Borg archives in the repository.
|
||||
'''
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
||||
full_command = (
|
||||
(local_path, 'list', repository)
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--json',) if json else ())
|
||||
)
|
||||
logger.debug(' '.join(full_command))
|
||||
|
||||
output = subprocess.check_output(full_command)
|
||||
return output.decode() if output is not None else None
|
||||
@@ -0,0 +1,62 @@
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
|
||||
|
||||
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'),
|
||||
)
|
||||
'''
|
||||
if not retention_config.get('prefix'):
|
||||
retention_config['prefix'] = '{hostname}-'
|
||||
|
||||
return (
|
||||
('--' + option_name.replace('_', '-'), str(retention_config[option_name]))
|
||||
for option_name, value in retention_config.items()
|
||||
)
|
||||
|
||||
|
||||
def prune_archives(dry_run, repository, storage_config, retention_config, local_path='borg', remote_path=None):
|
||||
'''
|
||||
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',
|
||||
repository,
|
||||
) + 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 ())
|
||||
)
|
||||
|
||||
logger.debug(' '.join(full_command))
|
||||
subprocess.check_call(full_command)
|
||||
+204
-29
@@ -1,16 +1,22 @@
|
||||
from __future__ import print_function
|
||||
from argparse import ArgumentParser
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from subprocess import CalledProcessError
|
||||
import sys
|
||||
|
||||
from borgmatic import borg
|
||||
from borgmatic.config import convert, validate
|
||||
from borgmatic.borg import check as borg_check, create as borg_create, prune as borg_prune, \
|
||||
list as borg_list, info as borg_info
|
||||
from borgmatic.commands import hook
|
||||
from borgmatic.config import collect, convert, validate
|
||||
from borgmatic.signals import configure_signals
|
||||
from borgmatic.verbosity import verbosity_to_log_level
|
||||
|
||||
|
||||
LEGACY_CONFIG_FILENAME = '/etc/borgmatic/config'
|
||||
DEFAULT_CONFIG_FILENAME = '/etc/borgmatic/config.yaml'
|
||||
DEFAULT_EXCLUDES_FILENAME = '/etc/borgmatic/excludes'
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
LEGACY_CONFIG_PATH = '/etc/borgmatic/config'
|
||||
|
||||
|
||||
def parse_arguments(*arguments):
|
||||
@@ -18,49 +24,218 @@ 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()
|
||||
config_paths = collect.get_default_config_paths()
|
||||
|
||||
parser = ArgumentParser(
|
||||
description=
|
||||
'''
|
||||
A simple wrapper script for the Borg backup software that creates and prunes backups.
|
||||
If none of the --prune, --create, or --check options are given, then borgmatic defaults
|
||||
to all three: prune, create, and check archives.
|
||||
'''
|
||||
)
|
||||
parser.add_argument(
|
||||
'-c', '--config',
|
||||
dest='config_filename',
|
||||
default=DEFAULT_CONFIG_FILENAME,
|
||||
help='Configuration filename',
|
||||
nargs='+',
|
||||
dest='config_paths',
|
||||
default=config_paths,
|
||||
help='Configuration filenames or directories, defaults to: {}'.format(' '.join(config_paths)),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--excludes',
|
||||
dest='excludes_filename',
|
||||
help='Excludes filename, deprecated in favor of exclude_patterns within configuration',
|
||||
help='Deprecated in favor of exclude_patterns within configuration',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-p', '--prune',
|
||||
dest='prune',
|
||||
action='store_true',
|
||||
help='Prune archives according to the retention policy',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-C', '--create',
|
||||
dest='create',
|
||||
action='store_true',
|
||||
help='Create archives (actually perform backups)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-k', '--check',
|
||||
dest='check',
|
||||
action='store_true',
|
||||
help='Check archives for consistency',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-l', '--list',
|
||||
dest='list',
|
||||
action='store_true',
|
||||
help='List archives',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-i', '--info',
|
||||
dest='info',
|
||||
action='store_true',
|
||||
help='Display summary information on archives',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--json',
|
||||
dest='json',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Output results from the --create, --list, or --info options as json',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-n', '--dry-run',
|
||||
dest='dry_run',
|
||||
action='store_true',
|
||||
help='Go through the motions, but do not actually write to any repositories',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-v', '--verbosity',
|
||||
type=int,
|
||||
choices=range(0,3),
|
||||
default=0,
|
||||
help='Display verbose progress (1 for some, 2 for lots)',
|
||||
)
|
||||
|
||||
return parser.parse_args(arguments)
|
||||
args = parser.parse_args(arguments)
|
||||
|
||||
if args.json and not (args.create or args.list or args.info):
|
||||
raise ValueError('The --json option can only be used with the --create, --list, or --info options')
|
||||
|
||||
if args.json and args.list and args.info:
|
||||
raise ValueError(
|
||||
'With the --json option, options --list and --info cannot be used together'
|
||||
)
|
||||
|
||||
# If any of the action flags are explicitly requested, leave them as-is. Otherwise, assume
|
||||
# defaults: Mutate the given arguments to enable the default actions.
|
||||
if args.prune or args.create or args.check or args.list or args.info:
|
||||
return args
|
||||
|
||||
args.prune = True
|
||||
args.create = True
|
||||
args.check = True
|
||||
return args
|
||||
|
||||
|
||||
def run_configuration(config_filename, args): # pragma: no cover
|
||||
'''
|
||||
Parse a single configuration file, and execute its defined pruning, backups, and/or consistency
|
||||
checks.
|
||||
'''
|
||||
logger.info('{}: Parsing configuration file'.format(config_filename))
|
||||
config = validate.parse_configuration(config_filename, validate.schema_filename())
|
||||
(location, storage, retention, consistency, hooks) = (
|
||||
config.get(section_name, {})
|
||||
for section_name in ('location', 'storage', 'retention', 'consistency', 'hooks')
|
||||
)
|
||||
|
||||
try:
|
||||
local_path = location.get('local_path', 'borg')
|
||||
remote_path = location.get('remote_path')
|
||||
borg_create.initialize_environment(storage)
|
||||
|
||||
if args.create:
|
||||
hook.execute_hook(hooks.get('before_backup'), config_filename, 'pre-backup')
|
||||
|
||||
_run_commands(args, consistency, local_path, location, remote_path, retention, storage)
|
||||
|
||||
if args.create:
|
||||
hook.execute_hook(hooks.get('after_backup'), config_filename, 'post-backup')
|
||||
except (OSError, CalledProcessError):
|
||||
hook.execute_hook(hooks.get('on_error'), config_filename, 'on-error')
|
||||
raise
|
||||
|
||||
|
||||
def _run_commands(args, consistency, local_path, location, remote_path, retention, storage):
|
||||
json_results = []
|
||||
for unexpanded_repository in location['repositories']:
|
||||
_run_commands_on_repository(
|
||||
args, consistency, json_results, local_path, location, remote_path, retention, storage,
|
||||
unexpanded_repository,
|
||||
)
|
||||
if args.json:
|
||||
sys.stdout.write(json.dumps(json_results))
|
||||
|
||||
|
||||
def _run_commands_on_repository(
|
||||
args, consistency, json_results, local_path, location, remote_path,
|
||||
retention, storage, unexpanded_repository,
|
||||
): # pragma: no cover
|
||||
repository = os.path.expanduser(unexpanded_repository)
|
||||
dry_run_label = ' (dry run; not making any changes)' if args.dry_run else ''
|
||||
if args.prune:
|
||||
logger.info('{}: Pruning archives{}'.format(repository, dry_run_label))
|
||||
borg_prune.prune_archives(
|
||||
args.dry_run,
|
||||
repository,
|
||||
storage,
|
||||
retention,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
if args.create:
|
||||
logger.info('{}: Creating archive{}'.format(repository, dry_run_label))
|
||||
borg_create.create_archive(
|
||||
args.dry_run,
|
||||
repository,
|
||||
location,
|
||||
storage,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
if args.check:
|
||||
logger.info('{}: Running consistency checks'.format(repository))
|
||||
borg_check.check_archives(
|
||||
repository,
|
||||
storage,
|
||||
consistency,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path
|
||||
)
|
||||
if args.list:
|
||||
logger.info('{}: Listing archives'.format(repository))
|
||||
output = borg_list.list_archives(
|
||||
repository,
|
||||
storage,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
json=args.json,
|
||||
)
|
||||
if args.json:
|
||||
json_results.append(json.loads(output))
|
||||
else:
|
||||
sys.stdout.write(output)
|
||||
if args.info:
|
||||
logger.info('{}: Displaying summary info for archives'.format(repository))
|
||||
output = borg_info.display_archives_info(
|
||||
repository,
|
||||
storage,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
json=args.json,
|
||||
)
|
||||
if args.json:
|
||||
json_results.append(json.loads(output))
|
||||
else:
|
||||
sys.stdout.write(output)
|
||||
|
||||
|
||||
def main(): # pragma: no cover
|
||||
try:
|
||||
configure_signals()
|
||||
args = parse_arguments(*sys.argv[1:])
|
||||
convert.guard_configuration_upgraded(LEGACY_CONFIG_FILENAME, args.config_filename)
|
||||
config = validate.parse_configuration(args.config_filename, validate.schema_filename())
|
||||
(location, storage, retention, consistency) = (
|
||||
config.get(section_name, {})
|
||||
for section_name in ('location', 'storage', 'retention', 'consistency')
|
||||
)
|
||||
remote_path = location.get('remote_path')
|
||||
logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s')
|
||||
|
||||
borg.initialize(storage)
|
||||
config_filenames = tuple(collect.collect_config_filenames(args.config_paths))
|
||||
logger.debug('Ensuring legacy configuration is upgraded')
|
||||
convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)
|
||||
|
||||
for repository in location['repositories']:
|
||||
borg.prune_archives(args.verbosity, repository, retention, remote_path=remote_path)
|
||||
borg.create_archive(
|
||||
args.verbosity,
|
||||
repository,
|
||||
location,
|
||||
storage,
|
||||
)
|
||||
borg.check_archives(args.verbosity, repository, consistency, remote_path=remote_path)
|
||||
if len(config_filenames) == 0:
|
||||
raise ValueError('Error: No configuration files found in: {}'.format(' '.join(args.config_paths)))
|
||||
|
||||
for config_filename in config_filenames:
|
||||
run_configuration(config_filename, args)
|
||||
except (ValueError, OSError, CalledProcessError) as error:
|
||||
print(error, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
from argparse import ArgumentParser
|
||||
import os
|
||||
from subprocess import CalledProcessError
|
||||
@@ -7,7 +6,6 @@ import textwrap
|
||||
|
||||
from ruamel import yaml
|
||||
|
||||
from borgmatic import borg
|
||||
from borgmatic.config import convert, generate, legacy, validate
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
from __future__ import print_function
|
||||
from argparse import ArgumentParser
|
||||
import os
|
||||
from subprocess import CalledProcessError
|
||||
import sys
|
||||
|
||||
from ruamel import yaml
|
||||
|
||||
from borgmatic import borg
|
||||
from borgmatic.config import convert, generate, validate
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def execute_hook(commands, config_filename, description):
|
||||
if not commands:
|
||||
logger.debug('{}: No commands to run for {} hook'.format(config_filename, description))
|
||||
return
|
||||
|
||||
if len(commands) == 1:
|
||||
logger.info('{}: Running command for {} hook'.format(config_filename, description))
|
||||
else:
|
||||
logger.info('{}: Running {} commands for {} hook'.format(config_filename, len(commands), description))
|
||||
|
||||
for command in commands:
|
||||
logger.debug('{}: Hook command: {}'.format(config_filename, command))
|
||||
subprocess.check_call(command, shell=True)
|
||||
@@ -0,0 +1,47 @@
|
||||
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 just an
|
||||
iterable of files. Accomplish this by listing any given directories looking for contained config
|
||||
files (ending with the ".yaml" 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 os.listdir(path):
|
||||
full_filename = os.path.join(path, filename)
|
||||
if full_filename.endswith('.yaml') and not os.path.isdir(full_filename):
|
||||
yield full_filename
|
||||
@@ -77,14 +77,19 @@ instead of the old one.'''
|
||||
)
|
||||
|
||||
|
||||
def guard_configuration_upgraded(source_config_filename, destination_config_filename):
|
||||
def guard_configuration_upgraded(source_config_filename, destination_config_filenames):
|
||||
'''
|
||||
If legacy souce configuration exists but destination upgraded config doesn't, raise
|
||||
If legacy source configuration exists but no destination upgraded configs do, raise
|
||||
LegacyConfigurationNotUpgraded.
|
||||
|
||||
The idea is that we want to alert the user about upgrading their config if they haven't already.
|
||||
'''
|
||||
if os.path.exists(source_config_filename) and not os.path.exists(destination_config_filename):
|
||||
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 LegacyConfigurationNotUpgraded()
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ def _schema_to_sample_configuration(schema, level=0):
|
||||
for each section based on the schema "desc" description.
|
||||
'''
|
||||
example = schema.get('example')
|
||||
if example:
|
||||
if example is not None:
|
||||
return example
|
||||
|
||||
config = yaml.comments.CommentedMap([
|
||||
|
||||
+165
-20
@@ -6,13 +6,14 @@ map:
|
||||
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
|
||||
required: true
|
||||
map:
|
||||
source_directories:
|
||||
required: True
|
||||
required: true
|
||||
seq:
|
||||
- type: scalar
|
||||
desc: List of source directories to backup (required). Globs are expanded.
|
||||
desc: |
|
||||
List of source directories to backup (required). Globs and tildes are expanded.
|
||||
example:
|
||||
- /home
|
||||
- /etc
|
||||
@@ -20,37 +21,108 @@ map:
|
||||
one_file_system:
|
||||
type: bool
|
||||
desc: Stay in same file system (do not cross mount points).
|
||||
example: yes
|
||||
example: true
|
||||
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.
|
||||
example: false
|
||||
bsd_flags:
|
||||
type: bool
|
||||
desc: Record bsdflags (e.g. NODUMP, IMMUTABLE) in archive. Defaults to true.
|
||||
example: true
|
||||
files_cache:
|
||||
type: scalar
|
||||
desc: |
|
||||
Mode in which to operate the files cache. See
|
||||
https://borgbackup.readthedocs.io/en/stable/usage/create.html#description for
|
||||
details.
|
||||
example: ctime,size,inode
|
||||
local_path:
|
||||
type: scalar
|
||||
desc: Alternate Borg local executable. Defaults to "borg".
|
||||
example: borg1
|
||||
remote_path:
|
||||
type: scalar
|
||||
desc: Alternate Borg remote executable. Defaults to "borg".
|
||||
example: borg1
|
||||
repositories:
|
||||
required: True
|
||||
required: true
|
||||
seq:
|
||||
- type: scalar
|
||||
desc: |
|
||||
Paths to local or remote repositories (required). Multiple repositories are
|
||||
backed up to in sequence.
|
||||
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
|
||||
patterns:
|
||||
seq:
|
||||
- type: scalar
|
||||
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: scalar
|
||||
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: scalar
|
||||
desc: |
|
||||
Any paths matching these patterns are excluded from backups. Globs are expanded.
|
||||
See https://borgbackup.readthedocs.io/en/stable/usage.html#borg-help-patterns
|
||||
for details.
|
||||
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'
|
||||
- /home/*/.cache
|
||||
- ~/*/.cache
|
||||
- /etc/ssl
|
||||
exclude_from:
|
||||
seq:
|
||||
- type: scalar
|
||||
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.
|
||||
example: true
|
||||
exclude_if_present:
|
||||
type: scalar
|
||||
desc: Exclude directories that contain a file with the given filename.
|
||||
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.html#environment-variables for details.
|
||||
https://borgbackup.readthedocs.io/en/stable/usage/general.html#environment-variables for
|
||||
details.
|
||||
map:
|
||||
encryption_passcommand:
|
||||
type: scalar
|
||||
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.
|
||||
example: "secret-tool lookup borg-repository repo-name"
|
||||
encryption_passphrase:
|
||||
type: scalar
|
||||
desc: |
|
||||
@@ -59,6 +131,13 @@ map:
|
||||
punctuation, so it parses correctly. And backslash any quote or backslash
|
||||
literals as well.
|
||||
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
|
||||
compression:
|
||||
type: scalar
|
||||
desc: |
|
||||
@@ -66,19 +145,46 @@ map:
|
||||
https://borgbackup.readthedocs.org/en/stable/usage.html#borg-create for details.
|
||||
Defaults to no compression.
|
||||
example: lz4
|
||||
remote_rate_limit:
|
||||
type: int
|
||||
desc: Remote network upload rate limit in kiBytes/second.
|
||||
example: 100
|
||||
ssh_command:
|
||||
type: scalar
|
||||
desc: Command to use instead of just "ssh". This can be used to specify ssh options.
|
||||
example: ssh -i /path/to/private/key
|
||||
umask:
|
||||
type: scalar
|
||||
desc: Umask to be used for borg create.
|
||||
example: 0077
|
||||
lock_wait:
|
||||
type: int
|
||||
desc: Maximum seconds to wait for acquiring a repository/cache lock.
|
||||
example: 5
|
||||
archive_name_format:
|
||||
type: scalar
|
||||
desc: |
|
||||
Name of the archive. Borg placeholders can be used. See the output of
|
||||
"borg help placeholders" for details. Default is
|
||||
"{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}"
|
||||
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.
|
||||
map:
|
||||
keep_within:
|
||||
type: scalar
|
||||
desc: Keep all archives within this time interval.
|
||||
example: 3H
|
||||
keep_minutely:
|
||||
type: int
|
||||
desc: Number of minutely archives to keep.
|
||||
example: 60
|
||||
keep_hourly:
|
||||
type: int
|
||||
desc: Number of hourly archives to keep.
|
||||
@@ -101,26 +207,65 @@ map:
|
||||
example: 1
|
||||
prefix:
|
||||
type: scalar
|
||||
desc: When pruning, only consider archive names starting with this prefix.
|
||||
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. Default is "{hostname}-".
|
||||
example: sourcehostname
|
||||
consistency:
|
||||
desc: |
|
||||
Consistency checks to run after backups. See
|
||||
https://borgbackup.readthedocs.org/en/stable/usage.html#borg-check for details.
|
||||
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', 'disabled']
|
||||
unique: True
|
||||
enum: ['repository', 'archives', 'extract', 'disabled']
|
||||
unique: true
|
||||
desc: |
|
||||
List of consistency checks to run: "repository", "archives", or both. Defaults
|
||||
to both. Set to "disabled" to disable all consistency checks. See
|
||||
https://borgbackup.readthedocs.org/en/stable/usage.html#borg-check for details.
|
||||
List of one or more consistency checks to run: "repository", "archives", and/or
|
||||
"extract". Defaults to "repository" and "archives". Set to "disabled" to disable
|
||||
all consistency checks. "repository" checks the consistency of the repository,
|
||||
"archive" checks all of the archives, and "extract" does an extraction dry-run
|
||||
of just the most recent archive.
|
||||
example:
|
||||
- repository
|
||||
- archives
|
||||
check_last:
|
||||
type: int
|
||||
desc: Restrict the number of checked archives to the last n.
|
||||
desc: Restrict the number of checked archives to the last n. Applies only to the
|
||||
"archives" check.
|
||||
example: 3
|
||||
prefix:
|
||||
type: scalar
|
||||
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. Default is "{hostname}-".
|
||||
example: sourcehostname
|
||||
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: scalar
|
||||
desc: List of one or more shell commands or scripts to execute before creating a backup.
|
||||
example:
|
||||
- echo "`date` - Starting a backup job."
|
||||
after_backup:
|
||||
seq:
|
||||
- type: scalar
|
||||
desc: List of one or more shell commands or scripts to execute after creating a backup.
|
||||
example:
|
||||
- echo "`date` - Backup created."
|
||||
on_error:
|
||||
seq:
|
||||
- type: scalar
|
||||
desc: List of one or more shell commands or scripts to execute in case an exception has occurred.
|
||||
example:
|
||||
- echo "`date` - Error while creating a backup."
|
||||
|
||||
@@ -8,6 +8,9 @@ import pykwalify.errors
|
||||
from ruamel import yaml
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def schema_filename():
|
||||
'''
|
||||
Path to the installed YAML configuration schema file, used to validate and parse the
|
||||
@@ -25,6 +28,36 @@ class Validation_error(ValueError):
|
||||
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.',
|
||||
)
|
||||
)
|
||||
|
||||
consistency_prefix = parsed_configuration.get('consistency', {}).get('prefix')
|
||||
if archive_name_format and not consistency_prefix:
|
||||
logger.warning('Since version 1.1.16, if you provide `archive_name_format`, you should also'
|
||||
' specify `consistency.prefix`.')
|
||||
|
||||
|
||||
def parse_configuration(config_filename, schema_filename):
|
||||
'''
|
||||
@@ -38,9 +71,11 @@ def parse_configuration(config_filename, schema_filename):
|
||||
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 = yaml.round_trip_load(open(config_filename))
|
||||
schema = yaml.round_trip_load(open(schema_filename))
|
||||
config = yaml.safe_load(open(config_filename))
|
||||
schema = yaml.safe_load(open(schema_filename))
|
||||
except yaml.error.YAMLError as error:
|
||||
raise Validation_error(config_filename, (str(error),))
|
||||
|
||||
@@ -48,7 +83,7 @@ def parse_configuration(config_filename, schema_filename):
|
||||
# simply 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')
|
||||
field_schema.pop('example', None)
|
||||
|
||||
validator = pykwalify.core.Core(source_data=config, schema_data=schema)
|
||||
parsed_result = validator.validate(raise_exception=False)
|
||||
@@ -56,19 +91,6 @@ def parse_configuration(config_filename, schema_filename):
|
||||
if validator.validation_errors:
|
||||
raise Validation_error(config_filename, validator.validation_errors)
|
||||
|
||||
apply_logical_validation(config_filename, parsed_result)
|
||||
|
||||
return parsed_result
|
||||
|
||||
|
||||
def display_validation_error(validation_error):
|
||||
'''
|
||||
Given a Validation_error, display its error messages to stderr.
|
||||
'''
|
||||
print(
|
||||
'An error occurred while parsing a configuration file at {}:'.format(
|
||||
validation_error.config_filename
|
||||
),
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
for error in validation_error.error_messages:
|
||||
print(error, file=sys.stderr)
|
||||
|
||||
@@ -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)
|
||||
@@ -7,29 +7,99 @@ from borgmatic.commands import borgmatic as module
|
||||
|
||||
|
||||
def test_parse_arguments_with_no_arguments_uses_defaults():
|
||||
config_paths = ['default']
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
|
||||
|
||||
parser = module.parse_arguments()
|
||||
|
||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
||||
assert parser.config_paths == config_paths
|
||||
assert parser.excludes_filename == None
|
||||
assert parser.verbosity is None
|
||||
assert parser.verbosity is 0
|
||||
assert parser.json is False
|
||||
|
||||
|
||||
def test_parse_arguments_with_filename_arguments_overrides_defaults():
|
||||
def test_parse_arguments_with_path_arguments_overrides_defaults():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
parser = module.parse_arguments('--config', 'myconfig', '--excludes', 'myexcludes')
|
||||
|
||||
assert parser.config_filename == 'myconfig'
|
||||
assert parser.config_paths == ['myconfig']
|
||||
assert parser.excludes_filename == 'myexcludes'
|
||||
assert parser.verbosity is None
|
||||
assert parser.verbosity is 0
|
||||
|
||||
|
||||
def test_parse_arguments_with_multiple_config_paths_parses_as_list():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
parser = module.parse_arguments('--config', 'myconfig', 'otherconfig')
|
||||
|
||||
assert parser.config_paths == ['myconfig', 'otherconfig']
|
||||
assert parser.verbosity is 0
|
||||
|
||||
|
||||
def test_parse_arguments_with_verbosity_flag_overrides_default():
|
||||
config_paths = ['default']
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
|
||||
|
||||
parser = module.parse_arguments('--verbosity', '1')
|
||||
|
||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
||||
assert parser.config_paths == config_paths
|
||||
assert parser.excludes_filename == None
|
||||
assert parser.verbosity == 1
|
||||
|
||||
|
||||
def test_parse_arguments_with_json_flag_overrides_default():
|
||||
parser = module.parse_arguments('--list', '--json')
|
||||
assert parser.json is True
|
||||
|
||||
|
||||
def test_parse_arguments_with_no_actions_defaults_to_all_actions_enabled():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
parser = module.parse_arguments()
|
||||
|
||||
assert parser.prune is True
|
||||
assert parser.create is True
|
||||
assert parser.check is True
|
||||
|
||||
|
||||
def test_parse_arguments_with_prune_action_leaves_other_actions_disabled():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
parser = module.parse_arguments('--prune')
|
||||
|
||||
assert parser.prune is True
|
||||
assert parser.create is False
|
||||
assert parser.check is False
|
||||
|
||||
|
||||
def test_parse_arguments_with_multiple_actions_leaves_other_action_disabled():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
parser = module.parse_arguments('--create', '--check')
|
||||
|
||||
assert parser.prune is False
|
||||
assert parser.create is True
|
||||
assert parser.check is True
|
||||
|
||||
|
||||
def test_parse_arguments_with_invalid_arguments_exits():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
module.parse_arguments('--posix-me-harder')
|
||||
|
||||
|
||||
def test_parse_arguments_with_json_flag_with_list_or_info_flag_does_not_raise_any_error():
|
||||
module.parse_arguments('--list', '--json')
|
||||
module.parse_arguments('--info', '--json')
|
||||
|
||||
|
||||
def test_parse_arguments_with_json_flag_but_no_list_or_info_flag_raises_value_error():
|
||||
with pytest.raises(ValueError):
|
||||
module.parse_arguments('--json')
|
||||
|
||||
|
||||
def test_parse_arguments_with_json_flag_and_both_list_and_info_flag_raises_value_error():
|
||||
with pytest.raises(ValueError):
|
||||
module.parse_arguments('--list', '--info', '--json')
|
||||
|
||||
@@ -15,13 +15,18 @@ def test_schema_filename_returns_plausable_path():
|
||||
assert schema_path.endswith('/schema.yaml')
|
||||
|
||||
|
||||
def mock_config_and_schema(config_yaml):
|
||||
def mock_config_and_schema(config_yaml, schema_yaml=None):
|
||||
'''
|
||||
Set up mocks for the config config YAML string and the default schema so that the code under
|
||||
test consumes them when parsing the configuration.
|
||||
Set up mocks for the given config config YAML string and the schema YAML string, or the default
|
||||
schema if no schema is provided. The idea is that that the code under test consumes these mocks
|
||||
when parsing the configuration.
|
||||
'''
|
||||
config_stream = io.StringIO(config_yaml)
|
||||
schema_stream = open(module.schema_filename())
|
||||
if schema_yaml is None:
|
||||
schema_stream = open(module.schema_filename())
|
||||
else:
|
||||
schema_stream = io.StringIO(schema_yaml)
|
||||
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_stream)
|
||||
builtins.should_receive('open').with_args('schema.yaml').and_return(schema_stream)
|
||||
@@ -39,6 +44,8 @@ def test_parse_configuration_transforms_file_into_mapping():
|
||||
- hostname.borg
|
||||
|
||||
retention:
|
||||
keep_minutely: 60
|
||||
keep_hourly: 24
|
||||
keep_daily: 7
|
||||
|
||||
consistency:
|
||||
@@ -52,7 +59,7 @@ def test_parse_configuration_transforms_file_into_mapping():
|
||||
|
||||
assert result == {
|
||||
'location': {'source_directories': ['/home', '/etc'], 'repositories': ['hostname.borg']},
|
||||
'retention': {'keep_daily': 7},
|
||||
'retention': {'keep_daily': 7, 'keep_hourly': 24, 'keep_minutely': 60},
|
||||
'consistency': {'checks': ['repository', 'archives']},
|
||||
}
|
||||
|
||||
@@ -81,6 +88,35 @@ def test_parse_configuration_passes_through_quoted_punctuation():
|
||||
}
|
||||
|
||||
|
||||
def test_parse_configuration_with_schema_lacking_examples_does_not_raise():
|
||||
mock_config_and_schema(
|
||||
'''
|
||||
location:
|
||||
source_directories:
|
||||
- /home
|
||||
|
||||
repositories:
|
||||
- hostname.borg
|
||||
''',
|
||||
'''
|
||||
map:
|
||||
location:
|
||||
required: true
|
||||
map:
|
||||
source_directories:
|
||||
required: true
|
||||
seq:
|
||||
- type: scalar
|
||||
repositories:
|
||||
required: true
|
||||
seq:
|
||||
- type: scalar
|
||||
'''
|
||||
)
|
||||
|
||||
module.parse_configuration('config.yaml', 'schema.yaml')
|
||||
|
||||
|
||||
def test_parse_configuration_raises_for_missing_config_file():
|
||||
with pytest.raises(FileNotFoundError):
|
||||
module.parse_configuration('config.yaml', 'schema.yaml')
|
||||
@@ -114,10 +150,3 @@ def test_parse_configuration_raises_for_validation_error():
|
||||
|
||||
with pytest.raises(module.Validation_error):
|
||||
module.parse_configuration('config.yaml', 'schema.yaml')
|
||||
|
||||
|
||||
def test_display_validation_error_does_not_raise():
|
||||
flexmock(sys.modules['builtins']).should_receive('print')
|
||||
error = module.Validation_error('config.yaml', ('oops', 'uh oh'))
|
||||
|
||||
module.display_validation_error(error)
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
from subprocess import STDOUT
|
||||
import logging, sys
|
||||
|
||||
from flexmock import flexmock
|
||||
import pytest
|
||||
|
||||
from borgmatic.borg import check as module
|
||||
from borgmatic.tests.unit.test_verbosity import insert_logging_mock
|
||||
|
||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
|
||||
|
||||
|
||||
def insert_subprocess_never():
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_call').never()
|
||||
|
||||
|
||||
def test_parse_checks_returns_them_as_tuple():
|
||||
checks = module._parse_checks({'checks': ['foo', 'disabled', 'bar']})
|
||||
|
||||
assert checks == ('foo', 'bar')
|
||||
|
||||
|
||||
def test_parse_checks_with_missing_value_returns_defaults():
|
||||
checks = module._parse_checks({})
|
||||
|
||||
assert checks == module.DEFAULT_CHECKS
|
||||
|
||||
|
||||
def test_parse_checks_with_blank_value_returns_defaults():
|
||||
checks = module._parse_checks({'checks': []})
|
||||
|
||||
assert checks == module.DEFAULT_CHECKS
|
||||
|
||||
|
||||
def test_parse_checks_with_disabled_returns_no_checks():
|
||||
checks = module._parse_checks({'checks': ['disabled']})
|
||||
|
||||
assert checks == ()
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_check_returns_flag():
|
||||
flags = module._make_check_flags(('repository',))
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_extract_omits_extract_flag():
|
||||
flags = module._make_check_flags(('extract',))
|
||||
|
||||
assert flags == ()
|
||||
|
||||
|
||||
def test_make_check_flags_with_default_checks_returns_default_flags():
|
||||
flags = module._make_check_flags(module.DEFAULT_CHECKS)
|
||||
|
||||
assert flags == ('--prefix', module.DEFAULT_PREFIX)
|
||||
|
||||
|
||||
def test_make_check_flags_with_all_checks_returns_default_flags():
|
||||
flags = module._make_check_flags(module.DEFAULT_CHECKS + ('extract',))
|
||||
|
||||
assert flags == ('--prefix', module.DEFAULT_PREFIX)
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_last_includes_last_flag():
|
||||
flags = module._make_check_flags(('archives',), check_last=3)
|
||||
|
||||
assert flags == ('--archives-only', '--last', '3', '--prefix', module.DEFAULT_PREFIX)
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_check_and_last_omits_last_flag():
|
||||
flags = module._make_check_flags(('repository',), check_last=3)
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_default_checks_and_last_includes_last_flag():
|
||||
flags = module._make_check_flags(module.DEFAULT_CHECKS, check_last=3)
|
||||
|
||||
assert flags == ('--last', '3', '--prefix', module.DEFAULT_PREFIX)
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_prefix_includes_prefix_flag():
|
||||
flags = module._make_check_flags(('archives',), prefix='foo-')
|
||||
|
||||
assert flags == ('--archives-only', '--prefix', 'foo-')
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_check_and_prefix_omits_prefix_flag():
|
||||
flags = module._make_check_flags(('repository',), prefix='foo-')
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_default_checks_and_prefix_includes_prefix_flag():
|
||||
flags = module._make_check_flags(module.DEFAULT_CHECKS, prefix='foo-')
|
||||
|
||||
assert flags == ('--prefix', 'foo-')
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'checks',
|
||||
(
|
||||
('repository',),
|
||||
('archives',),
|
||||
('repository', 'archives'),
|
||||
('repository', 'archives', 'other'),
|
||||
),
|
||||
)
|
||||
def test_check_archives_calls_borg_with_parameters(checks):
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||
flexmock(module).should_receive('_make_check_flags').with_args(checks, check_last, None).and_return(())
|
||||
stdout = flexmock()
|
||||
insert_subprocess_mock(
|
||||
('borg', 'check', 'repo'),
|
||||
stdout=stdout, stderr=STDOUT,
|
||||
)
|
||||
flexmock(sys.modules['builtins']).should_receive('open').and_return(stdout)
|
||||
flexmock(module.os).should_receive('devnull')
|
||||
|
||||
module.check_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_extract_check_calls_extract_only():
|
||||
checks = ('extract',)
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||
flexmock(module).should_receive('_make_check_flags').never()
|
||||
flexmock(module.extract).should_receive('extract_last_archive_dry_run').once()
|
||||
insert_subprocess_never()
|
||||
|
||||
module.check_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_log_info_calls_borg_with_info_parameter():
|
||||
checks = ('repository',)
|
||||
consistency_config = {'check_last': None}
|
||||
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||
flexmock(module).should_receive('_make_check_flags').and_return(())
|
||||
insert_logging_mock(logging.INFO)
|
||||
insert_subprocess_mock(
|
||||
('borg', 'check', 'repo', '--info'),
|
||||
stdout=None, stderr=STDOUT,
|
||||
)
|
||||
|
||||
module.check_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_log_debug_calls_borg_with_debug_parameter():
|
||||
checks = ('repository',)
|
||||
consistency_config = {'check_last': None}
|
||||
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||
flexmock(module).should_receive('_make_check_flags').and_return(())
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
insert_subprocess_mock(
|
||||
('borg', 'check', 'repo', '--debug', '--show-rc'),
|
||||
stdout=None, stderr=STDOUT,
|
||||
)
|
||||
|
||||
module.check_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_without_any_checks_bails():
|
||||
consistency_config = {'check_last': None}
|
||||
flexmock(module).should_receive('_parse_checks').and_return(())
|
||||
insert_subprocess_never()
|
||||
|
||||
module.check_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_local_path_calls_borg_via_local_path():
|
||||
checks = ('repository',)
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||
flexmock(module).should_receive('_make_check_flags').with_args(checks, check_last, None).and_return(())
|
||||
stdout = flexmock()
|
||||
insert_subprocess_mock(
|
||||
('borg1', 'check', 'repo'),
|
||||
stdout=stdout, stderr=STDOUT,
|
||||
)
|
||||
flexmock(sys.modules['builtins']).should_receive('open').and_return(stdout)
|
||||
flexmock(module.os).should_receive('devnull')
|
||||
|
||||
module.check_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||
checks = ('repository',)
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||
flexmock(module).should_receive('_make_check_flags').with_args(checks, check_last, None).and_return(())
|
||||
stdout = flexmock()
|
||||
insert_subprocess_mock(
|
||||
('borg', 'check', 'repo', '--remote-path', 'borg1'),
|
||||
stdout=stdout, stderr=STDOUT,
|
||||
)
|
||||
flexmock(sys.modules['builtins']).should_receive('open').and_return(stdout)
|
||||
flexmock(module.os).should_receive('devnull')
|
||||
|
||||
module.check_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
checks = ('repository',)
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||
flexmock(module).should_receive('_make_check_flags').with_args(checks, check_last, None).and_return(())
|
||||
stdout = flexmock()
|
||||
insert_subprocess_mock(
|
||||
('borg', 'check', 'repo', '--lock-wait', '5'),
|
||||
stdout=stdout, stderr=STDOUT,
|
||||
)
|
||||
flexmock(sys.modules['builtins']).should_receive('open').and_return(stdout)
|
||||
flexmock(module.os).should_receive('devnull')
|
||||
|
||||
module.check_archives(
|
||||
repository='repo',
|
||||
storage_config={'lock_wait': 5},
|
||||
consistency_config=consistency_config,
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_retention_prefix():
|
||||
checks = ('repository',)
|
||||
check_last = flexmock()
|
||||
prefix = 'foo-'
|
||||
consistency_config = {'check_last': check_last, 'prefix': prefix}
|
||||
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||
flexmock(module).should_receive('_make_check_flags').with_args(checks, check_last, prefix).and_return(())
|
||||
stdout = flexmock()
|
||||
insert_subprocess_mock(
|
||||
('borg', 'check', 'repo'),
|
||||
stdout=stdout, stderr=STDOUT,
|
||||
)
|
||||
|
||||
flexmock(sys.modules['builtins']).should_receive('open').and_return(stdout)
|
||||
flexmock(module.os).should_receive('devnull')
|
||||
|
||||
module.check_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
)
|
||||
@@ -0,0 +1,730 @@
|
||||
import logging, os
|
||||
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.borg import create as module
|
||||
from borgmatic.tests.unit.test_verbosity import insert_logging_mock
|
||||
|
||||
|
||||
def test_initialize_environment_with_passcommand_should_set_environment():
|
||||
orig_environ = os.environ
|
||||
|
||||
try:
|
||||
os.environ = {}
|
||||
module.initialize_environment({'encryption_passcommand': 'command'})
|
||||
assert os.environ.get('BORG_PASSCOMMAND') == 'command'
|
||||
finally:
|
||||
os.environ = orig_environ
|
||||
|
||||
|
||||
def test_initialize_environment_with_passphrase_should_set_environment():
|
||||
orig_environ = os.environ
|
||||
|
||||
try:
|
||||
os.environ = {}
|
||||
module.initialize_environment({'encryption_passphrase': 'pass'})
|
||||
assert os.environ.get('BORG_PASSPHRASE') == 'pass'
|
||||
finally:
|
||||
os.environ = orig_environ
|
||||
|
||||
|
||||
def test_initialize_environment_with_ssh_command_should_set_environment():
|
||||
orig_environ = os.environ
|
||||
|
||||
try:
|
||||
os.environ = {}
|
||||
module.initialize_environment({'ssh_command': 'ssh -C'})
|
||||
assert os.environ.get('BORG_RSH') == 'ssh -C'
|
||||
finally:
|
||||
os.environ = orig_environ
|
||||
|
||||
|
||||
def test_initialize_environment_without_configuration_should_not_set_environment():
|
||||
orig_environ = os.environ
|
||||
|
||||
try:
|
||||
os.environ = {}
|
||||
module.initialize_environment({})
|
||||
assert os.environ.get('BORG_PASSCOMMAND') == None
|
||||
assert os.environ.get('BORG_PASSPHRASE') == None
|
||||
assert os.environ.get('BORG_RSH') == None
|
||||
finally:
|
||||
os.environ = orig_environ
|
||||
|
||||
|
||||
def test_expand_directory_with_basic_path_passes_it_through():
|
||||
flexmock(module.os.path).should_receive('expanduser').and_return('foo')
|
||||
flexmock(module.glob).should_receive('glob').and_return([])
|
||||
|
||||
paths = module._expand_directory('foo')
|
||||
|
||||
assert paths == ['foo']
|
||||
|
||||
|
||||
def test_expand_directory_with_glob_expands():
|
||||
flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
|
||||
flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
|
||||
|
||||
paths = module._expand_directory('foo*')
|
||||
|
||||
assert paths == ['foo', 'food']
|
||||
|
||||
|
||||
def test_expand_directories_flattens_expanded_directories():
|
||||
flexmock(module).should_receive('_expand_directory').with_args('~/foo').and_return(['/root/foo'])
|
||||
flexmock(module).should_receive('_expand_directory').with_args('bar*').and_return(['bar', 'barf'])
|
||||
|
||||
paths = module._expand_directories(('~/foo', 'bar*'))
|
||||
|
||||
assert paths == ('/root/foo', 'bar', 'barf')
|
||||
|
||||
|
||||
def test_expand_directories_considers_none_as_no_directories():
|
||||
paths = module._expand_directories(None)
|
||||
|
||||
assert paths == ()
|
||||
|
||||
|
||||
def test_write_pattern_file_does_not_raise():
|
||||
temporary_file = flexmock(
|
||||
name='filename',
|
||||
write=lambda mode: None,
|
||||
flush=lambda: None,
|
||||
)
|
||||
flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
|
||||
|
||||
module._write_pattern_file(['exclude'])
|
||||
|
||||
|
||||
def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
|
||||
module._write_pattern_file([])
|
||||
|
||||
|
||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
|
||||
|
||||
|
||||
def test_make_pattern_flags_includes_pattern_filename_when_given():
|
||||
pattern_flags = module._make_pattern_flags(
|
||||
location_config={'patterns': ['R /', '- /var']},
|
||||
pattern_filename='/tmp/patterns',
|
||||
)
|
||||
|
||||
assert pattern_flags == ('--patterns-from', '/tmp/patterns')
|
||||
|
||||
|
||||
def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
|
||||
pattern_flags = module._make_pattern_flags(
|
||||
location_config={'patterns_from': ['patterns', 'other']},
|
||||
)
|
||||
|
||||
assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
|
||||
|
||||
|
||||
def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
|
||||
pattern_flags = module._make_pattern_flags(
|
||||
location_config={'patterns_from': ['patterns']},
|
||||
pattern_filename='/tmp/patterns',
|
||||
)
|
||||
|
||||
assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
|
||||
|
||||
|
||||
def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
|
||||
pattern_flags = module._make_pattern_flags(
|
||||
location_config={'patterns_from': None},
|
||||
)
|
||||
|
||||
assert pattern_flags == ()
|
||||
|
||||
|
||||
def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
|
||||
exclude_flags = module._make_exclude_flags(
|
||||
location_config={'exclude_patterns': ['*.pyc', '/var']},
|
||||
exclude_filename='/tmp/excludes',
|
||||
)
|
||||
|
||||
assert exclude_flags == ('--exclude-from', '/tmp/excludes')
|
||||
|
||||
|
||||
def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
|
||||
|
||||
exclude_flags = module._make_exclude_flags(
|
||||
location_config={'exclude_from': ['excludes', 'other']},
|
||||
)
|
||||
|
||||
assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
|
||||
|
||||
|
||||
def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
|
||||
exclude_flags = module._make_exclude_flags(
|
||||
location_config={'exclude_from': ['excludes']},
|
||||
exclude_filename='/tmp/excludes',
|
||||
)
|
||||
|
||||
assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
|
||||
|
||||
|
||||
def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
|
||||
exclude_flags = module._make_exclude_flags(
|
||||
location_config={'exclude_from': None},
|
||||
)
|
||||
|
||||
assert exclude_flags == ()
|
||||
|
||||
|
||||
def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
|
||||
exclude_flags = module._make_exclude_flags(
|
||||
location_config={'exclude_caches': True},
|
||||
)
|
||||
|
||||
assert exclude_flags == ('--exclude-caches',)
|
||||
|
||||
|
||||
def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
|
||||
exclude_flags = module._make_exclude_flags(
|
||||
location_config={'exclude_caches': False},
|
||||
)
|
||||
|
||||
assert exclude_flags == ()
|
||||
|
||||
|
||||
def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
|
||||
exclude_flags = module._make_exclude_flags(
|
||||
location_config={'exclude_if_present': 'exclude_me'},
|
||||
)
|
||||
|
||||
assert exclude_flags == ('--exclude-if-present', 'exclude_me')
|
||||
|
||||
|
||||
def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
|
||||
exclude_flags = module._make_exclude_flags(location_config={})
|
||||
|
||||
assert exclude_flags == ()
|
||||
|
||||
|
||||
DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
|
||||
CREATE_COMMAND = ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar')
|
||||
|
||||
|
||||
def test_create_archive_calls_borg_with_parameters():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND)
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_patterns_calls_borg_with_patterns():
|
||||
pattern_flags = ('--patterns-from', 'patterns')
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(flexmock(name='/tmp/patterns')).and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + pattern_flags)
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'patterns': ['pattern'],
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
|
||||
exclude_flags = ('--exclude-from', 'excludes')
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(('exclude',))
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None).and_return(flexmock(name='/tmp/excludes'))
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
|
||||
insert_subprocess_mock(CREATE_COMMAND + exclude_flags)
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': ['exclude'],
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_log_info_calls_borg_with_info_parameter():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--stats',))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME','--stats', '--debug', '--show-rc'))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--dry-run',))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=True,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_parameter():
|
||||
""" --dry-run and --stats are mutually exclusive, see:
|
||||
https://borgbackup.readthedocs.io/en/stable/usage/create.html#description """
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--info', '--dry-run'))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.create_archive(
|
||||
dry_run=True,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_parameter():
|
||||
""" --dry-run and --stats are mutually exclusive, see:
|
||||
https://borgbackup.readthedocs.io/en/stable/usage/create.html#description """
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME', '--debug', '--show-rc', '--dry-run'))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.create_archive(
|
||||
dry_run=True,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--checkpoint-interval', '600'))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={'checkpoint_interval': 600},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_compression_calls_borg_with_compression_parameters():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--compression', 'rle'))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={'compression': 'rle'},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_parameters():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--remote-ratelimit', '100'))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={'remote_rate_limit': 100},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameters():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--one-file-system',))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'one_file_system': True,
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--read-special',))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'read_special': True,
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_bsd_flags_true_calls_borg_without_nobsdflags_parameter():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND)
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'bsd_flags': True,
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_bsd_flags_false_calls_borg_with_nobsdflags_parameter():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--nobsdflags',))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'bsd_flags': False,
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--files-cache', 'ctime,size'))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'files_cache': 'ctime,size',
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_local_path_calls_borg_via_local_path():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(('borg1',) + CREATE_COMMAND[1:])
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--remote-path', 'borg1'))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_umask_calls_borg_with_umask_parameters():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--umask', '740'))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={'umask': 740},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--lock-wait', '5'))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={'lock_wait': 5},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_json_calls_borg_with_json_parameter():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--json',))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
json=True
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_source_directories_glob_expands():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'))
|
||||
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo*'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_non_matching_source_directories_glob_passes_through():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo*',)).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'))
|
||||
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo*'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_glob_calls_borg_with_expanded_directories():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo*'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return(())
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={
|
||||
'archive_name_format': 'ARCHIVE_NAME',
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
|
||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar')).and_return([])
|
||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||
insert_subprocess_mock(('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'))
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={
|
||||
'archive_name_format': 'Documents_{hostname}-{now}',
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,136 @@
|
||||
import logging, sys
|
||||
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.borg import extract as module
|
||||
from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
|
||||
from borgmatic.tests.unit.test_verbosity import insert_logging_mock
|
||||
|
||||
|
||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
|
||||
|
||||
|
||||
def insert_subprocess_never():
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_call').never()
|
||||
|
||||
|
||||
def insert_subprocess_check_output_mock(check_output_command, result, **kwargs):
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_output').with_args(check_output_command, **kwargs).and_return(result).once()
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_should_call_borg_with_last_archive():
|
||||
flexmock(sys.stdout).encoding = 'utf-8'
|
||||
insert_subprocess_check_output_mock(
|
||||
('borg', 'list', '--short', 'repo'),
|
||||
result='archive1\narchive2\n'.encode('utf-8'),
|
||||
)
|
||||
insert_subprocess_mock(
|
||||
('borg', 'extract', '--dry-run', 'repo::archive2'),
|
||||
)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
repository='repo',
|
||||
lock_wait=None,
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_without_any_archives_should_bail():
|
||||
flexmock(sys.stdout).encoding = 'utf-8'
|
||||
insert_subprocess_check_output_mock(
|
||||
('borg', 'list', '--short', 'repo'),
|
||||
result='\n'.encode('utf-8'),
|
||||
)
|
||||
insert_subprocess_never()
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
repository='repo',
|
||||
lock_wait=None,
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_with_log_info_should_call_borg_with_info_parameter():
|
||||
flexmock(sys.stdout).encoding = 'utf-8'
|
||||
insert_subprocess_check_output_mock(
|
||||
('borg', 'list', '--short', 'repo', '--info'),
|
||||
result='archive1\narchive2\n'.encode('utf-8'),
|
||||
)
|
||||
insert_subprocess_mock(
|
||||
('borg', 'extract', '--dry-run', 'repo::archive2', '--info'),
|
||||
)
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
repository='repo',
|
||||
lock_wait=None,
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_with_log_debug_should_call_borg_with_debug_parameter():
|
||||
flexmock(sys.stdout).encoding = 'utf-8'
|
||||
insert_subprocess_check_output_mock(
|
||||
('borg', 'list', '--short', 'repo', '--debug', '--show-rc'),
|
||||
result='archive1\narchive2\n'.encode('utf-8'),
|
||||
)
|
||||
insert_subprocess_mock(
|
||||
('borg', 'extract', '--dry-run', 'repo::archive2', '--debug', '--show-rc', '--list'),
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
repository='repo',
|
||||
lock_wait=None,
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_should_call_borg_via_local_path():
|
||||
flexmock(sys.stdout).encoding = 'utf-8'
|
||||
insert_subprocess_check_output_mock(
|
||||
('borg1', 'list', '--short', 'repo'),
|
||||
result='archive1\narchive2\n'.encode('utf-8'),
|
||||
)
|
||||
insert_subprocess_mock(
|
||||
('borg1', 'extract', '--dry-run', 'repo::archive2'),
|
||||
)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
repository='repo',
|
||||
lock_wait=None,
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_should_call_borg_with_remote_path_parameters():
|
||||
flexmock(sys.stdout).encoding = 'utf-8'
|
||||
insert_subprocess_check_output_mock(
|
||||
('borg', 'list', '--short', 'repo', '--remote-path', 'borg1'),
|
||||
result='archive1\narchive2\n'.encode('utf-8'),
|
||||
)
|
||||
insert_subprocess_mock(
|
||||
('borg', 'extract', '--dry-run', 'repo::archive2', '--remote-path', 'borg1'),
|
||||
)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
repository='repo',
|
||||
lock_wait=None,
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_should_call_borg_with_lock_wait_parameters():
|
||||
flexmock(sys.stdout).encoding = 'utf-8'
|
||||
insert_subprocess_check_output_mock(
|
||||
('borg', 'list', '--short', 'repo', '--lock-wait', '5'),
|
||||
result='archive1\narchive2\n'.encode('utf-8'),
|
||||
)
|
||||
insert_subprocess_mock(
|
||||
('borg', 'extract', '--dry-run', 'repo::archive2', '--lock-wait', '5'),
|
||||
)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
repository='repo',
|
||||
lock_wait=5,
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.commands import hook as module
|
||||
|
||||
|
||||
def test_execute_hook_invokes_each_command():
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_call').with_args(':', shell=True).once()
|
||||
|
||||
module.execute_hook([':'], 'config.yaml', 'pre-backup')
|
||||
|
||||
|
||||
def test_execute_hook_with_multiple_commands_invokes_each_command():
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_call').with_args(':', shell=True).once()
|
||||
subprocess.should_receive('check_call').with_args('true', shell=True).once()
|
||||
|
||||
module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup')
|
||||
|
||||
|
||||
def test_execute_hook_with_empty_commands_does_not_raise():
|
||||
module.execute_hook([], 'config.yaml', 'post-backup')
|
||||
@@ -0,0 +1,83 @@
|
||||
import logging
|
||||
from collections import OrderedDict
|
||||
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.borg import info as module
|
||||
from borgmatic.tests.unit.test_verbosity import insert_logging_mock
|
||||
|
||||
|
||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_output').with_args(check_call_command, **kwargs).once()
|
||||
|
||||
|
||||
INFO_COMMAND = ('borg', 'info', 'repo')
|
||||
|
||||
|
||||
def test_display_archives_info_calls_borg_with_parameters():
|
||||
insert_subprocess_mock(INFO_COMMAND)
|
||||
|
||||
module.display_archives_info(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
|
||||
insert_subprocess_mock(INFO_COMMAND + ('--info',))
|
||||
insert_logging_mock(logging.INFO)
|
||||
module.display_archives_info(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
|
||||
insert_subprocess_mock(INFO_COMMAND + ('--debug', '--show-rc'))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.display_archives_info(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_with_json_calls_borg_with_json_parameter():
|
||||
insert_subprocess_mock(INFO_COMMAND + ('--json',))
|
||||
|
||||
module.display_archives_info(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
json=True,
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_with_local_path_calls_borg_via_local_path():
|
||||
insert_subprocess_mock(('borg1',) + INFO_COMMAND[1:])
|
||||
|
||||
module.display_archives_info(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||
insert_subprocess_mock(INFO_COMMAND + ('--remote-path', 'borg1'))
|
||||
|
||||
module.display_archives_info(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
storage_config = {'lock_wait': 5}
|
||||
insert_subprocess_mock(INFO_COMMAND + ('--lock-wait', '5'))
|
||||
|
||||
module.display_archives_info(
|
||||
repository='repo',
|
||||
storage_config=storage_config,
|
||||
)
|
||||
@@ -0,0 +1,84 @@
|
||||
import logging
|
||||
from collections import OrderedDict
|
||||
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.borg import list as module
|
||||
from borgmatic.tests.unit.test_verbosity import insert_logging_mock
|
||||
|
||||
|
||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_output').with_args(check_call_command, **kwargs).once()
|
||||
|
||||
|
||||
LIST_COMMAND = ('borg', 'list', 'repo')
|
||||
|
||||
|
||||
def test_list_archives_calls_borg_with_parameters():
|
||||
insert_subprocess_mock(LIST_COMMAND)
|
||||
|
||||
module.list_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_list_archives_with_log_info_calls_borg_with_info_parameter():
|
||||
insert_subprocess_mock(LIST_COMMAND + ('--info',))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.list_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_list_archives_with_log_debug_calls_borg_with_debug_parameter():
|
||||
insert_subprocess_mock(LIST_COMMAND + ('--debug', '--show-rc'))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.list_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
)
|
||||
|
||||
|
||||
def test_list_archives_with_json_calls_borg_with_json_parameter():
|
||||
insert_subprocess_mock(LIST_COMMAND + ('--json',))
|
||||
|
||||
module.list_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
json=True,
|
||||
)
|
||||
|
||||
|
||||
def test_list_archives_with_local_path_calls_borg_via_local_path():
|
||||
insert_subprocess_mock(('borg1',) + LIST_COMMAND[1:])
|
||||
|
||||
module.list_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_list_archives_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||
insert_subprocess_mock(LIST_COMMAND + ('--remote-path', 'borg1'))
|
||||
|
||||
module.list_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_list_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
storage_config = {'lock_wait': 5}
|
||||
insert_subprocess_mock(LIST_COMMAND + ('--lock-wait', '5'))
|
||||
|
||||
module.list_archives(
|
||||
repository='repo',
|
||||
storage_config=storage_config,
|
||||
)
|
||||
@@ -0,0 +1,183 @@
|
||||
import logging
|
||||
from collections import OrderedDict
|
||||
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.borg import prune as module
|
||||
from borgmatic.tests.unit.test_verbosity import insert_logging_mock
|
||||
|
||||
|
||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
||||
subprocess = flexmock(module.subprocess)
|
||||
subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
|
||||
|
||||
|
||||
|
||||
BASE_PRUNE_FLAGS = (
|
||||
('--keep-daily', '1'),
|
||||
('--keep-weekly', '2'),
|
||||
('--keep-monthly', '3'),
|
||||
)
|
||||
|
||||
|
||||
def test_make_prune_flags_returns_flags_from_config_plus_default_prefix():
|
||||
retention_config = OrderedDict(
|
||||
(
|
||||
('keep_daily', 1),
|
||||
('keep_weekly', 2),
|
||||
('keep_monthly', 3),
|
||||
)
|
||||
)
|
||||
|
||||
result = module._make_prune_flags(retention_config)
|
||||
|
||||
assert tuple(result) == BASE_PRUNE_FLAGS + (('--prefix', '{hostname}-'),)
|
||||
|
||||
|
||||
def test_make_prune_flags_accepts_prefix_with_placeholders():
|
||||
retention_config = OrderedDict(
|
||||
(
|
||||
('keep_daily', 1),
|
||||
('prefix', 'Documents_{hostname}-{now}'),
|
||||
)
|
||||
)
|
||||
|
||||
result = module._make_prune_flags(retention_config)
|
||||
|
||||
expected = (
|
||||
('--keep-daily', '1'),
|
||||
('--prefix', 'Documents_{hostname}-{now}'),
|
||||
)
|
||||
|
||||
assert tuple(result) == expected
|
||||
|
||||
|
||||
PRUNE_COMMAND = (
|
||||
'borg', 'prune', 'repo', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3',
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_calls_borg_with_parameters():
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND)
|
||||
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
retention_config=retention_config,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_log_info_calls_borg_with_info_parameter():
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND + ('--stats', '--info',))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.prune_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
dry_run=False,
|
||||
retention_config=retention_config,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND + ('--stats', '--debug', '--list', '--show-rc'))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.prune_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
dry_run=False,
|
||||
retention_config=retention_config,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter():
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND + ('--dry-run',))
|
||||
|
||||
module.prune_archives(
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
dry_run=True,
|
||||
retention_config=retention_config,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_local_path_calls_borg_via_local_path():
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(('borg1',) + PRUNE_COMMAND[1:])
|
||||
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
retention_config=retention_config,
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND + ('--remote-path', 'borg1'))
|
||||
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
storage_config={},
|
||||
retention_config=retention_config,
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_umask_calls_borg_with_umask_parameters():
|
||||
storage_config = {'umask': '077'}
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND + ('--umask', '077'))
|
||||
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
storage_config=storage_config,
|
||||
retention_config=retention_config,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
storage_config = {'lock_wait': 5}
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND + ('--lock-wait', '5'))
|
||||
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
storage_config=storage_config,
|
||||
retention_config=retention_config,
|
||||
)
|
||||
@@ -0,0 +1,52 @@
|
||||
import json
|
||||
import sys
|
||||
|
||||
from flexmock import flexmock
|
||||
import pytest
|
||||
|
||||
from borgmatic.commands import borgmatic
|
||||
|
||||
|
||||
def test__run_commands_handles_multiple_json_outputs_in_array():
|
||||
(
|
||||
flexmock(borgmatic)
|
||||
.should_receive('_run_commands_on_repository')
|
||||
.times(3)
|
||||
.replace_with(
|
||||
lambda args, consistency, json_results, local_path, location, remote_path, retention,
|
||||
storage,
|
||||
unexpanded_repository: json_results.append({"whatever": unexpanded_repository})
|
||||
)
|
||||
)
|
||||
|
||||
(
|
||||
flexmock(sys.stdout)
|
||||
.should_call("write")
|
||||
.with_args(
|
||||
json.dumps(
|
||||
json.loads(
|
||||
'''
|
||||
[
|
||||
{"whatever": "fake_repo1"},
|
||||
{"whatever": "fake_repo2"},
|
||||
{"whatever": "fake_repo3"}
|
||||
]
|
||||
''',
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
borgmatic._run_commands(
|
||||
args=flexmock(json=True),
|
||||
consistency=None,
|
||||
local_path=None,
|
||||
location={'repositories': [
|
||||
'fake_repo1',
|
||||
'fake_repo2',
|
||||
'fake_repo3'
|
||||
]},
|
||||
remote_path=None,
|
||||
retention=None,
|
||||
storage=None,
|
||||
)
|
||||
@@ -0,0 +1,115 @@
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.config import collect as module
|
||||
|
||||
|
||||
def test_get_default_config_paths_includes_absolute_user_config_path():
|
||||
flexmock(module.os, environ={'XDG_CONFIG_HOME': None, 'HOME': '/home/user'})
|
||||
|
||||
config_paths = module.get_default_config_paths()
|
||||
|
||||
assert '/home/user/.config/borgmatic/config.yaml' in config_paths
|
||||
|
||||
|
||||
def test_get_default_config_paths_prefers_xdg_config_home_for_user_config_path():
|
||||
flexmock(module.os, environ={'XDG_CONFIG_HOME': '/home/user/.etc', 'HOME': '/home/user'})
|
||||
|
||||
config_paths = module.get_default_config_paths()
|
||||
|
||||
assert '/home/user/.etc/borgmatic/config.yaml' in config_paths
|
||||
|
||||
|
||||
def test_collect_config_filenames_collects_given_files():
|
||||
config_paths = ('config.yaml', 'other.yaml')
|
||||
flexmock(module.os.path).should_receive('isdir').and_return(False)
|
||||
|
||||
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
||||
|
||||
assert config_filenames == config_paths
|
||||
|
||||
|
||||
def test_collect_config_filenames_collects_files_from_given_directories_and_ignores_sub_directories():
|
||||
config_paths = ('config.yaml', '/etc/borgmatic.d')
|
||||
mock_path = flexmock(module.os.path)
|
||||
mock_path.should_receive('exists').and_return(True)
|
||||
mock_path.should_receive('isdir').with_args('config.yaml').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d').and_return(True)
|
||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar').and_return(True)
|
||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.yaml').and_return(False)
|
||||
flexmock(module.os).should_receive('listdir').and_return(['foo.yaml', 'bar', 'baz.yaml'])
|
||||
|
||||
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
||||
|
||||
assert config_filenames == (
|
||||
'config.yaml',
|
||||
'/etc/borgmatic.d/foo.yaml',
|
||||
'/etc/borgmatic.d/baz.yaml',
|
||||
)
|
||||
|
||||
|
||||
def test_collect_config_filenames_collects_files_from_given_directories_and_ignores_non_yaml_filenames():
|
||||
config_paths = ('/etc/borgmatic.d',)
|
||||
mock_path = flexmock(module.os.path)
|
||||
mock_path.should_receive('exists').and_return(True)
|
||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d').and_return(True)
|
||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar.yaml~').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.txt').and_return(False)
|
||||
flexmock(module.os).should_receive('listdir').and_return(['foo.yaml', 'bar.yaml~', 'baz.txt'])
|
||||
|
||||
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
||||
|
||||
assert config_filenames == ('/etc/borgmatic.d/foo.yaml',)
|
||||
|
||||
|
||||
def test_collect_config_filenames_skips_etc_borgmatic_config_dot_yaml_if_it_does_not_exist():
|
||||
config_paths = ('config.yaml', '/etc/borgmatic/config.yaml')
|
||||
mock_path = flexmock(module.os.path)
|
||||
mock_path.should_receive('exists').with_args('config.yaml').and_return(True)
|
||||
mock_path.should_receive('exists').with_args('/etc/borgmatic/config.yaml').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('config.yaml').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic/config.yaml').and_return(True)
|
||||
|
||||
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
||||
|
||||
assert config_filenames == ('config.yaml',)
|
||||
|
||||
|
||||
def test_collect_config_filenames_skips_etc_borgmatic_dot_d_if_it_does_not_exist():
|
||||
config_paths = ('config.yaml', '/etc/borgmatic.d')
|
||||
mock_path = flexmock(module.os.path)
|
||||
mock_path.should_receive('exists').with_args('config.yaml').and_return(True)
|
||||
mock_path.should_receive('exists').with_args('/etc/borgmatic.d').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('config.yaml').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d').and_return(True)
|
||||
|
||||
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
||||
|
||||
assert config_filenames == ('config.yaml',)
|
||||
|
||||
|
||||
def test_collect_config_filenames_skips_non_canonical_etc_borgmatic_dot_d_if_it_does_not_exist():
|
||||
config_paths = ('config.yaml', '/etc/../etc/borgmatic.d')
|
||||
mock_path = flexmock(module.os.path)
|
||||
mock_path.should_receive('exists').with_args('config.yaml').and_return(True)
|
||||
mock_path.should_receive('exists').with_args('/etc/../etc/borgmatic.d').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('config.yaml').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('/etc/../etc/borgmatic.d').and_return(True)
|
||||
|
||||
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
||||
|
||||
assert config_filenames == ('config.yaml',)
|
||||
|
||||
|
||||
def test_collect_config_filenames_includes_other_directory_if_it_does_not_exist():
|
||||
config_paths = ('config.yaml', '/my/directory')
|
||||
mock_path = flexmock(module.os.path)
|
||||
mock_path.should_receive('exists').with_args('config.yaml').and_return(True)
|
||||
mock_path.should_receive('exists').with_args('/my/directory').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('config.yaml').and_return(False)
|
||||
mock_path.should_receive('isdir').with_args('/my/directory').and_return(True)
|
||||
|
||||
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
||||
|
||||
assert config_filenames == config_paths
|
||||
@@ -79,30 +79,34 @@ def test_convert_legacy_parsed_config_splits_space_separated_values():
|
||||
def test_guard_configuration_upgraded_raises_when_only_source_config_present():
|
||||
flexmock(os.path).should_receive('exists').with_args('config').and_return(True)
|
||||
flexmock(os.path).should_receive('exists').with_args('config.yaml').and_return(False)
|
||||
flexmock(os.path).should_receive('exists').with_args('other.yaml').and_return(False)
|
||||
|
||||
with pytest.raises(module.LegacyConfigurationNotUpgraded):
|
||||
module.guard_configuration_upgraded('config', 'config.yaml')
|
||||
module.guard_configuration_upgraded('config', ('config.yaml', 'other.yaml'))
|
||||
|
||||
|
||||
def test_guard_configuration_upgraded_does_not_raise_when_only_destination_config_present():
|
||||
flexmock(os.path).should_receive('exists').with_args('config').and_return(False)
|
||||
flexmock(os.path).should_receive('exists').with_args('config.yaml').and_return(True)
|
||||
flexmock(os.path).should_receive('exists').with_args('config.yaml').and_return(False)
|
||||
flexmock(os.path).should_receive('exists').with_args('other.yaml').and_return(True)
|
||||
|
||||
module.guard_configuration_upgraded('config', 'config.yaml')
|
||||
module.guard_configuration_upgraded('config', ('config.yaml', 'other.yaml'))
|
||||
|
||||
|
||||
def test_guard_configuration_upgraded_does_not_raise_when_both_configs_present():
|
||||
flexmock(os.path).should_receive('exists').with_args('config').and_return(True)
|
||||
flexmock(os.path).should_receive('exists').with_args('config.yaml').and_return(True)
|
||||
flexmock(os.path).should_receive('exists').with_args('config.yaml').and_return(False)
|
||||
flexmock(os.path).should_receive('exists').with_args('other.yaml').and_return(True)
|
||||
|
||||
module.guard_configuration_upgraded('config', 'config.yaml')
|
||||
module.guard_configuration_upgraded('config', ('config.yaml', 'other.yaml'))
|
||||
|
||||
|
||||
def test_guard_configuration_upgraded_does_not_raise_when_neither_config_present():
|
||||
flexmock(os.path).should_receive('exists').with_args('config').and_return(False)
|
||||
flexmock(os.path).should_receive('exists').with_args('config.yaml').and_return(False)
|
||||
flexmock(os.path).should_receive('exists').with_args('other.yaml').and_return(False)
|
||||
|
||||
module.guard_configuration_upgraded('config', 'config.yaml')
|
||||
module.guard_configuration_upgraded('config', ('config.yaml', 'other.yaml'))
|
||||
|
||||
|
||||
def test_guard_excludes_filename_omitted_raises_when_filename_provided():
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import pytest
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.config import validate as module
|
||||
|
||||
|
||||
def test_validation_error_str_contains_error_messages_and_config_filename():
|
||||
error = module.Validation_error('config.yaml', ('oops', 'uh oh'))
|
||||
|
||||
result = str(error)
|
||||
|
||||
assert 'config.yaml' in result
|
||||
assert 'oops' in result
|
||||
assert 'uh oh' in result
|
||||
|
||||
|
||||
def test_apply_logical_validation_raises_if_archive_name_format_present_without_prefix():
|
||||
with pytest.raises(module.Validation_error):
|
||||
module.apply_logical_validation(
|
||||
'config.yaml',
|
||||
{
|
||||
'storage': {'archive_name_format': '{hostname}-{now}'},
|
||||
'retention': {'keep_daily': 7},
|
||||
},
|
||||
)
|
||||
|
||||
def test_apply_logical_validation_raises_if_archive_name_format_present_without_retention_prefix():
|
||||
with pytest.raises(module.Validation_error):
|
||||
module.apply_logical_validation(
|
||||
'config.yaml',
|
||||
{
|
||||
'storage': {'archive_name_format': '{hostname}-{now}'},
|
||||
'retention': {'keep_daily': 7},
|
||||
'consistency': {'prefix': '{hostname}-'}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_apply_logical_validation_warns_if_archive_name_format_present_without_consistency_prefix():
|
||||
logger = flexmock(module.logger)
|
||||
logger.should_receive('warning').once()
|
||||
|
||||
module.apply_logical_validation(
|
||||
'config.yaml',
|
||||
{
|
||||
'storage': {'archive_name_format': '{hostname}-{now}'},
|
||||
'retention': {'prefix': '{hostname}-'},
|
||||
'consistency': {},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_apply_logical_validation_does_not_raise_or_warn_if_archive_name_format_and_prefix_present():
|
||||
logger = flexmock(module.logger)
|
||||
logger.should_receive('warning').never()
|
||||
|
||||
module.apply_logical_validation(
|
||||
'config.yaml',
|
||||
{
|
||||
'storage': {'archive_name_format': '{hostname}-{now}'},
|
||||
'retention': {'prefix': '{hostname}-'},
|
||||
'consistency': {'prefix': '{hostname}-'}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_apply_logical_validation_does_not_raise_otherwise():
|
||||
module.apply_logical_validation(
|
||||
'config.yaml',
|
||||
{
|
||||
'retention': {'keep_secondly': 1000},
|
||||
},
|
||||
)
|
||||
@@ -1,518 +0,0 @@
|
||||
from collections import OrderedDict
|
||||
from subprocess import STDOUT
|
||||
import sys
|
||||
import os
|
||||
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic import borg as module
|
||||
from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
|
||||
|
||||
|
||||
def test_initialize_with_passphrase_should_set_environment():
|
||||
orig_environ = os.environ
|
||||
|
||||
try:
|
||||
os.environ = {}
|
||||
module.initialize({'encryption_passphrase': 'pass'}, command='borg')
|
||||
assert os.environ.get('BORG_PASSPHRASE') == 'pass'
|
||||
finally:
|
||||
os.environ = orig_environ
|
||||
|
||||
|
||||
def test_initialize_without_passphrase_should_not_set_environment():
|
||||
orig_environ = os.environ
|
||||
|
||||
try:
|
||||
os.environ = {}
|
||||
module.initialize({}, command='borg')
|
||||
assert os.environ.get('BORG_PASSPHRASE') == None
|
||||
finally:
|
||||
os.environ = orig_environ
|
||||
|
||||
def test_write_exclude_file_does_not_raise():
|
||||
temporary_file = flexmock(
|
||||
name='filename',
|
||||
write=lambda mode: None,
|
||||
flush=lambda: None,
|
||||
)
|
||||
flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
|
||||
|
||||
module._write_exclude_file(['exclude'])
|
||||
|
||||
|
||||
def test_write_exclude_file_with_empty_exclude_patterns_does_not_raise():
|
||||
module._write_exclude_file([])
|
||||
|
||||
|
||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
||||
subprocess = flexmock(STDOUT=STDOUT)
|
||||
subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
|
||||
flexmock(module).subprocess = subprocess
|
||||
|
||||
|
||||
def insert_subprocess_never():
|
||||
subprocess = flexmock()
|
||||
subprocess.should_receive('check_call').never()
|
||||
flexmock(module).subprocess = subprocess
|
||||
|
||||
|
||||
def insert_platform_mock():
|
||||
flexmock(module.platform).should_receive('node').and_return('host')
|
||||
|
||||
|
||||
def insert_datetime_mock():
|
||||
flexmock(module).datetime = flexmock().should_receive('now').and_return(
|
||||
flexmock().should_receive('isoformat').and_return('now').mock
|
||||
).mock
|
||||
|
||||
|
||||
CREATE_COMMAND = ('borg', 'create', 'repo::host-now', 'foo', 'bar')
|
||||
|
||||
|
||||
def test_create_archive_should_call_borg_with_parameters():
|
||||
flexmock(module).should_receive('_write_exclude_file')
|
||||
insert_subprocess_mock(CREATE_COMMAND)
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
|
||||
module.create_archive(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_exclude_patterns_should_call_borg_with_excludes():
|
||||
flexmock(module).should_receive('_write_exclude_file').and_return(flexmock(name='excludes'))
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--exclude-from', 'excludes'))
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
|
||||
module.create_archive(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': ['exclude'],
|
||||
},
|
||||
storage_config={},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_verbosity_some_should_call_borg_with_info_parameter():
|
||||
flexmock(module).should_receive('_write_exclude_file')
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--info', '--stats',))
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
|
||||
module.create_archive(
|
||||
verbosity=VERBOSITY_SOME,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_verbosity_lots_should_call_borg_with_debug_parameter():
|
||||
flexmock(module).should_receive('_write_exclude_file')
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--debug', '--list', '--stats'))
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
|
||||
module.create_archive(
|
||||
verbosity=VERBOSITY_LOTS,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_compression_should_call_borg_with_compression_parameters():
|
||||
flexmock(module).should_receive('_write_exclude_file')
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--compression', 'rle'))
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
|
||||
module.create_archive(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={'compression': 'rle'},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_one_file_system_should_call_borg_with_one_file_system_parameters():
|
||||
flexmock(module).should_receive('_write_exclude_file')
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--one-file-system',))
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
|
||||
module.create_archive(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'one_file_system': True,
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_remote_path_should_call_borg_with_remote_path_parameters():
|
||||
flexmock(module).should_receive('_write_exclude_file')
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--remote-path', 'borg1'))
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
|
||||
module.create_archive(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'remote_path': 'borg1',
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_umask_should_call_borg_with_umask_parameters():
|
||||
flexmock(module).should_receive('_write_exclude_file')
|
||||
insert_subprocess_mock(CREATE_COMMAND + ('--umask', '740'))
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
|
||||
module.create_archive(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={'umask': 740},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_source_directories_glob_expands():
|
||||
flexmock(module).should_receive('_write_exclude_file')
|
||||
insert_subprocess_mock(('borg', 'create', 'repo::host-now', 'foo', 'food'))
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
|
||||
|
||||
module.create_archive(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo*'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_non_matching_source_directories_glob_passes_through():
|
||||
flexmock(module).should_receive('_write_exclude_file')
|
||||
insert_subprocess_mock(('borg', 'create', 'repo::host-now', 'foo*'))
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
|
||||
|
||||
module.create_archive(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo*'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_glob_should_call_borg_with_expanded_directories():
|
||||
flexmock(module).should_receive('_write_exclude_file')
|
||||
insert_subprocess_mock(('borg', 'create', 'repo::host-now', 'foo', 'food'))
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
|
||||
|
||||
module.create_archive(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo*'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
BASE_PRUNE_FLAGS = (
|
||||
('--keep-daily', '1'),
|
||||
('--keep-weekly', '2'),
|
||||
('--keep-monthly', '3'),
|
||||
)
|
||||
|
||||
|
||||
def test_make_prune_flags_should_return_flags_from_config():
|
||||
retention_config = OrderedDict(
|
||||
(
|
||||
('keep_daily', 1),
|
||||
('keep_weekly', 2),
|
||||
('keep_monthly', 3),
|
||||
)
|
||||
)
|
||||
|
||||
result = module._make_prune_flags(retention_config)
|
||||
|
||||
assert tuple(result) == BASE_PRUNE_FLAGS
|
||||
|
||||
|
||||
PRUNE_COMMAND = (
|
||||
'borg', 'prune', 'repo', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3',
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_should_call_borg_with_parameters():
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND)
|
||||
|
||||
module.prune_archives(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
retention_config=retention_config,
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_verbosity_some_should_call_borg_with_info_parameter():
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND + ('--info', '--stats',))
|
||||
|
||||
module.prune_archives(
|
||||
repository='repo',
|
||||
verbosity=VERBOSITY_SOME,
|
||||
retention_config=retention_config,
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_verbosity_lots_should_call_borg_with_debug_parameter():
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND + ('--debug', '--stats',))
|
||||
|
||||
module.prune_archives(
|
||||
repository='repo',
|
||||
verbosity=VERBOSITY_LOTS,
|
||||
retention_config=retention_config,
|
||||
command='borg',
|
||||
)
|
||||
|
||||
def test_prune_archive_with_remote_path_should_call_borg_with_remote_path_parameters():
|
||||
retention_config = flexmock()
|
||||
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||
BASE_PRUNE_FLAGS,
|
||||
)
|
||||
insert_subprocess_mock(PRUNE_COMMAND + ('--remote-path', 'borg1'))
|
||||
|
||||
module.prune_archives(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
retention_config=retention_config,
|
||||
command='borg',
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_parse_checks_returns_them_as_tuple():
|
||||
checks = module._parse_checks({'checks': ['foo', 'disabled', 'bar']})
|
||||
|
||||
assert checks == ('foo', 'bar')
|
||||
|
||||
|
||||
def test_parse_checks_with_missing_value_returns_defaults():
|
||||
checks = module._parse_checks({})
|
||||
|
||||
assert checks == module.DEFAULT_CHECKS
|
||||
|
||||
|
||||
def test_parse_checks_with_blank_value_returns_defaults():
|
||||
checks = module._parse_checks({'checks': []})
|
||||
|
||||
assert checks == module.DEFAULT_CHECKS
|
||||
|
||||
|
||||
def test_parse_checks_with_disabled_returns_no_checks():
|
||||
checks = module._parse_checks({'checks': ['disabled']})
|
||||
|
||||
assert checks == ()
|
||||
|
||||
|
||||
def test_make_check_flags_with_checks_returns_flags():
|
||||
flags = module._make_check_flags(('foo', 'bar'))
|
||||
|
||||
assert flags == ('--foo-only', '--bar-only')
|
||||
|
||||
|
||||
def test_make_check_flags_with_default_checks_returns_no_flags():
|
||||
flags = module._make_check_flags(module.DEFAULT_CHECKS)
|
||||
|
||||
assert flags == ()
|
||||
|
||||
|
||||
def test_make_check_flags_with_checks_and_last_returns_flags_including_last():
|
||||
flags = module._make_check_flags(('foo', 'bar'), check_last=3)
|
||||
|
||||
assert flags == ('--foo-only', '--bar-only', '--last', '3')
|
||||
|
||||
|
||||
def test_make_check_flags_with_last_returns_last_flag():
|
||||
flags = module._make_check_flags(module.DEFAULT_CHECKS, check_last=3)
|
||||
|
||||
assert flags == ('--last', '3')
|
||||
|
||||
|
||||
def test_check_archives_should_call_borg_with_parameters():
|
||||
checks = flexmock()
|
||||
check_last = flexmock()
|
||||
consistency_config = flexmock().should_receive('get').and_return(check_last).mock
|
||||
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||
flexmock(module).should_receive('_make_check_flags').with_args(checks, check_last).and_return(())
|
||||
stdout = flexmock()
|
||||
insert_subprocess_mock(
|
||||
('borg', 'check', 'repo'),
|
||||
stdout=stdout, stderr=STDOUT,
|
||||
)
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
flexmock(sys.modules['builtins']).should_receive('open').and_return(stdout)
|
||||
flexmock(module.os).should_receive('devnull')
|
||||
|
||||
module.check_archives(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
consistency_config=consistency_config,
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_verbosity_some_should_call_borg_with_info_parameter():
|
||||
consistency_config = flexmock().should_receive('get').and_return(None).mock
|
||||
flexmock(module).should_receive('_parse_checks').and_return(flexmock())
|
||||
flexmock(module).should_receive('_make_check_flags').and_return(())
|
||||
insert_subprocess_mock(
|
||||
('borg', 'check', 'repo', '--info'),
|
||||
stdout=None, stderr=STDOUT,
|
||||
)
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
|
||||
module.check_archives(
|
||||
verbosity=VERBOSITY_SOME,
|
||||
repository='repo',
|
||||
consistency_config=consistency_config,
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_verbosity_lots_should_call_borg_with_debug_parameter():
|
||||
consistency_config = flexmock().should_receive('get').and_return(None).mock
|
||||
flexmock(module).should_receive('_parse_checks').and_return(flexmock())
|
||||
flexmock(module).should_receive('_make_check_flags').and_return(())
|
||||
insert_subprocess_mock(
|
||||
('borg', 'check', 'repo', '--debug'),
|
||||
stdout=None, stderr=STDOUT,
|
||||
)
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
|
||||
module.check_archives(
|
||||
verbosity=VERBOSITY_LOTS,
|
||||
repository='repo',
|
||||
consistency_config=consistency_config,
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_without_any_checks_should_bail():
|
||||
consistency_config = flexmock().should_receive('get').and_return(None).mock
|
||||
flexmock(module).should_receive('_parse_checks').and_return(())
|
||||
insert_subprocess_never()
|
||||
|
||||
module.check_archives(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
consistency_config=consistency_config,
|
||||
command='borg',
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_remote_path_should_call_borg_with_remote_path_parameters():
|
||||
checks = flexmock()
|
||||
check_last = flexmock()
|
||||
consistency_config = flexmock().should_receive('get').and_return(check_last).mock
|
||||
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||
flexmock(module).should_receive('_make_check_flags').with_args(checks, check_last).and_return(())
|
||||
stdout = flexmock()
|
||||
insert_subprocess_mock(
|
||||
('borg', 'check', 'repo', '--remote-path', 'borg1'),
|
||||
stdout=stdout, stderr=STDOUT,
|
||||
)
|
||||
insert_platform_mock()
|
||||
insert_datetime_mock()
|
||||
flexmock(sys.modules['builtins']).should_receive('open').and_return(stdout)
|
||||
flexmock(module.os).should_receive('devnull')
|
||||
|
||||
module.check_archives(
|
||||
verbosity=None,
|
||||
repository='repo',
|
||||
consistency_config=consistency_config,
|
||||
command='borg',
|
||||
remote_path='borg1',
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
import logging
|
||||
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic import verbosity as module
|
||||
|
||||
def insert_logging_mock(log_level):
|
||||
""" Mocks the isEnabledFor from python logging. """
|
||||
logging = flexmock(module.logging.Logger)
|
||||
logging.should_receive('isEnabledFor').replace_with(lambda lvl : lvl >= log_level)
|
||||
logging.should_receive('getEffectiveLevel').replace_with(lambda: log_level)
|
||||
|
||||
|
||||
def test_verbosity_to_log_level_maps_known_verbosity_to_log_level():
|
||||
assert module.verbosity_to_log_level(module.VERBOSITY_SOME) == logging.INFO
|
||||
assert module.verbosity_to_log_level(module.VERBOSITY_LOTS) == logging.DEBUG
|
||||
|
||||
|
||||
def test_verbosity_to_log_level_maps_unknown_verbosity_to_warning_level():
|
||||
assert module.verbosity_to_log_level('my pants') == logging.WARNING
|
||||
@@ -1,2 +1,17 @@
|
||||
import logging
|
||||
|
||||
|
||||
VERBOSITY_WARNING = 0
|
||||
VERBOSITY_SOME = 1
|
||||
VERBOSITY_LOTS = 2
|
||||
|
||||
|
||||
def verbosity_to_log_level(verbosity):
|
||||
'''
|
||||
Given a borgmatic verbosity value, return the corresponding Python log level.
|
||||
'''
|
||||
return {
|
||||
VERBOSITY_WARNING: logging.WARNING,
|
||||
VERBOSITY_SOME: logging.INFO,
|
||||
VERBOSITY_LOTS: logging.DEBUG,
|
||||
}.get(verbosity, logging.WARNING)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# You can drop this file into /etc/cron.d/ to run borgmatic nightly.
|
||||
|
||||
0 3 * * * PATH=$PATH:/usr/bin /usr/bin/borgmatic
|
||||
@@ -3,6 +3,7 @@ Description=Run borgmatic backup
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o nounset
|
||||
|
||||
# For each Borg sub-command that borgmatic uses, print out the Borg flags that borgmatic does not
|
||||
# appear to support yet. This script isn't terribly robust. It's intended as a basic tool to ferret
|
||||
# out unsupported Borg options so that they can be considered for addition to borgmatic.
|
||||
|
||||
# Generate a sample borgmatic configuration with all options set.
|
||||
generate-borgmatic-config --destination temp.yaml
|
||||
|
||||
# For each sub-command (prune, create, and check), collect the Borg command-line flags that result
|
||||
# from running borgmatic with the generated configuration. Then, collect the full set of available
|
||||
# Borg flags as reported by "borg --help" for that sub-command. Finally, compare the two lists of
|
||||
# flags to determine which Borg flags borgmatic doesn't yet support.
|
||||
for sub_command in prune create check list info; do
|
||||
echo "********** borg $sub_command **********"
|
||||
|
||||
for line in $(borgmatic --config temp.yaml --$sub_command -v 2 2>&1 | grep "borg\w* $sub_command") ; do
|
||||
echo "$line" | grep '^-' >> borgmatic_borg_flags
|
||||
done
|
||||
sort borgmatic_borg_flags > borgmatic_borg_flags.sorted
|
||||
mv borgmatic_borg_flags.sorted borgmatic_borg_flags
|
||||
|
||||
for word in $(borg $sub_command --help | grep '^ -') ; do
|
||||
# Exclude a bunch of flags that borgmatic actually supports, but don't get exercised by the
|
||||
# generated sample config, and also flags that don't make sense to support.
|
||||
echo "$word" | grep ^-- | sed -e 's/,$//' \
|
||||
| grep -v '^--archives-only$' \
|
||||
| grep -v '^--critical$' \
|
||||
| grep -v '^--debug$' \
|
||||
| grep -v '^--dry-run$' \
|
||||
| grep -v '^--error$' \
|
||||
| grep -v '^--help$' \
|
||||
| grep -v '^--info$' \
|
||||
| grep -v '^--list$' \
|
||||
| grep -v '^--nobsdflags$' \
|
||||
| grep -v '^--pattern$' \
|
||||
| grep -v '^--read-special$' \
|
||||
| grep -v '^--repository-only$' \
|
||||
| grep -v '^--show-rc$' \
|
||||
| grep -v '^--stats$' \
|
||||
| grep -v '^--verbose$' \
|
||||
| grep -v '^--warning$' \
|
||||
| grep -v '^-h$' \
|
||||
>> all_borg_flags
|
||||
done
|
||||
|
||||
sort all_borg_flags > all_borg_flags.sorted
|
||||
mv all_borg_flags.sorted all_borg_flags
|
||||
|
||||
comm -13 borgmatic_borg_flags all_borg_flags
|
||||
|
||||
rm ./*_borg_flags
|
||||
done
|
||||
|
||||
rm temp.yaml
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
git push -u origin master
|
||||
git push -u github master
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
version=$(head --lines=1 NEWS)
|
||||
git tag $version
|
||||
git push origin $version
|
||||
git push github $version
|
||||
|
||||
rm -fr dist
|
||||
python3 setup.py bdist_wheel
|
||||
python3 setup.py sdist
|
||||
twine upload -r pypi dist/borgmatic-*.tar.gz
|
||||
twine upload -r pypi dist/borgmatic-*-py3-none-any.whl
|
||||
@@ -1,7 +1,7 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
VERSION = '1.1.2'
|
||||
VERSION = '1.2.4'
|
||||
|
||||
|
||||
setup(
|
||||
@@ -11,7 +11,6 @@ setup(
|
||||
author='Dan Helfman',
|
||||
author_email='witten@torsion.org',
|
||||
url='https://torsion.org/borgmatic',
|
||||
download_url='https://torsion.org/hg/borgmatic/archive/%s.tar.gz' % VERSION,
|
||||
classifiers=(
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Environment :: Console',
|
||||
@@ -33,8 +32,8 @@ setup(
|
||||
'atticmatic',
|
||||
],
|
||||
install_requires=(
|
||||
'pykwalify',
|
||||
'ruamel.yaml<=0.15',
|
||||
'pykwalify>=1.6.0,<14.06',
|
||||
'ruamel.yaml>0.15.0,<0.16.0',
|
||||
'setuptools',
|
||||
),
|
||||
tests_require=(
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
@@ -1,5 +1,5 @@
|
||||
flexmock==0.10.2
|
||||
pykwalify==1.6.0
|
||||
pytest==2.9.1
|
||||
pykwalify==1.6.1
|
||||
pytest==3.7.4
|
||||
pytest-cov==2.5.1
|
||||
ruamel.yaml==0.15.18
|
||||
ruamel.yaml>0.15.0,<0.16.0
|
||||
|
||||
Reference in New Issue
Block a user