commit 1e2f7a1e8d3f8653f9b089a1028e099b9a294293 Author: Helix Date: Sun Dec 12 15:33:30 2021 +0100 initial commit diff --git a/files/borgmatic@.service b/files/borgmatic@.service new file mode 100644 index 0000000..e257cfe --- /dev/null +++ b/files/borgmatic@.service @@ -0,0 +1,24 @@ +[Unit] +Description=backup %i with borgmatic +Wants=network-online.target +After=network-online.target +ConditionACPower=true + +[Service] +Type=oneshot + +# Lower CPU and I/O priority. +Nice=19 +CPUSchedulingPolicy=batch +IOSchedulingClass=best-effort +IOSchedulingPriority=7 +IOWeight=100 + +Restart=no +# Prevent rate limiting of borgmatic log events. If you are using an older version of systemd that +# doesn't support this (pre-240 or so), you may have to remove this option. +LogRateLimitIntervalSec=0 + +# Delay start to prevent backups running during boot. Note that systemd-inhibit requires dbus and +# dbus-user-session to be installed. +ExecStart=systemd-inhibit --who="borgmatic-%i" --why="Prevent interrupting backup of %I" /usr/bin/borgmatic /etc/borgmatic/%i.yaml --syslog-verbosity 1 diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..9d2fa3e --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,18 @@ +- name: Install Borg Backup via dnf package manager + ansible.builtin.dnf: + name: "borgbackup" + state: present + +- name: Install Borgmatic via Pip package manager + ansible.builtin.pip: + name: "borgmatic" + state: present + +- name: Copy systemd unit files + ansible.builtin.copy: + src: "../files/borgmatic@.service" + dest: "/etc/systemd/system/borgmatic@.service" + owner: root + group: root + mode: u=rw,g=r,o=r + diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..32c11f6 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,8 @@ +- name: Check if we already installed borgmatic + stat: + path: "/etc/systemd/system/borgmatic@.service" + register: borgmatic_installed + +- name: "Install borg and borgmatic" + include: install.yml + when: not borgmatic_installed.stat.exists