Add the hostname to the tag

This commit is contained in:
Andreas Zweili 2022-08-23 20:54:23 +02:00
parent a979c7f0ec
commit e637fd1643
3 changed files with 57 additions and 28 deletions

View File

@ -20,10 +20,10 @@
script = ''
${pkgs.restic}/bin/restic backup \
--exclude-file=${inputs.self}/modules/restic/excludes.txt \
--tag home-dir /home/${custom.username}
--tag home-dir-${config.networking.hostName} /home/${custom.username}
${pkgs.restic}/bin/restic forget \
--tag home-dir \
--tag home-dir-${config.networking.hostName} \
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \

View File

@ -20,16 +20,16 @@
script = ''
${pkgs.restic}/bin/restic backup \
--exclude-file=${inputs.self}/modules/restic/excludes.txt \
--tag home-dir /home/${custom.username}
--tag home-dir-${config.networking.hostName} /home/${custom.username}
${pkgs.mariadb}/bin/mysqldump --single-transaction --all-databases | \
${pkgs.restic}/bin/restic backup \
--tag mariadb \
--tag mariadb-${config.networking.hostName} \
--stdin \
--stdin-filename all_databases.sql
${pkgs.restic}/bin/restic forget \
--tag home-dir \
--tag home-dir-${config.networking.hostName} \
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
@ -37,7 +37,7 @@
--keep-yearly 75
${pkgs.restic}/bin/restic forget \
--tag mariadb \
--tag mariadb-${config.networking.hostName} \
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \

View File

@ -2,13 +2,47 @@
let
password_file = "/home/${custom.username}/.nixos/secrets/passwords/restic.key";
repository = "rest:http://10.7.89.30:8000";
restic-mount = pkgs.writeScriptBin "restic-mount" ''
mkdir -p /tmp/restic &&
${pkgs.restic}/bin/restic \
--repo ${repository} \
--password-file ${password_file} \
--host ${config.networking.hostName} \
mount /tmp/restic'';
restic-mount-all = pkgs.writeScriptBin "restic-mount-all" ''
mkdir -p /tmp/restic &&
${pkgs.restic}/bin/restic \
--repo ${repository} \
--password-file ${password_file} \
mount /tmp/restic'';
infomaniak-env = "/home/${custom.username}/.nixos/secrets/passwords/infomaniak-env";
infomaniak-repo = "swift:default:/Backup 1/restic/";
infomaniak-auth-url = "https://swiss-backup02.infomaniak.com/identity/v3";
restic-infomaniak-list = pkgs.writeScriptBin "restic-infomaniak-list" ''
export $(${pkgs.gnugrep}/bin/grep -v '^#' ${infomaniak-env} | ${pkgs.findutils}/bin/xargs)
export RESTIC_REPOSITORY="${infomaniak-repo}"
export OS_AUTH_URL="${infomaniak-auth-url}"
export OS_USER_DOMAIN_NAME=default
mkdir -p /tmp/restic &&
${pkgs.restic}/bin/restic --password-file ${password_file} list snapshots'';
restic-infomaniak-mount = pkgs.writeScriptBin "restic-infomaniak-mount" ''
export $(${pkgs.gnugrep}/bin/grep -v '^#' ${infomaniak-env} | ${pkgs.findutils}/bin/xargs)
export RESTIC_REPOSITORY="${infomaniak-repo}"
export OS_AUTH_URL="${infomaniak-auth-url}"
export OS_USER_DOMAIN_NAME=default
mkdir -p /tmp/restic &&
${pkgs.restic}/bin/restic --password-file ${password_file} mount /tmp/swissbackup'';
in
{
environment.systemPackages = with pkgs;
[
restic
];
systemd.timers."restic-backups-${custom.username}" = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-backups-${custom.username}.service" ];
@ -46,32 +80,27 @@ in
environment.shellAliases = {
restic-list = ''
restic \
${pkgs.restic}/bin/restic \
--repo ${repository} \
--password-file ${password_file} \
snapshots --host ${config.networking.hostName}'';
restic-unlock = ''
restic \
${pkgs.restic}/bin/restic \
--repo ${repository} \
--password-file ${password_file} \
unlock'';
restic-mount = ''
mkdir -p /tmp/restic && \
restic \
--repo ${repository} \
--password-file ${password_file} \
--host ${config.networking.hostName} \
mount /tmp/restic'';
restic-mount-all = ''
mkdir -p /tmp/restic && \
restic \
--repo ${repository} \
--password-file ${password_file} \
mount /tmp/restic'';
restic-forget = ''
restic \
--repo ${repository} \
${pkgs.restic}/bin/restic --repo ${repository} \
--password-file ${password_file} \
forget $1'';
};
environment.systemPackages = with pkgs;
[
restic
restic-mount
restic-mount-all
restic-infomaniak-list
restic-infomaniak-mount
];
}