From 6564f78511dc5580c3016c0c0d386d77ea588ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Grondek?= Date: Fri, 22 Sep 2023 20:05:32 +0200 Subject: [PATCH] Add task for backup --- localhost.yml | 1 + roles/backup/files/etc/btrbk/btrbk.conf | 13 +++++++++++ roles/backup/files/etc/cron.daily/btrbk | 2 ++ roles/backup/tasks/arch.yml | 29 +++++++++++++++++++++++++ roles/backup/tasks/main.yml | 3 +++ 5 files changed, 48 insertions(+) create mode 100644 roles/backup/files/etc/btrbk/btrbk.conf create mode 100755 roles/backup/files/etc/cron.daily/btrbk create mode 100644 roles/backup/tasks/arch.yml create mode 100644 roles/backup/tasks/main.yml diff --git a/localhost.yml b/localhost.yml index fe84d2e..c03fa5b 100644 --- a/localhost.yml +++ b/localhost.yml @@ -14,6 +14,7 @@ - docker - laptop - desktop + - backup # - flutter # - virtual diff --git a/roles/backup/files/etc/btrbk/btrbk.conf b/roles/backup/files/etc/btrbk/btrbk.conf new file mode 100644 index 0000000..08c5d4f --- /dev/null +++ b/roles/backup/files/etc/btrbk/btrbk.conf @@ -0,0 +1,13 @@ +timestamp_format long + +snapshot_preserve_min 24h +snapshot_preserve 7d 4w 3m + +volume /home + snapshot_dir /home/.snapshots + subvolume /home + +volume / + snapshot_dir /.snapshot_dir + subvolume / + diff --git a/roles/backup/files/etc/cron.daily/btrbk b/roles/backup/files/etc/cron.daily/btrbk new file mode 100755 index 0000000..2d8693d --- /dev/null +++ b/roles/backup/files/etc/cron.daily/btrbk @@ -0,0 +1,2 @@ +#!/bin/sh +exec /usr/bin/btrbk -q run diff --git a/roles/backup/tasks/arch.yml b/roles/backup/tasks/arch.yml new file mode 100644 index 0000000..bcd7cb7 --- /dev/null +++ b/roles/backup/tasks/arch.yml @@ -0,0 +1,29 @@ +--- +- name: install btrbk + become: yes + community.general.pacman: + name: + - btrfs-progs + - btrbk + - cronie + +- name: "Enable cron" + become: yes + ansible.builtin.systemd: + name: cronie + state: started + enabled: yes + +- name: Copy configuration + become: yes + copy: + src: etc/btrbk/btrbk.conf + dest: /etc/btrbk/btrbk.conf + mode: 0644 + +- name: Add cron daily + become: yes + copy: + src: etc/cron.daily/btrbk + dest: /etc/cron.daily/btrbk + mode: 0755 diff --git a/roles/backup/tasks/main.yml b/roles/backup/tasks/main.yml new file mode 100644 index 0000000..6d32278 --- /dev/null +++ b/roles/backup/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- import_tasks: arch.yml + when: ansible_distribution == "Archlinux"