Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06a7489032 | ||
|
|
1d415bfae8 |
No files matched your search
+22
-14
@@ -1,27 +1,32 @@
|
||||
---
|
||||
- name: Install restic
|
||||
ansible.builtin.apt:
|
||||
name: restic
|
||||
state: present
|
||||
|
||||
- name: Initialize restic repository
|
||||
- name: Install and initialize restic
|
||||
become: true
|
||||
environment:
|
||||
RESTIC_REPOSITORY: "{{ vault_restic_repo_url }}"
|
||||
RESTIC_PASSWORD: "{{ vault_restic_password }}"
|
||||
AWS_ACCESS_KEY_ID: "{{ vault_aws_access_key }}"
|
||||
AWS_SECRET_ACCESS_KEY: "{{ vault_aws_secret_key }}"
|
||||
block:
|
||||
- name: Check if already initialized
|
||||
ansible.builtin.command: restic snapshots
|
||||
- name: Install restic
|
||||
ansible.builtin.apt:
|
||||
name: restic
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Check if repository is initialized
|
||||
ansible.builtin.command: restic cat config
|
||||
register: restic_check
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Initialize repository
|
||||
ansible.builtin.command: restic init
|
||||
when: restic_check.rc != 0
|
||||
|
||||
- name: Deploy restic environment file
|
||||
- name: Configure restic backup job
|
||||
become: true
|
||||
block:
|
||||
- name: Deploy restic environment file
|
||||
ansible.builtin.template:
|
||||
src: restic-backup.env.j2
|
||||
dest: /etc/restic-backup.env
|
||||
@@ -29,7 +34,7 @@
|
||||
group: root
|
||||
mode: "0600" ## only root can read this file
|
||||
|
||||
- name: Deploy restic backup script
|
||||
- name: Deploy restic backup script
|
||||
ansible.builtin.template:
|
||||
src: restic-backup.sh.j2
|
||||
dest: /usr/local/bin/restic-backup.sh
|
||||
@@ -37,7 +42,10 @@
|
||||
group: root
|
||||
mode: "0700" ## only root can execute the script
|
||||
|
||||
- name: Deploy restic systemd service
|
||||
- name: Schedule restic backups
|
||||
become: true
|
||||
block:
|
||||
- name: Deploy restic systemd service
|
||||
ansible.builtin.template:
|
||||
src: restic-backup.service.j2
|
||||
dest: /etc/systemd/system/restic-backup.service
|
||||
@@ -45,7 +53,7 @@
|
||||
group: root
|
||||
mode: "0644"
|
||||
|
||||
- name: Deploy restic systemd timer
|
||||
- name: Deploy restic systemd timer
|
||||
ansible.builtin.template:
|
||||
src: restic-backup.timer.j2
|
||||
dest: /etc/systemd/system/restic-backup.timer
|
||||
@@ -53,7 +61,7 @@
|
||||
group: root
|
||||
mode: "0644"
|
||||
|
||||
- name: Enable and start backup timer
|
||||
- name: Enable and start backup timer
|
||||
ansible.builtin.systemd:
|
||||
name: restic-backup.timer
|
||||
enabled: yes
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
# Source environment variables if running manually/outside Systemd
|
||||
if [ -f /etc/restic-backup.env ]; then
|
||||
# shellcheck source=/dev/null
|
||||
. /etc/restic-backup.env
|
||||
fi
|
||||
## Environment is injected by the systemd unit via EnvironmentFile=/etc/restic-backup.env. Run manually with: systemctl start restic-backup.service
|
||||
|
||||
echo "Starting Restic Backup at $(date)"
|
||||
|
||||
|
||||
Reference in new issue
Block a user