X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Frsync_backup%2Fdefault.nix;h=ff84fe3fbb60ae98686a21b3854e244c17f01d00;hb=46b7e62708f01eaefef78341819643eeceea8130;hp=dadf5e7cd6ed8375f96816f183df0d9f7680fbcc;hpb=ab8f306d7c2c49b8116e1af7b355ed2384617ed9;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/rsync_backup/default.nix b/modules/rsync_backup/default.nix index dadf5e7..ff84fe3 100644 --- a/modules/rsync_backup/default.nix +++ b/modules/rsync_backup/default.nix @@ -41,6 +41,13 @@ let Number of backups to keep ''; }; + check_command = lib.mkOption { + type = lib.types.str; + default = "backup"; + description = '' + command to check if backup needs to be done + ''; + }; login = lib.mkOption { type = lib.types.str; description = '' @@ -84,19 +91,16 @@ let ssh_key = config.secrets.fullPaths."rsync_backup/identity"; - backup_head = mailto: '' + backup_head = '' #!${pkgs.stdenv.shell} EXCL_FROM=`mktemp` FILES_FROM=`mktemp` TMP_STDERR=`mktemp` on_exit() { - ${lib.optionalString (mailto != null) '' - MAILTO="${mailto}" if [ -s "$TMP_STDERR" ]; then - cat "$TMP_STDERR" | ${pkgs.mailutils}/bin/mail -s "save_distant rsync error" "$MAILTO" + cat "$TMP_STDERR" fi - ''} rm -f $TMP_STDERR $EXCL_FROM $FILES_FROM } @@ -131,7 +135,7 @@ let -o CheckHostIP=no \ -p $PORT \ -i ${ssh_key} \ - $DEST backup; then + $DEST ${profile.check_command}; then echo "Fichier de verrouillage backup sur $DEST ou impossible de se connecter" >&2 skip=$DEST fi @@ -171,7 +175,7 @@ let EOF OUT=$RSYNC_OUTPUT/$LOCAL - ${pkgs.rsync}/bin/rsync -XAavbrz --fake-super -e "ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -i ${ssh_key} -p $PORT" --numeric-ids --delete \ + ${pkgs.rsync}/bin/rsync --new-compress -XAavbr --fake-super -e "ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -i ${ssh_key} -p $PORT" --numeric-ids --delete \ --backup-dir=$BAK_BASE/$LOCAL \${ lib.optionalString (part.args != null) "\n ${part.args} \\"}${ lib.optionalString (builtins.length part.exclude_from > 0) "\n --exclude-from=$EXCL_FROM \\"}${ @@ -186,11 +190,6 @@ in type = lib.types.path; description = "Path to the base folder for backups"; }; - mailto = lib.mkOption { - type = lib.types.nullOr lib.types.str; - default = null; - description = "E-mail to send the report to"; - }; profiles = lib.mkOption { type = lib.types.attrsOf profileModule; default = {}; @@ -223,7 +222,7 @@ in services.cron.systemCronJobs = let backup = pkgs.writeScript "backup.sh" (builtins.concatStringsSep "\n" ([ - (backup_head cfg.mailto) + backup_head ] ++ lib.mapAttrsToList backup_profile cfg.profiles)); in [ ''