Fix automatic restic backup

This commit is contained in:
GHOSCHT 2024-04-03 11:25:20 +02:00
parent 73df2f82c0
commit 65aa06c5f5
Signed by: ghoscht
GPG key ID: 2C2C1C62A5388E82

View file

@ -5,26 +5,42 @@
}: let
vars = import ../../vars.nix;
arionPath = "/home/${vars.user}/.setup/hosts/franz/arion";
cfg = config.virtualisation.arion;
in {
systemd.timers."restic-cron" = {
wantedBy = ["timers.target"];
timerConfig = {
OnBootSec = "5m";
OnUnitActiveSec = "5m";
Unit = "restic-cron.service";
};
# systemd.timers."restic-cron" = {
# wantedBy = ["timers.target"];
# timerConfig = {
# OnBootSec = "1m";
# OnUnitActiveSec = "1m";
# Unit = "restic-cron.service";
# };
# };
#
# systemd.services."restic-cron" = {
# path = [
# cfg.docker.client.package
# cfg.package
# pkgs.nix
# pkgs.restic
# pkgs.autorestic
# ];
# script = ''
# source /etc/profile
# autorestic -c /home/ghoscht/.autorestic.yml --verbose cron >> /tmp/autorestic.log 2>&1
# '';
# serviceConfig = {
# Type = "oneshot";
# User = "root";
# };
# };
services.cron = {
enable = true;
systemCronJobs = [
"*/5 * * * * root . /etc/profile; autorestic -c /home/ghoscht/.autorestic.yml --ci cron"
];
};
systemd.services."restic-cron" = {
script = ''
set -eu
${pkgs.autorestic}/bin/autorestic -c /home/ghoscht/.autorestic.yml --restic-bin ${pkgs.restic}/bin/restic --ci cron > /tmp/autorestic.log 2>&1
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
environment.systemPackages = with pkgs; [autorestic restic];
sops.secrets."autorestic/zfs_key" = {
@ -49,35 +65,32 @@ in {
from: /storage/dataset/docker/dashboard
to:
- zfs
- ssd
cron: '0 3 * * 0' # Every Sunday at 3:00
hooks:
before:
- sudo arion -f ${arionPath}/dashboard/arion-compose.nix -p ${arionPath}/dashboard/arion-pkgs.nix stop
- arion -f ${arionPath}/dashboard/arion-compose.nix -p ${arionPath}/dashboard/arion-pkgs.nix stop
after:
- sudo arion -f ${arionPath}/dashboard/arion-compose.nix -p ${arionPath}/dashboard/arion-pkgs.nix start
- arion -f ${arionPath}/dashboard/arion-compose.nix -p ${arionPath}/dashboard/arion-pkgs.nix start
dns:
from: /storage/dataset/docker/dns
to:
- zfs
- ssd
cron: '0 3 * * 0' # Every Sunday at 3:00
hooks:
before:
- sudo arion -f ${arionPath}/dns/arion-compose.nix -p ${arionPath}/dns/arion-pkgs.nix stop
- arion -f ${arionPath}/dns/arion-compose.nix -p ${arionPath}/dns/arion-pkgs.nix stop
after:
- sudo arion -f ${arionPath}/dns/arion-compose.nix -p ${arionPath}/dns/arion-pkgs.nix start
- arion -f ${arionPath}/dns/arion-compose.nix -p ${arionPath}/dns/arion-pkgs.nix start
feed:
from: /storage/dataset/docker/feed
to:
- zfs
- ssd
cron: '0 3 * * 0' # Every Sunday at 3:00
hooks:
before:
- sudo arion -f ${arionPath}/feed/arion-compose.nix -p ${arionPath}/feed/arion-pkgs.nix stop
- arion -f ${arionPath}/feed/arion-compose.nix -p ${arionPath}/feed/arion-pkgs.nix stop
after:
- sudo arion -f ${arionPath}/feed/arion-compose.nix -p ${arionPath}/feed/arion-pkgs.nix start
- arion -f ${arionPath}/feed/arion-compose.nix -p ${arionPath}/feed/arion-pkgs.nix start
git:
from: /storage/dataset/docker/git
to:
@ -86,20 +99,19 @@ in {
cron: '0 3 * * *' # Every Day at 3:00
hooks:
before:
- sudo arion -f ${arionPath}/git/arion-compose.nix -p ${arionPath}/git/arion-pkgs.nix stop
- arion -f ${arionPath}/git/arion-compose.nix -p ${arionPath}/git/arion-pkgs.nix stop
after:
- sudo arion -f ${arionPath}/git/arion-compose.nix -p ${arionPath}/git/arion-pkgs.nix start
- arion -f ${arionPath}/git/arion-compose.nix -p ${arionPath}/git/arion-pkgs.nix start
media:
from: /storage/dataset/docker/media
to:
- zfs
- ssd
cron: '0 3 * * 0' # Every Sunday at 3:00
cron: '0 3 * * *' # Every Day at 3:00
hooks:
before:
- sudo arion -f ${arionPath}/media/arion-compose.nix -p ${arionPath}/media/arion-pkgs.nix stop
- arion -f ${arionPath}/media/arion-compose.nix -p ${arionPath}/media/arion-pkgs.nix stop
after:
- sudo arion -f ${arionPath}/media/arion-compose.nix -p ${arionPath}/media/arion-pkgs.nix start
- arion -f ${arionPath}/media/arion-compose.nix -p ${arionPath}/media/arion-pkgs.nix start
nextcloud:
from: /storage/dataset/docker/nextcloud
to:
@ -108,20 +120,19 @@ in {
cron: '0 3 * * *' # Every Day at 3:00
hooks:
before:
- sudo arion -f ${arionPath}/nextcloud/arion-compose.nix -p ${arionPath}/nextcloud/arion-pkgs.nix stop
- arion -f ${arionPath}/nextcloud/arion-compose.nix -p ${arionPath}/nextcloud/arion-pkgs.nix stop
after:
- sudo arion -f ${arionPath}/nextcloud/arion-compose.nix -p ${arionPath}/nextcloud/arion-pkgs.nix start
- arion -f ${arionPath}/nextcloud/arion-compose.nix -p ${arionPath}/nextcloud/arion-pkgs.nix start
smarthome:
from: /storage/dataset/docker/smarthome
to:
- zfs
- ssd
cron: '0 3 * * 0' # Every Sunday at 3:00
hooks:
before:
- sudo arion -f ${arionPath}/smarthome/arion-compose.nix -p ${arionPath}/smarthome/arion-pkgs.nix stop
- arion -f ${arionPath}/smarthome/arion-compose.nix -p ${arionPath}/smarthome/arion-pkgs.nix stop
after:
- sudo arion -f ${arionPath}/smarthome/arion-compose.nix -p ${arionPath}/smarthome/arion-pkgs.nix start
- arion -f ${arionPath}/smarthome/arion-compose.nix -p ${arionPath}/smarthome/arion-pkgs.nix start
passwords:
from: /storage/dataset/docker/passwords
to:
@ -130,9 +141,9 @@ in {
cron: '0 3 * * *' # Every Day at 3:00
hooks:
before:
- sudo arion -f ${arionPath}/passwords/arion-compose.nix -p ${arionPath}/passwords/arion-pkgs.nix stop
- arion -f ${arionPath}/passwords/arion-compose.nix -p ${arionPath}/passwords/arion-pkgs.nix stop
after:
- sudo arion -f ${arionPath}/passwords/arion-compose.nix -p ${arionPath}/passwords/arion-pkgs.nix start
- arion -f ${arionPath}/passwords/arion-compose.nix -p ${arionPath}/passwords/arion-pkgs.nix start
backends:
zfs:
type: local