Remove helper scripts, fix absolute path

This commit is contained in:
Manu 2023-03-19 19:16:44 +00:00
parent adc2e40ccb
commit f9fc12be61
11 changed files with 10 additions and 127 deletions

View File

@ -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`

View File

@ -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:

View File

@ -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 <dornheim@posteo.de> 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} <CONTAINERNAME> <CONTAINERNAME 2>"
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 "<CONTAINERNAME>: start|stop of a named container"
echo ""
;;
*)
echo "Usage: $0. The first argument have to be:{start|stop}. See --help." >&2
exit 1
;;
esac

View File

@ -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

View File

@ -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" }
...

View File

@ -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:

View File

@ -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
...

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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.