Guest User

Untitled

a guest
Jan 22nd, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. { config, pkgs, lib, ... }:
  2.  
  3. let
  4. cfg = config.mailserver;
  5.  
  6. backupUser = "tardis";
  7.  
  8. dsyncBackupScript = "dsyncbackup.sh";
  9.  
  10. set = cfg.loginAccounts;
  11. mailboxes = builtins.attrNames set;
  12. lines = lib.lists.imap0 (i: v: "dsync -f -o plugin/acl= -o plugin/quota= -o plugin/zlib_save= -u ${toString v} backup maildir:$WORK_DIR/${toString v}") mailboxes;
  13. scriptLines = builtins.concatStringsSep "\n" lines;
  14. script = pkgs.writeScript (toString dsyncBackupScript) ''
  15. #!${pkgs.stdenv.shell}
  16. set -e
  17.  
  18. # create temp directory that dsync can write to
  19. WORK_DIR=$(mktemp -d)
  20. chmod o+rwx $WORK_DIR
  21.  
  22. function cleanup {
  23. rm -rf "$WORK_DIR"
  24. echo "Deleted temp working directory $WORK_DIR"
  25. }
  26.  
  27. # register cleanup
  28. trap cleanup EXIT
  29.  
  30. # backs up all mailboxes to subdirectories of the current one to be picked up by rsnapshot
  31. ${scriptLines}
  32.  
  33. # move content of tmp directory into current directory
  34. mv $WORK_DIR/* .
  35. '';
  36. in {
  37. # dsync backup of a single mailbox
  38. services.rsnapshot = {
  39. enable = true;
  40. cronIntervals = {
  41. # minute, hour, day-in-month, month, weekday (0 = sunday)
  42. "hourly" = " 0 * * * *"; # Every full hour
  43. "daily" = "50 21 * * *"; # Every day at 21:50
  44. "weekly" = " 0 5 * * 0"; # Every sunday at 5:00 AM
  45. };
  46. # rsnapshot expects intervals shortest first, e.g. hourly first, then daily.
  47. # tabs must separate all elements
  48. extraConfig = ''
  49. #snapshot_root /home/${backupUser}/rsnapshot
  50. snapshot_root /var/rsnapshot
  51. retain hourly 24
  52. retain daily 365
  53. retain weekly 54
  54. backup_exec chmod o+rx g+rx /var/rsnapshot
  55. backup_script ${script} localhost/dsync/
  56. backup /var/vmail/ localhost/
  57. '';
  58. };
  59.  
  60. users.extraUsers."${backupUser}" = {
  61. isSystemUser = true;
  62. home = "/home/${backupUser}";
  63. createHome = true;
  64. extraGroups = [ ];
  65. };
  66. }
Add Comment
Please, Sign In to add comment