From f9fc12be61f71ce061777fbaec925a429b8bea36 Mon Sep 17 00:00:00 2001 From: Manu Date: Sun, 19 Mar 2023 19:16:44 +0000 Subject: [PATCH] Remove helper scripts, fix absolute path --- README.md | 8 +-- defaults/main.yml | 2 - files/docker.sh | 88 ------------------------------ molecule/default/converge.yml | 8 +-- tasks/04_helper_scripts.yml | 14 ----- tasks/07_install_timer.yml | 2 +- tasks/main.yml | 1 - tasks/noauto_create_timer_cron.yml | 2 +- tasks/noauto_install_pip.yml | 6 +- templates/borgmatic.service.j2 | 2 +- templates/config.yaml.j2 | 4 -- 11 files changed, 10 insertions(+), 127 deletions(-) delete mode 100644 files/docker.sh delete mode 100644 tasks/04_helper_scripts.yml diff --git a/README.md b/README.md index da92218..37fd481 100644 --- a/README.md +++ b/README.md @@ -87,12 +87,6 @@ $ git clone https://github.com/borgbase/ansible-role-borgbackup.git roles/ansibl ``` -## Tags: -This role supports the following Ansible tags: - -- `backup_install_helper` Install optional helper scripts from `files` folder. Currently only Docker. - - ## Role Variables ### Required Variables @@ -117,7 +111,7 @@ This role supports the following Ansible tags: - `borg_ssh_key_name`: Name of the SSH public and pivate key. Default `id_ed25519` - `borg_ssh_key_file_path`: SSH-key to be used. Default `~/.ssh/{{ borg_ssh_key_name }}` - `borg_ssh_key_type`: The algorithm used to generate the SSH private key. Choose: `rsa`, `dsa`, `rsa1`, `ecdsa`, `ed25519`. Default: `ed25519` -- `borg_ssh_command`: Command to use instead of just "ssh". This can be used to specify ssh options. +- `borg_ssh_command`: Command to use instead of just "ssh". This can be used to specify SSH options. - `borg_version`: Force a specific borg version to be installed - `borg_venv_path`: Path to store the venv for `borg(backup)` and `borgmatic` diff --git a/defaults/main.yml b/defaults/main.yml index ca94457..42e73b3 100755 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -8,9 +8,7 @@ borg_lock_wait_time: 5 borg_ssh_key_type: "ed25519" borg_ssh_key_name: "id_{{ borg_ssh_key_type }}" borg_ssh_key_file_path: "{{ backup_user_info.home }}/.ssh/{{ borg_ssh_key_name }}" -# borg_ssh_key_file_path: "{{ backup_user_info.home }}/.ssh/backup" # static key borg_ssh_command: "ssh -i {{ borg_ssh_key_file_path }}" -# borg_ssh_command: "ssh -i {{ borg_ssh_key_file_path }} -o StrictHostKeyChecking=no" borg_remote_path: false borg_remote_rate_limit: 0 borg_retention_policy: diff --git a/files/docker.sh b/files/docker.sh deleted file mode 100644 index d5e5e04..0000000 --- a/files/docker.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env bash - -# Purpose: Get and save state of docker containers and stop them for a backup -# Author: Frank Dornheim under GPLv2+ -# Category: Core -# Override: False - -FILENAME=/tmp/borgbackup_docker.state -DOCKERGROUP=docker - -# -# Checks the state of a Docker container and saves it. -# Running containers are stopped to maintain a consistent backup. -# After the backup finished, in a second step, all containers are restarted. -# - -# Check for permissions to work with docker -if [[ $(id -u) -ne 0 ]] || [[ $(groups) =~ '$DOCKERGROUP' ]]; then - echo "Please run as root or member of group docker" - exit 1 -fi - -function rwo(){ tr ' ' '\n'<<<"$@"|tac|tr '\n' ' ';} # reverse name order - -case "$1" in - start) - if [[ ! -f "$FILENAME" ]]; then - echo "$FILENAME didnt loger exist so cat restart container." - exit 1 - fi - - container_list=$(cat "$FILENAME") - - echo "Containers were stopped in the following order: $container_list" - container_start_list=$(rwo $container_list) - echo "Reversed start order: $container_start_list" - - for i in $container_start_list; do - echo "Start container: $i" - docker start $i &>/dev/null - done - - #clean up - rm $FILENAME - ;; - - stop) - # delete old state file - if [[ -f "$FILENAME" ]]; then - rm "$FILENAME" - fi - - # Named container or all container - if [[ $# -gt 1 ]]; then - container_list="${@:2:$#}" # Slice Arguments the first is {start|stop} the other are container names - else - # No container names passed, this means all containers are analyzed - container_list=$( docker inspect --format={{.Name}} $( docker ps -aq --no-trunc ) | cut -c2- ) - fi - - # save state and shutdown active container - for i in $container_list; do - state=$( docker ps -a -f name=$i | grep $i 2> /dev/null | awk '{ print $7 }') - if [[ $state -eq Up ]]; then - echo "Stop container: $i" - docker stop $i &>/dev/null - else - echo "The State of container: $i is not up, so ignoring them." - fi - done - echo "Containers were stopped in the following order: $( echo $container_list | tr '\n' ' ')" - echo $container_list > $FILENAME - ;; - - --help) - echo "$0 {start|stop} " - echo "" - echo "stop: Save the status of all running container an stop them due backup." - echo "start: Load status of container before the backup and start them." - echo ": start|stop of a named container" - echo "" - ;; - - *) - echo "Usage: $0. The first argument have to be:{start|stop}. See --help." >&2 - exit 1 - ;; -esac diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 9508ae1..c58023e 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -19,8 +19,10 @@ roles: - role: m3nu.ansible_role_borgbackup - borg_encryption_passphrase: CHANGEME + borg_install_method: pip + borgmatic_timer: cron borg_repository: m5vz9gp4@m5vz9gp4.repo.borgbase.com:repo + borg_encryption_passphrase: CHANGEME borg_source_directories: - /srv/www - /var/lib/automysqlbackup @@ -38,10 +40,6 @@ - name: users hostname: database1.example.org port: 5433 - borg_install_method: pip - borg_ssh_key_file_path: "{{ backup_user_info.home }}/.ssh/backup" - borg_ssh_command: "ssh -i {{ borg_ssh_key_file_path }} -o StrictHostKeyChecking=no" - borgmatic_timer: cron post_tasks: - name: Install yamllint for checking config file diff --git a/tasks/04_helper_scripts.yml b/tasks/04_helper_scripts.yml deleted file mode 100644 index 6a26af7..0000000 --- a/tasks/04_helper_scripts.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: Install helper scripts - tags: - - never - - backup_install_helper - ansible.builtin.copy: - src: "{{ item.src }}" - dest: "{{ item.dest }}" - owner: "{{ item.owner }}" - group: "{{ item.group }}" - mode: "{{ item.mode }}" - with_items: - - { src: "docker.sh", dest: "/usr/local/bin/docker.sh", owner: "{{ borg_user }}", group: "{{ borg_group }}", mode: "0770" } -... diff --git a/tasks/07_install_timer.yml b/tasks/07_install_timer.yml index 8f273ce..4ca6afa 100644 --- a/tasks/07_install_timer.yml +++ b/tasks/07_install_timer.yml @@ -1,5 +1,5 @@ --- -- name: Create borgbackup timer +- name: Install timer to run Borgmatic when: - borgmatic_timer is defined and borgmatic_timer | length > 0 block: diff --git a/tasks/main.yml b/tasks/main.yml index f30bb09..d6b56c1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,5 +4,4 @@ with_items: "{{ lookup('ansible.builtin.fileglob', '*.yml').split(',') | reject('search', 'main.yml') | reject('search', 'noauto_*') | sort }}" loop_control: loop_var: bak_element - tags: always ... diff --git a/tasks/noauto_create_timer_cron.yml b/tasks/noauto_create_timer_cron.yml index 2b79ed7..0afa70e 100644 --- a/tasks/noauto_create_timer_cron.yml +++ b/tasks/noauto_create_timer_cron.yml @@ -13,7 +13,7 @@ minute: "{{ borgmatic_timer_minute }}" user: "{{ borg_user }}" cron_file: "{{ borgmatic_timer_cron_name }}" - job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}" + job: "borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}" - name: Ensure separate check cron job is absent cron: diff --git a/tasks/noauto_install_pip.yml b/tasks/noauto_install_pip.yml index 8b8f400..1b059a6 100644 --- a/tasks/noauto_install_pip.yml +++ b/tasks/noauto_install_pip.yml @@ -15,13 +15,13 @@ virtualenv: "{{ borg_venv_path }}" virtualenv_command: "{{ python_bin }} -m venv" - - name: Install dependent Python Packages + - name: Install dependent Python packages ansible.builtin.pip: name: "{{ borg_dependent_python_packages }}" virtualenv: "{{ borg_venv_path }}" when: borg_dependent_python_packages is defined - - name: Install main Python Packages + - name: Install main Python packages ansible.builtin.pip: name: "{{ item.name }}" version: "{{ item.version | default(omit, true) }}" @@ -29,7 +29,7 @@ when: borg_python_packages is defined loop: "{{ borg_python_packages }}" -- name: Create links to Borgmatic and Borg binarys +- name: Create links to Borgmatic and Borg binaries block: - name: Create borgmatic command in /usr/local/bin ansible.builtin.copy: diff --git a/templates/borgmatic.service.j2 b/templates/borgmatic.service.j2 index 1fb08ce..4e4406c 100644 --- a/templates/borgmatic.service.j2 +++ b/templates/borgmatic.service.j2 @@ -12,7 +12,7 @@ ConditionACPower=true [Service] Type=oneshot User={{ borg_user }} -ExecStart=/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} +ExecStart=borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} # Source: https://projects.torsion.org/borgmatic-collective/borgmatic/raw/branch/master/sample/systemd/borgmatic.service # Security settings for systemd running as root, optional but recommended to improve security. You diff --git a/templates/config.yaml.j2 b/templates/config.yaml.j2 index dd066e9..69ddf33 100644 --- a/templates/config.yaml.j2 +++ b/templates/config.yaml.j2 @@ -110,10 +110,6 @@ storage: # Bypass Borg error about a repository that has been moved. relocated_repo_access_is_ok: {{ borgmatic_relocated_repo_access_is_ok }} - # Path for Borg encryption key files. Defaults to - # $borg_base_directory/.config/borg/keys - borg_keys_directory: {{ backup_user_info.home }}/.config/borg/keys - # 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.