blob: a9c5c311961b540a3def8cc3c2bc157d84688c99 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
---
- name: Create script for automatic borg backup
ansible.builtin.file:
dest: "{{ script_location }}"
state: touch
owner: "{{ borg_client_user }}"
group: "{{ borg_client_user }}"
modification_time: preserve
access_time: preserve
mode: "0711"
become: true
- name: Insert shebang into backup script
ansible.builtin.lineinfile:
path: "{{ script_location }}"
line: "#!/bin/bash"
insertbefore: BOF
state: present
become: true
- name: Insert Backup job block into scripts
ansible.builtin.blockinfile:
path: "{{ script_location }}"
marker: "## {mark} ANSIBLE MANAGED BLOCK for {{ borg_server_host_url }}/{{ borg_repo_name }}"
block: |
export BORG_PASSPHRASE={{ borg_passphrase | quote }}
{% if borg_ssh_key_per_repo %}
export BORG_RSH="ssh -i {{ borg_ssh_key_path }}"
{% endif %}
borg create -C {{ borg_compression }} \
borg@{{ borg_server_host_url }}:{{ borg_server_user_home }}/{{ borg_repo_name }}::{{ borg_backup_name_format }} \
{{ borg_included_dirs | map('quote') | join(' ') }} \
{% for e in (borg_excluded_dirs | map('quote')) %} --exclude {{ e }} {% endfor %}
become: true
|