mirror of
https://github.com/borgbase/ansible-role-borgbackup.git
synced 2025-09-17 17:53:06 +02:00
Remove helper scripts, fix absolute path
This commit is contained in:
parent
adc2e40ccb
commit
f9fc12be61
@ -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
|
## Role Variables
|
||||||
|
|
||||||
### Required 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_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_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_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_version`: Force a specific borg version to be installed
|
||||||
- `borg_venv_path`: Path to store the venv for `borg(backup)` and `borgmatic`
|
- `borg_venv_path`: Path to store the venv for `borg(backup)` and `borgmatic`
|
||||||
|
|
||||||
|
@ -8,9 +8,7 @@ borg_lock_wait_time: 5
|
|||||||
borg_ssh_key_type: "ed25519"
|
borg_ssh_key_type: "ed25519"
|
||||||
borg_ssh_key_name: "id_{{ borg_ssh_key_type }}"
|
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/{{ 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 }}"
|
||||||
# borg_ssh_command: "ssh -i {{ borg_ssh_key_file_path }} -o StrictHostKeyChecking=no"
|
|
||||||
borg_remote_path: false
|
borg_remote_path: false
|
||||||
borg_remote_rate_limit: 0
|
borg_remote_rate_limit: 0
|
||||||
borg_retention_policy:
|
borg_retention_policy:
|
||||||
|
@ -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
|
|
@ -19,8 +19,10 @@
|
|||||||
|
|
||||||
roles:
|
roles:
|
||||||
- role: m3nu.ansible_role_borgbackup
|
- 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_repository: m5vz9gp4@m5vz9gp4.repo.borgbase.com:repo
|
||||||
|
borg_encryption_passphrase: CHANGEME
|
||||||
borg_source_directories:
|
borg_source_directories:
|
||||||
- /srv/www
|
- /srv/www
|
||||||
- /var/lib/automysqlbackup
|
- /var/lib/automysqlbackup
|
||||||
@ -38,10 +40,6 @@
|
|||||||
- name: users
|
- name: users
|
||||||
hostname: database1.example.org
|
hostname: database1.example.org
|
||||||
port: 5433
|
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:
|
post_tasks:
|
||||||
- name: Install yamllint for checking config file
|
- name: Install yamllint for checking config 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" }
|
|
||||||
...
|
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: Create borgbackup timer
|
- name: Install timer to run Borgmatic
|
||||||
when:
|
when:
|
||||||
- borgmatic_timer is defined and borgmatic_timer | length > 0
|
- borgmatic_timer is defined and borgmatic_timer | length > 0
|
||||||
block:
|
block:
|
||||||
|
@ -4,5 +4,4 @@
|
|||||||
with_items: "{{ lookup('ansible.builtin.fileglob', '*.yml').split(',') | reject('search', 'main.yml') | reject('search', 'noauto_*') | sort }}"
|
with_items: "{{ lookup('ansible.builtin.fileglob', '*.yml').split(',') | reject('search', 'main.yml') | reject('search', 'noauto_*') | sort }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
loop_var: bak_element
|
loop_var: bak_element
|
||||||
tags: always
|
|
||||||
...
|
...
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
minute: "{{ borgmatic_timer_minute }}"
|
minute: "{{ borgmatic_timer_minute }}"
|
||||||
user: "{{ borg_user }}"
|
user: "{{ borg_user }}"
|
||||||
cron_file: "{{ borgmatic_timer_cron_name }}"
|
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
|
- name: Ensure separate check cron job is absent
|
||||||
cron:
|
cron:
|
||||||
|
@ -15,13 +15,13 @@
|
|||||||
virtualenv: "{{ borg_venv_path }}"
|
virtualenv: "{{ borg_venv_path }}"
|
||||||
virtualenv_command: "{{ python_bin }} -m venv"
|
virtualenv_command: "{{ python_bin }} -m venv"
|
||||||
|
|
||||||
- name: Install dependent Python Packages
|
- name: Install dependent Python packages
|
||||||
ansible.builtin.pip:
|
ansible.builtin.pip:
|
||||||
name: "{{ borg_dependent_python_packages }}"
|
name: "{{ borg_dependent_python_packages }}"
|
||||||
virtualenv: "{{ borg_venv_path }}"
|
virtualenv: "{{ borg_venv_path }}"
|
||||||
when: borg_dependent_python_packages is defined
|
when: borg_dependent_python_packages is defined
|
||||||
|
|
||||||
- name: Install main Python Packages
|
- name: Install main Python packages
|
||||||
ansible.builtin.pip:
|
ansible.builtin.pip:
|
||||||
name: "{{ item.name }}"
|
name: "{{ item.name }}"
|
||||||
version: "{{ item.version | default(omit, true) }}"
|
version: "{{ item.version | default(omit, true) }}"
|
||||||
@ -29,7 +29,7 @@
|
|||||||
when: borg_python_packages is defined
|
when: borg_python_packages is defined
|
||||||
loop: "{{ borg_python_packages }}"
|
loop: "{{ borg_python_packages }}"
|
||||||
|
|
||||||
- name: Create links to Borgmatic and Borg binarys
|
- name: Create links to Borgmatic and Borg binaries
|
||||||
block:
|
block:
|
||||||
- name: Create borgmatic command in /usr/local/bin
|
- name: Create borgmatic command in /usr/local/bin
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
|
@ -12,7 +12,7 @@ ConditionACPower=true
|
|||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
User={{ borg_user }}
|
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
|
# 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
|
# Security settings for systemd running as root, optional but recommended to improve security. You
|
||||||
|
@ -110,10 +110,6 @@ storage:
|
|||||||
# Bypass Borg error about a repository that has been moved.
|
# Bypass Borg error about a repository that has been moved.
|
||||||
relocated_repo_access_is_ok: {{ borgmatic_relocated_repo_access_is_ok }}
|
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
|
# Retention policy for how many backups to keep in each category. See
|
||||||
# https://borgbackup.readthedocs.org/en/stable/usage.html#borg-prune for details.
|
# 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.
|
# At least one of the "keep" options is required for pruning to work.
|
||||||
|
Loading…
Reference in New Issue
Block a user