Easily run restic commands on a backup group
This commit is contained in:
parent
42e2ebd294
commit
a34238b3a9
@ -1,11 +1,13 @@
|
|||||||
{ config, lib, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.backup;
|
cfg = config.backup;
|
||||||
hostname = config.networking.hostName;
|
hostname = config.networking.hostName;
|
||||||
|
|
||||||
|
mkRespository = group: "s3:s3.us-west-004.backblazeb2.com/D22TgIt0-main-backup/${group}";
|
||||||
|
|
||||||
mkBackup = group: paths: {
|
mkBackup = group: paths: {
|
||||||
repository = "s3:s3.us-west-004.backblazeb2.com/D22TgIt0-main-backup/${group}";
|
repository = mkRespository group;
|
||||||
inherit paths;
|
inherit paths;
|
||||||
|
|
||||||
initialize = true;
|
initialize = true;
|
||||||
@ -29,6 +31,20 @@ let
|
|||||||
environmentFile = "/run/agenix/backblaze-s3-backups";
|
environmentFile = "/run/agenix/backblaze-s3-backups";
|
||||||
passwordFile = "/run/agenix/restic-password";
|
passwordFile = "/run/agenix/restic-password";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# example usage: "sudo restic_samba unlock" (removes lockfile)
|
||||||
|
mkResticGroupCmd = group: pkgs.writeShellScriptBin "restic_${group}" ''
|
||||||
|
if [ "$EUID" -ne 0 ]
|
||||||
|
then echo "Run as root"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
. /run/agenix/backblaze-s3-backups
|
||||||
|
export AWS_SECRET_ACCESS_KEY
|
||||||
|
export AWS_ACCESS_KEY_ID
|
||||||
|
export RESTIC_PASSWORD_FILE=/run/agenix/restic-password
|
||||||
|
export RESTIC_REPOSITORY="${mkRespository group}"
|
||||||
|
exec ${pkgs.restic}/bin/restic "$@"
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.backup = {
|
options.backup = {
|
||||||
@ -56,5 +72,7 @@ in
|
|||||||
|
|
||||||
age.secrets.backblaze-s3-backups.file = ../secrets/backblaze-s3-backups.age;
|
age.secrets.backblaze-s3-backups.file = ../secrets/backblaze-s3-backups.age;
|
||||||
age.secrets.restic-password.file = ../secrets/restic-password.age;
|
age.secrets.restic-password.file = ../secrets/restic-password.age;
|
||||||
|
|
||||||
|
environment.systemPackages = map mkResticGroupCmd (builtins.attrNames cfg.group);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user