From ac1d63bb0dc2f6833d78dc821fe448047e02ddd8 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 18 Jan 2020 20:00:18 -0800 Subject: [PATCH 1/7] Use more realistic repository examples in README. --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09f4e65..9d08811 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,11 @@ location: - /home - /etc - # Paths to local or remote repositories. + # Paths of local or remote repositories to backup to. repositories: - - user@backupserver:sourcehostname.borg + - 1234@usw-s001.rsync.net:backups.borg + - k8pDxu32@k8pDxu32.repo.borgbase.com:repo + - /var/lib/backups/backups.borg retention: # Retention policy for how many backups to keep. From 8a91c79fb027ad58bc22c7827f3fa50af8d0511d Mon Sep 17 00:00:00 2001 From: Ronan Dunklau Date: Sun, 19 Jan 2020 15:15:47 +0100 Subject: [PATCH 2/7] Support directory format dump cleanup. Previously, only deleting a dump in a single-file format was supported. This led to errors when performing a PostgreSQL directory format backup. --- borgmatic/hooks/dump.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/borgmatic/hooks/dump.py b/borgmatic/hooks/dump.py index 54db1d2..bd5ea08 100644 --- a/borgmatic/hooks/dump.py +++ b/borgmatic/hooks/dump.py @@ -1,6 +1,7 @@ import glob import logging import os +import shutil from borgmatic.borg.create import DEFAULT_BORGMATIC_SOURCE_DIRECTORY @@ -83,7 +84,10 @@ def remove_database_dumps(dump_path, databases, database_type_name, log_prefix, if dry_run: continue - os.remove(dump_filename) + if os.path.isdir(dump_filename): + shutil.rmtree(dump_filename) + else: + os.remove(dump_filename) dump_file_dir = os.path.dirname(dump_filename) if len(os.listdir(dump_file_dir)) == 0: From cc384f4324a44acf34635c2ef140b791d744eba7 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 21 Jan 2020 08:33:41 -0800 Subject: [PATCH 3/7] Second ticket for --json color bug. --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 0e76bf0..2d62f15 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,5 @@ 1.4.22.dev0 - * #276: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput. + * #276, #285: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput. * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths. 1.4.21 From 7824a034ca571848a4a58a2d166ff9b57176ea33 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 21 Jan 2020 10:34:46 -0800 Subject: [PATCH 4/7] Add test for database dump directory removal. --- NEWS | 1 + tests/unit/hooks/test_dump.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/NEWS b/NEWS index 2d62f15..2e507f2 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ 1.4.22.dev0 * #276, #285: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput. + * After a backup of a database dump in directory format, properly remove the dump directory. * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths. 1.4.21 diff --git a/tests/unit/hooks/test_dump.py b/tests/unit/hooks/test_dump.py index d36f809..dc6e8dd 100644 --- a/tests/unit/hooks/test_dump.py +++ b/tests/unit/hooks/test_dump.py @@ -66,6 +66,7 @@ def test_remove_database_dumps_removes_dump_for_each_database(): 'databases', 'bar', None ).and_return('databases/localhost/bar') + flexmock(module.os.path).should_receive('isdir').and_return(False) flexmock(module.os).should_receive('remove').with_args('databases/localhost/foo').once() flexmock(module.os).should_receive('remove').with_args('databases/localhost/bar').once() flexmock(module.os).should_receive('listdir').with_args('databases/localhost').and_return( @@ -77,6 +78,21 @@ def test_remove_database_dumps_removes_dump_for_each_database(): module.remove_database_dumps('databases', databases, 'SuperDB', 'test.yaml', dry_run=False) +def test_remove_database_dumps_removes_dump_in_directory_format(): + databases = [{'name': 'foo'}] + flexmock(module).should_receive('make_database_dump_filename').with_args( + 'databases', 'foo', None + ).and_return('databases/localhost/foo') + + flexmock(module.os.path).should_receive('isdir').and_return(True) + flexmock(module.os).should_receive('remove').never() + flexmock(module.shutil).should_receive('rmtree').with_args('databases/localhost/foo').once() + flexmock(module.os).should_receive('listdir').with_args('databases/localhost').and_return([]) + flexmock(module.os).should_receive('rmdir').with_args('databases/localhost').once() + + module.remove_database_dumps('databases', databases, 'SuperDB', 'test.yaml', dry_run=False) + + def test_remove_database_dumps_with_dry_run_skips_removal(): databases = [{'name': 'foo'}, {'name': 'bar'}] flexmock(module.os).should_receive('rmdir').never() From 8d120793869322d4c8472e45787a247015af7f8f Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 21 Jan 2020 10:47:29 -0800 Subject: [PATCH 5/7] Bump version. --- NEWS | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 2e507f2..df65bf0 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -1.4.22.dev0 +1.4.22 * #276, #285: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput. * After a backup of a database dump in directory format, properly remove the dump directory. * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths. diff --git a/setup.py b/setup.py index 15dfed5..2f07da6 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.4.22.dev0' +VERSION = '1.4.22' setup( From 88f06f7921f11987967ade92bc7d257941d535ae Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 21 Jan 2020 16:03:24 -0800 Subject: [PATCH 6/7] Revert "Use absolute paths in systemd commands." This reverts commit 24e1516ec50b73df7612862f95f4bff956268445. --- sample/systemd/borgmatic.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/systemd/borgmatic.service b/sample/systemd/borgmatic.service index 11725e6..cd3f51b 100644 --- a/sample/systemd/borgmatic.service +++ b/sample/systemd/borgmatic.service @@ -20,5 +20,5 @@ Restart=no LogRateLimitIntervalSec=0 # Delay start to prevent backups running during boot. -ExecStartPre=/usr/bin/sleep 1m -ExecStart=/usr/bin/systemd-inhibit --who="borgmatic" --why="Prevent interrupting scheduled backup" /root/.local/bin/borgmatic --syslog-verbosity 1 +ExecStartPre=sleep 1m +ExecStart=systemd-inhibit --who="borgmatic" --why="Prevent interrupting scheduled backup" /root/.local/bin/borgmatic --syslog-verbosity 1 From 39550a7fe9050bb3b10a1f15c2306775ec0c75fe Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 22 Jan 2020 09:26:58 -0800 Subject: [PATCH 7/7] Add ~/.config/borgmatic.d as another configuration directory default (#274). --- NEWS | 3 +++ borgmatic/config/collect.py | 1 + docs/how-to/make-per-application-backups.md | 7 ++++--- docs/how-to/set-up-backups.md | 21 +++++++++++++-------- setup.py | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index df65bf0..4a7ddd1 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.4.23.dev0 + * #274: Add ~/.config/borgmatic.d as another configuration directory default. + 1.4.22 * #276, #285: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput. * After a backup of a database dump in directory format, properly remove the dump directory. diff --git a/borgmatic/config/collect.py b/borgmatic/config/collect.py index ef04bd4..97c9410 100644 --- a/borgmatic/config/collect.py +++ b/borgmatic/config/collect.py @@ -17,6 +17,7 @@ def get_default_config_paths(expand_home=True): '/etc/borgmatic/config.yaml', '/etc/borgmatic.d', '%s/borgmatic/config.yaml' % user_config_directory, + '%s/borgmatic.d' % user_config_directory, ] diff --git a/docs/how-to/make-per-application-backups.md b/docs/how-to/make-per-application-backups.md index cd25746..8d08ac2 100644 --- a/docs/how-to/make-per-application-backups.md +++ b/docs/how-to/make-per-application-backups.md @@ -27,9 +27,10 @@ for each configuration file one at a time. In other words, borgmatic does not perform any merging of configuration files by default. If you'd like borgmatic to merge your configuration files, see below about configuration includes. -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. +Additionally, the `~/.config/borgmatic.d/` directory works the same way as +`/etc/borgmatic.d`. If you need even more customizability, you can specify +alternate configuration paths on the command-line with borgmatic's `--config` +flag. See `borgmatic --help` for more information. ## Configuration includes diff --git a/docs/how-to/set-up-backups.md b/docs/how-to/set-up-backups.md index 2d28837..59d9162 100644 --- a/docs/how-to/set-up-backups.md +++ b/docs/how-to/set-up-backups.md @@ -68,10 +68,13 @@ 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` (see above). Try looking in `~/.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 -representative. All options are optional except where indicated, so feel free -to ignore anything you don't need. +This generates a sample configuration file at `/etc/borgmatic/config.yaml` by +default. If you'd like to use another path, use the `--destination` flag, for +instance: `--destination ~/.config/borgmatic/config.yaml`. + +You should edit the configuration file to suit your needs, as the generated +values are only representative. All options are optional except where +indicated, so feel free to ignore anything you don't need. Note that the configuration file is organized into distinct sections, each with a section name like `location:` or `storage:`. So take care that if you @@ -79,12 +82,11 @@ uncomment a particular option, also uncomment its containing section name, or else borgmatic won't recognize the option. Also be sure to use spaces rather than tabs for indentation; YAML does not allow tabs. -You can also get the same sample configuration file from the [configuration +You can get the same sample configuration file from the [configuration reference](https://torsion.org/borgmatic/docs/reference/configuration/), the authoritative set of all configuration options. This is handy if borgmatic has -added new options -since you originally created your configuration file. Also check out how to -[upgrade your +added new options since you originally created your configuration file. Also +check out how to [upgrade your configuration](https://torsion.org/borgmatic/docs/how-to/upgrade/#upgrading-your-configuration). @@ -173,6 +175,9 @@ The verbosity flag makes borgmatic list the files that it's archiving, which are those that are new or changed since the last backup. Eyeball the list and see if it matches your expectations based on the configuration. +If you'd like to specify an alternate configuration file path, use the +`--config` flag. See `borgmatic --help` for more information. + ## Autopilot diff --git a/setup.py b/setup.py index 2f07da6..c73c9ea 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.4.22' +VERSION = '1.4.23.dev0' setup(