feat: backup #10

Open
alessandrovitali wants to merge 7 commits from feat/backup into main
pull from: feat/backup
Showing only changes of commit 06a7489032 - Show all commits
+49 -42
View File
@@ -1,19 +1,20 @@
--- ---
- name: Install restic - name: Install and initialize restic
ansible.builtin.apt: become: true
name: restic
state: present
update_cache: true
- name: Initialize restic repository
environment: environment:
RESTIC_REPOSITORY: "{{ vault_restic_repo_url }}" RESTIC_REPOSITORY: "{{ vault_restic_repo_url }}"
RESTIC_PASSWORD: "{{ vault_restic_password }}" RESTIC_PASSWORD: "{{ vault_restic_password }}"
AWS_ACCESS_KEY_ID: "{{ vault_aws_access_key }}" AWS_ACCESS_KEY_ID: "{{ vault_aws_access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ vault_aws_secret_key }}" AWS_SECRET_ACCESS_KEY: "{{ vault_aws_secret_key }}"
block: block:
- name: Install restic
ansible.builtin.apt:
name: restic
state: present
update_cache: true
- name: Check if repository is initialized - name: Check if repository is initialized
command: restic cat config ansible.builtin.command: restic cat config
register: restic_check register: restic_check
changed_when: false changed_when: false
failed_when: false failed_when: false
@@ -22,41 +23,47 @@
ansible.builtin.command: restic init ansible.builtin.command: restic init
when: restic_check.rc != 0 when: restic_check.rc != 0
- name: Deploy restic environment file - name: Configure restic backup job
ansible.builtin.template: become: true
src: restic-backup.env.j2 block:
dest: /etc/restic-backup.env - name: Deploy restic environment file
owner: root ansible.builtin.template:
group: root src: restic-backup.env.j2
mode: "0600" ## only root can read this file dest: /etc/restic-backup.env
owner: root
group: root
mode: "0600" ## only root can read this file
- name: Deploy restic backup script - name: Deploy restic backup script
ansible.builtin.template: ansible.builtin.template:
src: restic-backup.sh.j2 src: restic-backup.sh.j2
dest: /usr/local/bin/restic-backup.sh dest: /usr/local/bin/restic-backup.sh
owner: root owner: root
group: root group: root
mode: "0700" ## only root can execute the script mode: "0700" ## only root can execute the script
- name: Deploy restic systemd service - name: Schedule restic backups
ansible.builtin.template: become: true
src: restic-backup.service.j2 block:
dest: /etc/systemd/system/restic-backup.service - name: Deploy restic systemd service
owner: root ansible.builtin.template:
group: root src: restic-backup.service.j2
mode: "0644" dest: /etc/systemd/system/restic-backup.service
owner: root
group: root
mode: "0644"
- name: Deploy restic systemd timer - name: Deploy restic systemd timer
ansible.builtin.template: ansible.builtin.template:
src: restic-backup.timer.j2 src: restic-backup.timer.j2
dest: /etc/systemd/system/restic-backup.timer dest: /etc/systemd/system/restic-backup.timer
owner: root owner: root
group: root group: root
mode: "0644" mode: "0644"
- name: Enable and start backup timer - name: Enable and start backup timer
ansible.builtin.systemd: ansible.builtin.systemd:
name: restic-backup.timer name: restic-backup.timer
enabled: yes enabled: yes
state: started state: started
daemon_reload: yes daemon_reload: yes