From b326cd6d8264ca48b275cceeb2ecab1336ac2b0d Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Wed, 13 Feb 2019 16:50:54 -0500 Subject: [PATCH] Add borgmatic configuration This is a sample configuration file that users are encouraged to modify. Change-Id: Ifab9bd0325fb5198ccc7a91f7c101a2780744b6d Signed-off-by: Paul Belanger --- defaults/main.yaml | 13 ++++++++ molecule/tests/test_role.py | 18 +++++++++++ tasks/config.yaml | 31 +++++++++++++++++++ .../root/.config/borgmatic/config.yaml.j2 | 30 ++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 tasks/config.yaml create mode 100644 templates/root/.config/borgmatic/config.yaml.j2 diff --git a/defaults/main.yaml b/defaults/main.yaml index 0de617c..80836a5 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -15,6 +15,19 @@ # tasks/main.yaml borgmatic_task_manager: - install + - config + +# task/config.yaml +borgmatic_user_name: root +borgmatic_user_group: root +borgmatic_user_home: /root + +borgmatic_file_config_yaml_dest: + "{{ borgmatic_user_home }}/.config/borgmatic/config.yaml" +borgmatic_file_config_yaml_group: "{{ borgmatic_user_group }}" +borgmatic_file_config_yaml_mode: 0644 +borgmatic_file_config_yaml_owner: "{{ borgmatic_user_name }}" +borgmatic_file_config_yaml_src: root/.config/borgmatic/config.yaml.j2 # tasks/install.yaml borgmatic_git_dest: "{{ ansible_user_dir }}/src/github.com/witten/borgmatic" diff --git a/molecule/tests/test_role.py b/molecule/tests/test_role.py index 86593fe..a16f0f5 100644 --- a/molecule/tests/test_role.py +++ b/molecule/tests/test_role.py @@ -13,5 +13,23 @@ # under the License. +def test_borgmatic_config(host): + f = host.file('/root/.config/borgmatic') + assert f.exists + assert f.is_directory + assert f.user == 'root' + assert f.group == 'root' + # TODO(pabelanger): Validate mode + del f + + f = host.file('/root/.config/borgmatic/config.yaml') + assert f.exists + assert f.is_file + assert f.user == 'root' + assert f.group == 'root' + assert f.mode == 0o644 + del f + + def test_borgmatic_version(host): host.check_output('borgmatic --version') diff --git a/tasks/config.yaml b/tasks/config.yaml new file mode 100644 index 0000000..7dc8c46 --- /dev/null +++ b/tasks/config.yaml @@ -0,0 +1,31 @@ +# Copyright 2019 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +--- +- name: Create required directories + become: true + become_user: "{{ borgmatic_user_name }}" + file: + group: "{{ borgmatic_user_group }}" + owner: "{{ borgmatic_user_name }}" + path: "{{ borgmatic_user_home }}/.config/borgmatic" + state: directory + +- name: Install borgmatic configuration + become: true + template: + dest: "{{ borgmatic_file_config_yaml_dest }}" + group: "{{ borgmatic_file_config_yaml_group }}" + mode: "{{ borgmatic_file_config_yaml_mode }}" + owner: "{{borgmatic_file_config_yaml_owner }}" + src: "{{ borgmatic_file_config_yaml_src }}" diff --git a/templates/root/.config/borgmatic/config.yaml.j2 b/templates/root/.config/borgmatic/config.yaml.j2 new file mode 100644 index 0000000..c63b063 --- /dev/null +++ b/templates/root/.config/borgmatic/config.yaml.j2 @@ -0,0 +1,30 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +--- +location: + # List of source directories to backup. Globs are expanded. + source_directories: + - /home + - /etc + - /var/log/syslog* + + # Paths to local or remote repositories. + repositories: + - user@backupserver:sourcehostname.borg + + # Any paths matching these patterns are excluded from backups. + exclude_patterns: + - /home/*/.cache + +retention: + # Retention policy for how many backups to keep in each category. + keep_daily: 7 + keep_weekly: 4 + keep_monthly: 6 + +consistency: + # List of consistency checks to run: "repository", "archives", or both. + checks: + - repository + - archives