Simplified and fixed borg role
This commit is contained in:
parent
91b773e12e
commit
cab3d045c1
3 changed files with 17 additions and 41 deletions
7
README
7
README
|
@ -6,12 +6,17 @@ There are several variables you can define to configure a machines response to t
|
|||
- command_to_pipe: an optional command to pipe the backup data from
|
||||
- pre_command: an optional command to run before a job
|
||||
- post_command: an optional command to run after a job
|
||||
- exclude: an optional list of paths containing locations to exclude
|
||||
|
||||
To be valid, a borg job entry needs to have exactly one of the path or command_to_pipe keys.
|
||||
|
||||
Here are some job examples :
|
||||
- { name: etc, path: "/etc" }
|
||||
- { name: etc, path: "/etc", exclude: [ "/etc/firmware" ] }
|
||||
- { name: mysqldump, command_to_pipe: "/usr/bin/mysqldump -h {{ mysql_server }} -u{{ ansible_hostname }} -p{{ ansible_local.mysql_client.password }} --single-transaction --add-drop-database -B {{ ansible_hostname }}" }
|
||||
- { name: gitea, path: "/tmp/gitea.zip", pre_command: "echo '/usr/local/sbin/gitea -C /etc/gitea -c /etc/gitea/app.ini dump -f /tmp/gitea.zip' | su -l _gitea", post_command: "rm -f /tmp/gitea.zip" }
|
||||
|
||||
There is an action plugin that parses the borg_server entries from all hosts and set a flag to True in adyxax['is_borg_server'] for any machine specified as a backup target
|
||||
|
||||
Usefull commands:
|
||||
=================
|
||||
ansible all -i hosts -m shell -a "/usr/local/bin/adyxax_backup.sh"
|
||||
|
|
|
@ -15,53 +15,24 @@
|
|||
authorized_key:
|
||||
user: borg
|
||||
key: "{{ ansible_local.borg.pubkey }}"
|
||||
key_options: 'command="cd /srv/borg/repos/{{ ansible_hostname }}; borg serve --restrict-to-path /srv/borg/repos/{{ ansible_hostname }}",restrict'
|
||||
key_options: 'command="borg serve --restrict-to-path /srv/borg/repos/{{ ansible_hostname }}",restrict'
|
||||
delegate_to: "{{ borg_server }}"
|
||||
|
||||
- name: create borg client repo directory on server
|
||||
file:
|
||||
path: "/srv/borg/repos/{{ ansible_hostname }}"
|
||||
state: directory
|
||||
owner: borg
|
||||
mode: 0700
|
||||
delegate_to: "{{ borg_server }}"
|
||||
|
||||
- name: create borg client repo on server
|
||||
shell: "echo \"borg init --encryption=none /srv/borg/repos/{{ ansible_hostname }}\" | su -l borg"
|
||||
delegate_to: "{{ borg_server }}"
|
||||
args:
|
||||
creates: "/srv/borg/repos/{{ ansible_hostname }}/config"
|
||||
|
||||
- name: reload ansible_local
|
||||
setup: filter=ansible_local
|
||||
delegate_to: "{{ borg_server }}"
|
||||
delegate_facts: True
|
||||
when: hostvars[borg_server]['ansible_local']['borg']['repos'][ansible_hostname] is not defined
|
||||
|
||||
- name: make the server known to the client
|
||||
lineinfile:
|
||||
line: "{{ borg_server }} ecdsa-sha2-nistp256 {{ hostvars[borg_server]['ansible_ssh_host_key_ecdsa_public'] }}"
|
||||
path: /root/.ssh/known_hosts
|
||||
create: yes
|
||||
|
||||
- name: make the repo directory on the client
|
||||
file:
|
||||
state: directory
|
||||
path: "/root/.config/borg/security/{{ hostvars[borg_server]['ansible_local']['borg']['repos'][ansible_hostname] }}"
|
||||
owner: root
|
||||
mode: 0700
|
||||
- name: create borg client repo on server
|
||||
shell: "borg init --rsh \"ssh -i /root/.ssh/borg\" --encryption=none borg@{{ borg_server }}:/srv/borg/repos/{{ ansible_hostname }}"
|
||||
when: hostvars[borg_server]['ansible_local']['borg']['repos'][ansible_hostname] is not defined
|
||||
|
||||
- name: make the repo known to the client
|
||||
copy:
|
||||
dest: "/root/.config/borg/security/{{ hostvars[borg_server]['ansible_local']['borg']['repos'][ansible_hostname] }}/{{ item.dest }}"
|
||||
content: "{{ item.content }}"
|
||||
owner: root
|
||||
mode: 0600
|
||||
loop:
|
||||
- { dest: key-type, content: "2" }
|
||||
- { dest: location, content: "ssh://borg@{{ borg_server }}/srv/borg/repos/{{ ansible_hostname }}" }
|
||||
- { dest: manifest-timestamp, content: "{{ ansible_date_time['iso8601_micro'] }}" }
|
||||
changed_when: false
|
||||
- name: reload ansible_local
|
||||
setup: filter=ansible_local
|
||||
delegate_to: "{{ borg_server }}"
|
||||
delegate_facts: True
|
||||
when: hostvars[borg_server]['ansible_local']['borg']['repos'][ansible_hostname] is not defined
|
||||
|
||||
- name: deploy borg backup script
|
||||
template:
|
||||
|
|
|
@ -13,9 +13,9 @@ export BORG_RSH="ssh -i /root/.ssh/borg"
|
|||
{{ job.pre_command }}
|
||||
{% endif %}
|
||||
{% if job.command_to_pipe is defined %}
|
||||
{{ job.command_to_pipe }} | borg create borg@{{ borg_server }}:/srv/borg/repos/{{ ansible_hostname }}::{{ job.name }}-{now} {{ job.path | default('-') }}
|
||||
{{ job.command_to_pipe }} | borg create borg@{{ borg_server }}:/srv/borg/repos/{{ ansible_hostname }}::{{ job.name }}-{now} -
|
||||
{% else %}
|
||||
borg create borg@{{ borg_server }}:/srv/borg/repos/{{ ansible_hostname }}::{{ job.name }}-{now} {{ job.path }}
|
||||
borg create {% for exclude in job.exclude|default([]) %} --exclude {{ exclude }}{% endfor %} borg@{{ borg_server }}:/srv/borg/repos/{{ ansible_hostname }}::{{ job.name }}-{now} {{ job.path }}
|
||||
{% endif %}
|
||||
{% if job.post_command is defined %}
|
||||
{{ job.post_command }}
|
||||
|
|
Reference in a new issue