From 3878f68e1fc0e18961a8218505c17c098d77c057 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 3 Nov 2022 09:35:40 +0100 Subject: [PATCH] fist working backup script --- restic/files/backup.sh.jinja | 44 +++++++++++++++++++++++++++++ restic/files/restic.automount.jinja | 2 +- restic/files/restic.mount.jinja | 2 +- restic/init.sls | 19 +++++++++++++ restic/repository.sls | 2 +- top.sls | 2 +- 6 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 restic/files/backup.sh.jinja create mode 100644 restic/init.sls diff --git a/restic/files/backup.sh.jinja b/restic/files/backup.sh.jinja new file mode 100644 index 0000000..2b8817d --- /dev/null +++ b/restic/files/backup.sh.jinja @@ -0,0 +1,44 @@ +#!/bin/bash +{%- if pillar.restic.repository is defined %} +export RESTIC_REPOSITORY={{ pillar.restic.mount }}{{ pillar.restic.suffix }} +{%- else %} +export RESTIC_REPOSITORY="stfp:{{ pillar.restic.user }}@{{ pillar.restic.host }}:{{ pillar.restic.mount }}{{ pillar.restic.suffix }}" +{%- endif %} +export RESTIC_PASSWORD={{ pillar.restic.password }} + +restic backup \ + --exclude="*.tmp" \ + --exclude="lost+found" \ + --exclude="Cache" \ + --exclude="cache" \ + --exclude=".cache" \ + --exclude="tmp" \ + --exclude="temp" \ + --exclude="Temp" \ + --exclude="/home/*/go" \ + --exclude="/home/*/.local/share/virtualenv" \ + --exclude="/home/*/.local/share/virtualenvs" \ + --exclude="/home/*/VirtualBox VMs" \ + --exclude="/home/*/.mozillla/firefox/*/minidumps" \ + --exclude="/home/*/.mozillla/firefox/*/storage" \ + --exclude="/home/*/.mozillla/firefox/*/extensions.sqlite" \ + --exclude="/home/*/.mozillla/firefox/*/urlclassifier3.sqlite" \ + --exclude="/home/*/.config/google-chrome/*/Local Storage" \ + --exclude="/home/*/.config/google-chrome/*/Session Storage" \ + --exclude="/home/*/.config/google-chrome/*/Application Cache" \ + --exclude="/home/*/.config/google-chrome/*/History" \ + --exclude="/home/*/.config/google-chrome/*/History-journal" \ + --exclude="/home/*/.config/google-chrome/*/History Provider Cache" \ + --exclude="/home/*/.local/share/flatpak" \ + --exclude="/home/*/.var/app/com.slack.Slack" \ + --exclude="/home/*/.local/share/Trash" \ + --exclude="/home/*/.config/Microsoft/Microsoft Teams" \ + --exclude="/home/*/.wine" \ + --exclude="/home/*/.vim/bundle" \ + --exclude="/home/*/snap" \ + --exclude="/home/*/Downloads" \ + --exclude="/home/*/Nextcloud" \ + --exclude="/home/*/git" \ + --verbose \ + {% if pillar.podman is defined %}{{ salt['cmd.run']('podman info -f "{{.Store.VolumePath}}"', runas=pillar.podman.user ) }} \{% endif %} + /home diff --git a/restic/files/restic.automount.jinja b/restic/files/restic.automount.jinja index 57609c0..0ec3a96 100644 --- a/restic/files/restic.automount.jinja +++ b/restic/files/restic.automount.jinja @@ -2,7 +2,7 @@ Description=Automount for restic repository [Automount] -Where={{ pillar['restic']['repository']['mount'] }} +Where={{ pillar['restic']['mount'] }} [Install] WantedBy=multi-user.target diff --git a/restic/files/restic.mount.jinja b/restic/files/restic.mount.jinja index 5945724..08730b3 100644 --- a/restic/files/restic.mount.jinja +++ b/restic/files/restic.mount.jinja @@ -3,7 +3,7 @@ Description=Mount the USB disk used as restic repository [Mount] What=/dev/disk/by-uuid/{{ pillar['restic']['repository']['disk_uuid'] }} -Where={{ pillar['restic']['repository']['mount'] }} +Where={{ pillar['restic']['mount'] }} Type=auto Options=defaults diff --git a/restic/init.sls b/restic/init.sls new file mode 100644 index 0000000..ea7676b --- /dev/null +++ b/restic/init.sls @@ -0,0 +1,19 @@ +{% if pillar.restic.repository is defined %} +include: + - restic.repository +{% endif %} + +Install restic packages: + pkg.installed: + - pkgs: + - restic + - restic-bash-completion + +Copy backup script for {{ pillar.restic.user }}: + file.managed: + - name: {{ salt['user.info'](pillar.restic.user).home }}/bin/backup.sh + - source: salt://restic/files/backup.sh.jinja + - template: jinja + - user: {{ pillar.restic.user }} + - group: root + - mode: "0740" diff --git a/restic/repository.sls b/restic/repository.sls index b232134..64ff645 100644 --- a/restic/repository.sls +++ b/restic/repository.sls @@ -1,4 +1,4 @@ -{% set escape_command = [ "systemd-escape -p", pillar['restic']['repository']['mount']]|join(" ") %} +{% set escape_command = [ "systemd-escape -p", pillar['restic']['mount']]|join(" ") %} {% set unit_name = salt['cmd.shell'](escape_command) %} Create restic repository mount unit: diff --git a/top.sls b/top.sls index bcbfdf8..29eeed0 100644 --- a/top.sls +++ b/top.sls @@ -7,7 +7,7 @@ base: 'poblano.rre.nu': - podman - - restic.repository + - restic - cockpit 'pepper.rre.nu':